diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/config/WSCalculationConfiguration.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/config/WSCalculationConfiguration.java index 005fa4286..ac8c68890 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/config/WSCalculationConfiguration.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/config/WSCalculationConfiguration.java @@ -249,5 +249,10 @@ public class WSCalculationConfiguration { @Value("${sms.exclude.tenant}") private String smsExcludeTenant; - + + @Value("${is.save.demand.audit.enabled}") + private boolean isSaveDemandAuditEnabled; + + @Value("${egov.save.demand.audit.from.wscal}") + private String saveDemandAudit; } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java index 0aba61a11..19471617b 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java @@ -336,7 +336,7 @@ private void generateDemandAndSendnotification(RequestInfo requestInfo, String t } } catch (Exception e) { - System.out.println("Got the exception while genating the demands:" + connectionNo); + System.out.println("Got the exception while genating the demands:" + e); failedConnectionNos.add(connectionNo); } } @@ -462,14 +462,12 @@ private void generateDemandAndSendnotification(RequestInfo requestInfo, String t String msgLink = config.getNotificationUrl() + config.getGpUserDemandLink(); for (OwnerInfo userInfo : userDetailResponse.getUser()) { - log.info("USER NUMBER:" + userInfo.getMobileNumber() + " USER ROLE:" + userInfo.getRoles()); if (userInfo.getName() != null) { mobileNumberIdMap.put(userInfo.getMobileNumber(), userInfo.getName()); } else { mobileNumberIdMap.put(userInfo.getMobileNumber(), userInfo.getUserName()); } } - log.info("MOBILENUMBER MAPPINNG USERROLE:" +mobileNumberIdMap); mobileNumberIdMap.entrySet().stream().forEach(map -> { String msg = demandMessage.get(WSCalculationConstant.MSG_KEY); msg = msg.replace("{ownername}", map.getValue()); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandAuditSeqBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandAuditSeqBuilder.java new file mode 100644 index 000000000..8a416f438 --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandAuditSeqBuilder.java @@ -0,0 +1,24 @@ +package org.egov.wscalculation.repository; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Repository; + +@Component +@Slf4j +@Repository +public class DemandAuditSeqBuilder { + + @Autowired + private JdbcTemplate jdbcTemplate; + + public static final String SELECT_NEXT_SEQUENCE_USER = "select nextval('seq_eg_ws_demand_auditchange')"; + + public Long getNextSequence() { + return jdbcTemplate.queryForObject(SELECT_NEXT_SEQUENCE_USER, Long.class); + } + + +} diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java index 4016f83e0..75de96d6a 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java @@ -43,6 +43,7 @@ import org.egov.wscalculation.config.WSCalculationConfiguration; import org.egov.wscalculation.constants.WSCalculationConstant; import org.egov.wscalculation.producer.WSCalculationProducer; +import org.egov.wscalculation.repository.DemandAuditSeqBuilder; import org.egov.wscalculation.repository.DemandRepository; import org.egov.wscalculation.repository.ServiceRequestRepository; import org.egov.wscalculation.repository.WSCalculationDao; @@ -51,26 +52,8 @@ import org.egov.wscalculation.util.WSCalculationUtil; import org.egov.wscalculation.validator.WSCalculationValidator; import org.egov.wscalculation.validator.WSCalculationWorkflowValidator; -import org.egov.wscalculation.web.models.BulkDemand; -import org.egov.wscalculation.web.models.Calculation; -import org.egov.wscalculation.web.models.Category; -import org.egov.wscalculation.web.models.Demand; +import org.egov.wscalculation.web.models.*; import org.egov.wscalculation.web.models.Demand.StatusEnum; -import org.egov.wscalculation.web.models.DemandDetail; -import org.egov.wscalculation.web.models.DemandDetailAndCollection; -import org.egov.wscalculation.web.models.DemandPenaltyResponse; -import org.egov.wscalculation.web.models.DemandRequest; -import org.egov.wscalculation.web.models.DemandResponse; -import org.egov.wscalculation.web.models.GetBillCriteria; -import org.egov.wscalculation.web.models.OwnerInfo; -import org.egov.wscalculation.web.models.Property; -import org.egov.wscalculation.web.models.Recipient; -import org.egov.wscalculation.web.models.RequestInfoWrapper; -import org.egov.wscalculation.web.models.SMSRequest; -import org.egov.wscalculation.web.models.TaxHeadEstimate; -import org.egov.wscalculation.web.models.TaxPeriod; -import org.egov.wscalculation.web.models.WaterConnection; -import org.egov.wscalculation.web.models.WaterConnectionRequest; import org.egov.wscalculation.web.models.users.UserDetailResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -147,6 +130,9 @@ public class DemandService { @Autowired private EstimationService estimationService; + @Autowired + private DemandAuditSeqBuilder demandAuditSeqBuilder; + /** * Creates or updates Demand * @@ -285,6 +271,22 @@ private List createDemand(RequestInfo requestInfo, List cal .businessService(businessService).status(StatusEnum.valueOf("ACTIVE")).billExpiryTime(expiryDate) .build()); } + + if(config.isSaveDemandAuditEnabled()){ + demands.stream().forEach(demand -> { + Long id = demandAuditSeqBuilder.getNextSequence(); + WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id). + consumercode(demand.getConsumerCode()). + tenant_id(demand.getTenantId()). + status(demand.getStatus().toString()). + action("CREATE DEMAND BULK"). + data(demand). + createdby(requestInfo.getUserInfo().getUuid()). + createdtime(System.currentTimeMillis()).build(); + WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build(); + producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper); + }); + } demandRes = demandRepository.saveDemand(requestInfo, demands); finalDemandRes.addAll(demandRes); @@ -887,6 +889,21 @@ public List updateDemands(GetBillCriteria getBillCriteria, RequestInfoWr // Call demand update in bulk to update the interest or penalty if(!isGetPenaltyEstimate) { if(demandsToBeUpdated.size() > 0) { + if(config.isSaveDemandAuditEnabled()){ + demandsToBeUpdated.stream().forEach(demand -> { + Long id = demandAuditSeqBuilder.getNextSequence(); + WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id). + consumercode(demand.getConsumerCode()). + tenant_id(demand.getTenantId()). + status(demand.getStatus().toString()). + action("UPDATE DEMAND GET PENALTY/UPDATE API"). + data(demand). + createdby(demand.getAuditDetails().getCreatedBy()). + createdtime(demand.getAuditDetails().getLastModifiedTime()).build(); + WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build(); + producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper); + }); + } DemandRequest request = DemandRequest.builder().demands(demandsToBeUpdated).requestInfo(requestInfo).build(); repository.fetchResult(utils.getUpdateDemandUrl(), request); return res.getDemands(); @@ -946,6 +963,22 @@ private List updateDemandForCalculation(RequestInfo requestInfo, List { + Long id = demandAuditSeqBuilder.getNextSequence(); + WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id). + consumercode(dem.getConsumerCode()). + tenant_id(dem.getTenantId()). + status(dem.getStatus().toString()). + action("UPDATE DEMAND BULK"). + data(dem). + createdby(dem.getAuditDetails().getCreatedBy()). + createdtime(dem.getAuditDetails().getLastModifiedTime()).build(); + WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build(); + producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper); + }); + } demandRes = demandRepository.updateDemand(requestInfo, demands); finalDemandRes.addAll(demandRes); List billNumbers = fetchBill(demands, waterConnectionRequest.getRequestInfo()); @@ -1375,6 +1408,21 @@ public int compare(Demand d1, Demand d2) { } log.info("Updated Demand Details " + demands.toString()); + if(config.isSaveDemandAuditEnabled()){ + demands.stream().forEach(demand -> { + Long id = demandAuditSeqBuilder.getNextSequence(); + WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id). + consumercode(demand.getConsumerCode()). + tenant_id(demand.getTenantId()). + status(demand.getStatus().toString()). + action("UPDATE DEMAND APPLYADHOCTAX"). + data(demand). + createdby(demand.getAuditDetails().getCreatedBy()). + createdtime(demand.getAuditDetails().getLastModifiedTime()).build(); + WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build(); + producer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper); + }); + } demandRepository.updateDemand(requestInfo, demands); return calculations; } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java index 04f8dd5da..17572ec9c 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java @@ -17,21 +17,9 @@ import org.egov.wscalculation.config.WSCalculationConfiguration; import org.egov.wscalculation.constants.WSCalculationConstant; import org.egov.wscalculation.producer.WSCalculationProducer; -import org.egov.wscalculation.web.models.AdhocTaxReq; -import org.egov.wscalculation.web.models.BulkDemand; -import org.egov.wscalculation.web.models.Calculation; -import org.egov.wscalculation.web.models.CalculationCriteria; -import org.egov.wscalculation.web.models.CalculationReq; -import org.egov.wscalculation.web.models.Demand; +import org.egov.wscalculation.repository.DemandAuditSeqBuilder; +import org.egov.wscalculation.web.models.*; import org.egov.wscalculation.web.models.Demand.StatusEnum; -import org.egov.wscalculation.web.models.GetBillCriteria; -import org.egov.wscalculation.web.models.TaxHeadCategory; -import org.egov.wscalculation.web.models.Property; -import org.egov.wscalculation.web.models.RequestInfoWrapper; -import org.egov.wscalculation.web.models.TaxHeadEstimate; -import org.egov.wscalculation.web.models.TaxHeadMaster; -import org.egov.wscalculation.web.models.WaterConnection; -import org.egov.wscalculation.web.models.WaterConnectionRequest; import org.egov.wscalculation.web.models.enums.Status; import org.egov.wscalculation.repository.DemandRepository; import org.egov.wscalculation.repository.ServiceRequestRepository; @@ -82,6 +70,9 @@ public class WSCalculationServiceImpl implements WSCalculationService { @Autowired private WSCalculationConfiguration config; + @Autowired + private DemandAuditSeqBuilder demandAuditSeqBuilder; + /** * Get CalculationReq and Calculate the Tax Head on Water Charge And Estimation Charge */ @@ -127,6 +118,21 @@ public List getCalculation(CalculationReq request) { .getWaterConnection().getPreviousReadingDate().longValue())) { searchResult.get(0).setStatus(StatusEnum.CANCELLED); isWSUpdateSMS = true; + if(config.isSaveDemandAuditEnabled()){ + searchResult.stream().forEach(demand -> { + Long id = demandAuditSeqBuilder.getNextSequence(); + WsDemandChangeAuditRequest wsDemandChangeAuditRequest = WsDemandChangeAuditRequest.builder().id(id). + consumercode(demand.getConsumerCode()). + tenant_id(demand.getTenantId()). + status(demand.getStatus().toString()). + action("GET CALCULATION UPDATE"). + data(demand). + createdby(demand.getAuditDetails().getCreatedBy()). + createdtime(demand.getAuditDetails().getLastModifiedTime()).build(); + WsDemandChangeAuditRequestWrapper wsDemandChangeAuditRequestWrapper = WsDemandChangeAuditRequestWrapper.builder().wsDemandChangeAuditRequest(wsDemandChangeAuditRequest).build(); + wsCalculationProducer.push(config.getSaveDemandAudit(), wsDemandChangeAuditRequestWrapper); + }); + } demandRepository.updateDemand(request.getRequestInfo(), searchResult); } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/WsDemandChangeAuditRequest.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/WsDemandChangeAuditRequest.java new file mode 100644 index 000000000..3fc468037 --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/WsDemandChangeAuditRequest.java @@ -0,0 +1,28 @@ +package org.egov.wscalculation.web.models; + +import lombok.*; + +import java.util.Map; + +import static org.apache.commons.lang3.StringUtils.isNotEmpty; + + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ToString +public class WsDemandChangeAuditRequest { + private Long id; + private String consumercode; + private String tenant_id; + private String status; + private String action; + private Object data; + private String createdby; + private Long createdtime; + public boolean isValid() { + + return isNotEmpty(consumercode); + } +} diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/WsDemandChangeAuditRequestWrapper.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/WsDemandChangeAuditRequestWrapper.java new file mode 100644 index 000000000..fb439dcc1 --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/WsDemandChangeAuditRequestWrapper.java @@ -0,0 +1,16 @@ +package org.egov.wscalculation.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.*; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ToString +public class WsDemandChangeAuditRequestWrapper { + + @JsonProperty("WsDemandChangeAuditRequest") + private WsDemandChangeAuditRequest wsDemandChangeAuditRequest; +} diff --git a/municipal-services/ws-calculator/src/main/resources/application.properties b/municipal-services/ws-calculator/src/main/resources/application.properties index c1860ade8..f5d371823 100644 --- a/municipal-services/ws-calculator/src/main/resources/application.properties +++ b/municipal-services/ws-calculator/src/main/resources/application.properties @@ -145,3 +145,7 @@ sms.demand.enabled: true sms.payment.link.enabled: true sms.bill.download.enabled: true sms.exclude.tenant="pb.testing" + +#SAVE DEMAND AUDIT FROM WS_SERVICE +is.save.demand.audit.enabled= true +egov.save.demand.audit.from.wscal= save-ws-demand-change-audit \ No newline at end of file diff --git a/municipal-services/ws-calculator/src/main/resources/db/migration/ddl/V202405230601__wc_create_demand_audit_ddl.sql b/municipal-services/ws-calculator/src/main/resources/db/migration/ddl/V202405230601__wc_create_demand_audit_ddl.sql new file mode 100644 index 000000000..813ea1dbc --- /dev/null +++ b/municipal-services/ws-calculator/src/main/resources/db/migration/ddl/V202405230601__wc_create_demand_audit_ddl.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS eg_ws_demand_auditchange ( + id bigint NOT NULL, + consumercode VARCHAR(30) NOT NULL, + tenant_id VARCHAR(50), + status VARCHAR(50), + action VARCHAR(100), + data JSONB, + createdby VARCHAR(250), + createdtime bigint + +); +CREATE SEQUENCE seq_eg_ws_demand_auditchange + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE eg_ws_demand_auditchange ADD CONSTRAINT eg_ws_demand_auditchange_pkey PRIMARY KEY (id); \ No newline at end of file