diff --git a/core-services/egov-notification-sms/pom.xml b/core-services/egov-notification-sms/pom.xml index 4268b706a..0b85ef8d8 100644 --- a/core-services/egov-notification-sms/pom.xml +++ b/core-services/egov-notification-sms/pom.xml @@ -71,6 +71,11 @@ spring-boot-starter-test test + + org.springframework + spring-jdbc + 5.3.23 + diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/SmsSaveRequest.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/SmsSaveRequest.java index a1e84d7ea..8b3c660c4 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/SmsSaveRequest.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/SmsSaveRequest.java @@ -12,7 +12,7 @@ @Builder @ToString public class SmsSaveRequest { - private String id; + private Long id; private String mobileNumber; private String message; private Category category; diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/repository/builder/SmsNotificationRepository.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/repository/builder/SmsNotificationRepository.java new file mode 100644 index 000000000..505990986 --- /dev/null +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/repository/builder/SmsNotificationRepository.java @@ -0,0 +1,22 @@ +package org.egov.web.notification.sms.repository.builder; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; +import org.springframework.jdbc.core.JdbcTemplate; + +@Component +@Slf4j +@Repository +public class SmsNotificationRepository { + + private JdbcTemplate jdbcTemplate; + + public static final String SELECT_NEXT_SEQUENCE_USER = "select nextval('seq_eg_notification_sms')"; + + public Long getNextSequence() { + return jdbcTemplate.queryForObject(SELECT_NEXT_SEQUENCE_USER, Long.class); + } + + +} diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java index efdafab22..4c257ada6 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java @@ -8,6 +8,7 @@ import org.egov.web.notification.sms.config.*; import org.egov.web.notification.sms.models.*; import org.egov.web.notification.sms.producer.Producer; +import org.egov.web.notification.sms.repository.builder.SmsNotificationRepository; import org.springframework.asm.*; import org.springframework.beans.factory.annotation.*; import org.springframework.core.*; @@ -45,6 +46,9 @@ abstract public class BaseSMSService implements SMSService, SMSBodyBuilder { @Autowired private Producer producer; + @Autowired + private SmsNotificationRepository smsNotificationRepository; + @PostConstruct public void init() { List> converters = restTemplate.getMessageConverters(); @@ -80,7 +84,8 @@ public void sendSMS(Sms sms) { } log.info("calling submitToExternalSmsService() method"); if(smsProperties.isSaveSmsEnable()) { - SmsSaveRequest smsSaveRequest = SmsSaveRequest.builder().mobileNumber(sms.getMobileNumber()).message(sms.getMessage()) + Long id = smsNotificationRepository.getNextSequence(); + SmsSaveRequest smsSaveRequest = SmsSaveRequest.builder().id(id).mobileNumber(sms.getMobileNumber()).message(sms.getMessage()) .category(sms.getCategory()).templateId(sms.getTemplateId()).tenantId(sms.getTenantId()).createdtime(System.currentTimeMillis()).build(); log.info("SMS request to save sms topic" + smsSaveRequest); producer.push(smsProperties.getSaveSmsTopic(), smsSaveRequest); diff --git a/core-services/egov-notification-sms/src/main/resources/db/migration.main/V20231005150835_notification_sms_ddl.sql b/core-services/egov-notification-sms/src/main/resources/db/migration.main/V20231005150835_notification_sms_ddl.sql index e5344c243..04ae434f5 100644 --- a/core-services/egov-notification-sms/src/main/resources/db/migration.main/V20231005150835_notification_sms_ddl.sql +++ b/core-services/egov-notification-sms/src/main/resources/db/migration.main/V20231005150835_notification_sms_ddl.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS eg_notification_sms ( - id SERIAL PRIMARY KEY, + id bigint NOT NULL, mobile_no VARCHAR(20) NOT NULL, message TEXT, category VARCHAR(50), @@ -7,3 +7,11 @@ CREATE TABLE IF NOT EXISTS eg_notification_sms ( createdtime TIMESTAMP, tenant_id VARCHAR(50) ); +CREATE SEQUENCE seq_eg_notification_sms + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE eg_notification_sms ADD CONSTRAINT eg_notification_sms_pkey PRIMARY KEY (id); +