From 532402dd6329dc1129471daa1aad775f96c7b7c6 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 11 Mar 2024 11:02:19 +0530 Subject: [PATCH 01/63] PFM-5638: added changes for Penalty Schedular. --- utilities/Penalty/pom.xml | 138 ++++++++++++++++++ .../org/egov/PenaltySchedularApplication.java | 12 ++ .../config/PenaltyShedularConfiguration.java | 50 +++++++ .../org/egov/job/PenaltySchedularJob.java | 83 +++++++++++ .../org/egov/model/AddPenaltyCriteria.java | 21 +++ .../src/main/java/org/egov/model/Tenant.java | 14 ++ .../main/java/org/egov/util/MDMSClient.java | 101 +++++++++++++ .../egov/util/PenaltySchedularConstant.java | 7 + .../src/main/resources/application.properties | 17 +++ 9 files changed, 443 insertions(+) create mode 100644 utilities/Penalty/pom.xml create mode 100644 utilities/Penalty/src/main/java/org/egov/PenaltySchedularApplication.java create mode 100644 utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java create mode 100644 utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java create mode 100644 utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java create mode 100644 utilities/Penalty/src/main/java/org/egov/model/Tenant.java create mode 100644 utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java create mode 100644 utilities/Penalty/src/main/java/org/egov/util/PenaltySchedularConstant.java create mode 100644 utilities/Penalty/src/main/resources/application.properties diff --git a/utilities/Penalty/pom.xml b/utilities/Penalty/pom.xml new file mode 100644 index 000000000..33855dfd6 --- /dev/null +++ b/utilities/Penalty/pom.xml @@ -0,0 +1,138 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.6.6 + + + org.egov + penalty-schedular + 1.0-SNAPSHOT + penalty-schedular + penalty schedular + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.postgresql + postgresql + runtime + ${postgresql.version} + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.egov.services + ifix-services-common + 0.0.1-SNAPSHOT + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.google.code.gson + gson + 2.9.0 + + + org.apache.commons + commons-lang3 + 3.12.0 + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + 2.11.4 + + + com.vladmihalcea + hibernate-types-52 + 2.3.5 + + + org.egov + mdms-client + 0.0.4-SNAPSHOT + compile + + + org.flywaydb + flyway-core + + + org.bouncycastle + bcprov-jdk15on + 1.69 + + + org.apache.cxf + cxf-rt-frontend-jaxws + 3.5.0 + + + org.apache.cxf + cxf-rt-transports-http + 3.5.0 + + + org.projectlombok + lombok + 1.18.22 + compile + + + + + + repo.digit.org + eGov ERP Releases Repository + https://nexus-repo.digit.org/nexus/content/repositories/releases/ + + + repo.digit.org.snapshots + eGov ERP Releases Repository + https://nexus-repo.digit.org/nexus/content/repositories/snapshots/ + + + repo.digit.org.public + eGov Public Repository Group + https://nexus-repo.digit.org/nexus/content/groups/public/ + + + + + + 19 + 19 + UTF-8 + 1.8 + 2.17.1 + 42.3.3 + + + \ No newline at end of file diff --git a/utilities/Penalty/src/main/java/org/egov/PenaltySchedularApplication.java b/utilities/Penalty/src/main/java/org/egov/PenaltySchedularApplication.java new file mode 100644 index 000000000..735daa26e --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/PenaltySchedularApplication.java @@ -0,0 +1,12 @@ +package org.egov; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +public class PenaltySchedularApplication { + public static void main(String[] args) { + SpringApplication.run(PenaltySchedularApplication.class, args); + } +} \ No newline at end of file diff --git a/utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java b/utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java new file mode 100644 index 000000000..ce7c8ea0b --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java @@ -0,0 +1,50 @@ +package org.egov.config; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Import; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.List; +import java.util.TimeZone; + +@Component +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PenaltyShedularConfiguration { + + @Value("${app.timezone}") + private String timeZone; + + @PostConstruct + public void initialize() { + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + } + + //egov-mdms + @Value("${egov.mdms.host}") + private String egovMdmsHost; + + @Value("${egov.mdms.search.endpoint}") + private String egovMdmsSearchUrl; + + @Value("${mdms.event.tenantId}") + private String tenantId; + + @Value("${egov.wscalculator.host}") + private String egovWaterCalculatorHost; + + @Value("${egov.wscalculator.url}") + private String egovWaterCalculatorSearchUrl; + + @Value("${egov.penalty.enabled}") + private boolean isPenaltyEnabled; + + @Value("#{'${egov.penalty.enabled.division.code.list}'.split(',')}") + private List penaltyEnabledDivisionlist; +} + diff --git a/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java b/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java new file mode 100644 index 000000000..b24b92645 --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java @@ -0,0 +1,83 @@ +package org.egov.job; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.egov.config.PenaltyShedularConfiguration; +import org.egov.model.AddPenaltyCriteria; +import org.egov.model.Tenant; +import org.egov.util.MDMSClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.http.*; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Component +@Slf4j +@AllArgsConstructor +@NoArgsConstructor +public class PenaltySchedularJob implements ApplicationRunner { + + @Autowired + private MDMSClient mdmsClient; + + @Autowired + private PenaltyShedularConfiguration adapterConfiguration; + + @Autowired + private RestTemplate restTemplate; + + @Override + public void run(ApplicationArguments args) throws Exception { + + try { + List tenantList = mdmsClient.getTenants(); + System.out.println(tenantList.size()); + tenantList=tenantList.stream().filter( + tenant -> { + return adapterConfiguration.getPenaltyEnabledDivisionlist().contains(tenant.getDivisionCode()); + }).collect(Collectors.toList()); + + System.out.println(tenantList.size()); + + tenantList.stream().forEach(tenant -> { + + addPenaltyEventToWaterCalculator(AddPenaltyCriteria.builder().tenantId(tenant.getCode()).build()); + + }); + + } catch (Exception e) { + log.error("Exception occurred while running PenaltySchedularJob", e); + } + } + + public void addPenaltyEventToWaterCalculator(AddPenaltyCriteria penaltyCriteria) { + log.info("Posting request to add Penalty for tenantid:" +penaltyCriteria.getTenantId()); + + if (penaltyCriteria.getTenantId() != null) { + try { + restTemplate.put(getWaterConnnectionAddPennanltyUrl(), penaltyCriteria); + + log.info("Posted request to add Penalty for tenant:" + penaltyCriteria.getTenantId()); + } catch (RestClientException e) { + log.error("Error while calling to water calculator service for tenant :" + penaltyCriteria.getTenantId() + " ERROR MESSAGE:" + e.getMessage(), e.getCause()); + } + } + } + + /** + * @return - return iFix event publish url + */ + public String getWaterConnnectionAddPennanltyUrl() { + return (adapterConfiguration.getEgovWaterCalculatorHost() + adapterConfiguration.getEgovWaterCalculatorSearchUrl()); + } + + +} diff --git a/utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java b/utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java new file mode 100644 index 000000000..b929ff747 --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java @@ -0,0 +1,21 @@ +package org.egov.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AddPenaltyCriteria { + private String limit; + private String offset; + @NotNull + private String tenantId; + private List tenantids; +} diff --git a/utilities/Penalty/src/main/java/org/egov/model/Tenant.java b/utilities/Penalty/src/main/java/org/egov/model/Tenant.java new file mode 100644 index 000000000..4c1516740 --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/model/Tenant.java @@ -0,0 +1,14 @@ +package org.egov.model; + +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Tenant { + private String code; + private String divisionCode; + private String divisionName; +} diff --git a/utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java b/utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java new file mode 100644 index 000000000..40e780b68 --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java @@ -0,0 +1,101 @@ +package org.egov.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.minidev.json.JSONArray; +import org.egov.common.contract.request.RequestInfo; +import org.egov.config.PenaltyShedularConfiguration; +import org.egov.mdms.model.*; +import org.egov.model.Tenant; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@Component +@Slf4j +@AllArgsConstructor +@NoArgsConstructor +public class MDMSClient { + + @Autowired + private PenaltyShedularConfiguration adapterConfiguration; + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private ObjectMapper objectMapper; + + private List tenantids = null; + + @PostConstruct + protected void loadTenantsFromMdms() { + try { + MasterDetail masterDetail = MasterDetail.builder().name(PenaltySchedularConstant.MDMS_TENANT_MASTER_NAME).build(); + ModuleDetail moduleDetail = ModuleDetail.builder().moduleName(PenaltySchedularConstant.MDMS_MODULE_NAME) + .masterDetails(Arrays.asList(masterDetail)).build(); + + MdmsCriteria mdmsCriteria = MdmsCriteria.builder().tenantId(adapterConfiguration.getTenantId()) + .moduleDetails(Arrays.asList(moduleDetail)).build(); + + MdmsCriteriaReq mdmsCriteriaReq = MdmsCriteriaReq.builder().requestInfo(RequestInfo.builder().build()) + .mdmsCriteria(mdmsCriteria).build(); + + //header + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + //request + HttpEntity request = new HttpEntity<>(mdmsCriteriaReq, headers); + + ResponseEntity response = + restTemplate.postForEntity(adapterConfiguration.getEgovMdmsHost() + adapterConfiguration.getEgovMdmsSearchUrl(), + request, MdmsResponse.class); + + MdmsResponse mdmsResponse = null; + if (response != null && response.getBody() != null) { + mdmsResponse = response.getBody(); + }else { + return; + } + + if (mdmsResponse != null && (mdmsResponse.getMdmsRes() == null || mdmsResponse.getMdmsRes().isEmpty())) { + log.error("Tenants file is missing in mdms!!"); + } else { + if (mdmsResponse.getMdmsRes().get(PenaltySchedularConstant.MDMS_MODULE_NAME) != null && mdmsResponse.getMdmsRes().get(PenaltySchedularConstant.MDMS_MODULE_NAME) + .get(PenaltySchedularConstant.MDMS_TENANT_MASTER_NAME) != null) { + JSONArray tenantResponse = mdmsResponse.getMdmsRes().get(PenaltySchedularConstant.MDMS_MODULE_NAME) + .get(PenaltySchedularConstant.MDMS_TENANT_MASTER_NAME); + + ObjectReader reader = objectMapper.readerFor(objectMapper.getTypeFactory().constructCollectionType(List.class, + Tenant.class)); + + tenantids = reader.readValue(tenantResponse.toString()); + } + + } + + } catch (IOException e) { + log.error("Error occurred while getting the account to gp mapping from MDMS", e); + } + } + + public List getTenants() { + if (tenantids == null || tenantids.isEmpty()) { + return Collections.emptyList(); + } + return tenantids; + } +} diff --git a/utilities/Penalty/src/main/java/org/egov/util/PenaltySchedularConstant.java b/utilities/Penalty/src/main/java/org/egov/util/PenaltySchedularConstant.java new file mode 100644 index 000000000..536ffb10e --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/util/PenaltySchedularConstant.java @@ -0,0 +1,7 @@ +package org.egov.util; + +public class PenaltySchedularConstant { + public static final String MDMS_MODULE_NAME = "tenant"; + public static final String MDMS_TENANT_MASTER_NAME = "tenants"; + +} \ No newline at end of file diff --git a/utilities/Penalty/src/main/resources/application.properties b/utilities/Penalty/src/main/resources/application.properties new file mode 100644 index 000000000..9ec915bf1 --- /dev/null +++ b/utilities/Penalty/src/main/resources/application.properties @@ -0,0 +1,17 @@ +app.timezone=UTC + +#-----Disable the Web application----------------------# +spring.main.web-application-type=none + +#----------------MDMS config---------------------# +egov.mdms.host=http://localhost:8094 +egov.mdms.search.endpoint=/mdms-v2/v1/_search +mdms.event.tenantId=pb +egov.wscalculator.host=http://localhost:8083 +egov.wscalculator.url=/ws-calculator/waterCalculator/_addPenalty +egov.penalty.enabled= true +egov.penalty.enabled.division.code.list=DIV1038,DIV1001 + +#----------------aspect Configurations----------------# +timestamp.logging.enabled=true + From a75663008106186e1a902a89adca40dbea60afa9 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 11 Mar 2024 11:37:59 +0530 Subject: [PATCH 02/63] PFM-5638: added changes for Penalty Schedular. --- build/build-config.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/build-config.yml b/build/build-config.yml index ea8c9c688..dcde66e1d 100644 --- a/build/build-config.yml +++ b/build/build-config.yml @@ -134,3 +134,8 @@ config: dockerfile: "build/maven/Dockerfile" - work-dir: "business-services/egov-apportion-service/src/main/resources/db" image-name: "egov-apportion-service-db" + - name: "builds/mGramSeva/utilities/egov-penalty-schedular" + build: + - work-dir: "utilities/egov-penalty-schedular" + image-name: "egov-penalty-schedular" + dockerfile: "build/maven/Dockerfile" From a60ed70c5a103c67eceffa5ffdc85ebe50afe74a Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 11 Mar 2024 12:08:35 +0530 Subject: [PATCH 03/63] PFM-5638: added changes for Penalty Schedular. --- utilities/Penalty/Dockerfile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 utilities/Penalty/Dockerfile diff --git a/utilities/Penalty/Dockerfile b/utilities/Penalty/Dockerfile new file mode 100644 index 000000000..d1478053d --- /dev/null +++ b/utilities/Penalty/Dockerfile @@ -0,0 +1,20 @@ +FROM egovio/apline-jre:8u121 + +MAINTAINER Debasish + + +# INSTRUCTIONS ON HOW TO BUILD JAR: +# Move to the location where pom.xml is exist in project and build project using below command +# "mvn clean package" +COPY /target/egov-penalty-schedular-0.0.1-SNAPSHOT.jar /opt/egov/egov-penalty-schedular.jar + +COPY start.sh /usr/bin/start.sh + +RUN chmod +x /usr/bin/start.sh + +CMD ["/usr/bin/start.sh"] + +# NOTE: the two 'RUN' commands can probably be combined inside of a single +# script (i.e. RUN build-and-install-app.sh) so that we can also clean up the +# extra files created during the `mvn package' command. that step inflates the +# resultant image by almost 1.0GB. \ No newline at end of file From ff8aa02f182654684f8d460cab667207be491223 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 11 Mar 2024 12:10:28 +0530 Subject: [PATCH 04/63] PFM-5638: added changes for Penalty Schedular. --- build/build-config.yml | 2 +- utilities/Penalty/Dockerfile | 20 -------------------- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 utilities/Penalty/Dockerfile diff --git a/build/build-config.yml b/build/build-config.yml index dcde66e1d..fd95614d4 100644 --- a/build/build-config.yml +++ b/build/build-config.yml @@ -136,6 +136,6 @@ config: image-name: "egov-apportion-service-db" - name: "builds/mGramSeva/utilities/egov-penalty-schedular" build: - - work-dir: "utilities/egov-penalty-schedular" + - work-dir: "utilities/penalty" image-name: "egov-penalty-schedular" dockerfile: "build/maven/Dockerfile" diff --git a/utilities/Penalty/Dockerfile b/utilities/Penalty/Dockerfile deleted file mode 100644 index d1478053d..000000000 --- a/utilities/Penalty/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM egovio/apline-jre:8u121 - -MAINTAINER Debasish - - -# INSTRUCTIONS ON HOW TO BUILD JAR: -# Move to the location where pom.xml is exist in project and build project using below command -# "mvn clean package" -COPY /target/egov-penalty-schedular-0.0.1-SNAPSHOT.jar /opt/egov/egov-penalty-schedular.jar - -COPY start.sh /usr/bin/start.sh - -RUN chmod +x /usr/bin/start.sh - -CMD ["/usr/bin/start.sh"] - -# NOTE: the two 'RUN' commands can probably be combined inside of a single -# script (i.e. RUN build-and-install-app.sh) so that we can also clean up the -# extra files created during the `mvn package' command. that step inflates the -# resultant image by almost 1.0GB. \ No newline at end of file From 54b9e55cad9204539db514d22b53aeaea88e6179 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 11 Mar 2024 12:11:39 +0530 Subject: [PATCH 05/63] PFM-5638: added changes for Penalty Schedular. --- build/build-config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build-config.yml b/build/build-config.yml index fd95614d4..cc9f05230 100644 --- a/build/build-config.yml +++ b/build/build-config.yml @@ -136,6 +136,6 @@ config: image-name: "egov-apportion-service-db" - name: "builds/mGramSeva/utilities/egov-penalty-schedular" build: - - work-dir: "utilities/penalty" + - work-dir: "utilities/Penalty" image-name: "egov-penalty-schedular" dockerfile: "build/maven/Dockerfile" From 3d23038841a40f73eaf758be8cb255292cc1383b Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 11 Mar 2024 16:24:29 +0530 Subject: [PATCH 06/63] PFM-5638: Added log lines to check --- .../sms/config/SMSProperties.java | 2 +- .../builder/WSCalculatorQueryBuilder.java | 31 +++ .../wscalculation/service/DemandService.java | 231 ++++++++++++++++-- .../web/controller/CalculatorController.java | 20 +- .../web/models/AddPenaltyCriteria.java | 19 ++ 5 files changed, 272 insertions(+), 31 deletions(-) create mode 100644 municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java index e039f20e9..df71a4718 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java @@ -93,7 +93,7 @@ public class SMSProperties { @Value("${save.sms.entity.enabled}") private boolean isSaveSmsEnable; - @Value("#{'${sms.error.codes}'.split(',')}") + @Value("#{'${sms.disabled.tenants.list}'.split(',')}") protected List smsDisabledTenantList; @Setter(AccessLevel.PROTECTED) private List whitelistPatterns; diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java index 476db7821..08482213e 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java @@ -277,4 +277,35 @@ public String previousBillingCycleConnectionQuery(Set connectionNos, Str return builder.toString(); } + public String getPenaltyQuery(Set connectionNos, String tenantId, Long startDate, + Long endDate, List preparedStmtList) { + + StringBuilder builder = new StringBuilder(PREVIOUS_BILLING_CYCLE_DEMAND); + + if (!CollectionUtils.isEmpty(connectionNos)) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" consumercode IN (").append(createQuery(connectionNos)).append(")"); + addToPreparedStatement(preparedStmtList, connectionNos); + } + if (startDate != null && endDate != null) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" taxperiodto between ? and ? "); + preparedStmtList.add(startDate); + preparedStmtList.add(endDate); + // todo taxperiod to is in between startdate and enddate of previous billing + // cycle + } + + if (!StringUtils.isEmpty(tenantId)) { + addClauseIfRequired(preparedStmtList, builder); + builder.append(" tenantId =? "); + preparedStmtList.add(tenantId); + } + if(!CollectionUtils.isEmpty(preparedStmtList)) + builder.append("and status not IN ('CANCELLED')"); + + System.out.println("Final query ::" + builder.toString()); + return builder.toString(); + } + } 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 e4a03511b..709f2d04e 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 @@ -33,6 +33,7 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpStatus; import org.egov.common.contract.request.RequestInfo; import org.egov.common.contract.request.User; import org.egov.mdms.model.MasterDetail; @@ -51,28 +52,11 @@ 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.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; @@ -872,6 +856,9 @@ public List updateDemands(GetBillCriteria getBillCriteria, RequestInfoWr demandsToBeUpdated.add(demand); }); } + + log.info("Demamd to be updated:" + demandsToBeUpdated.size()); + log.info("Demand:::: " + demandsToBeUpdated.get(0)); // Call demand update in bulk to update the interest or penalty @@ -1409,4 +1396,210 @@ public boolean isOnlinePaymentAllowed(RequestInfo requestInfo, String tenantId) return true; } + public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { + /*List demands = updateDemands(getBillCriteria, requestInfoWrapper); + + + + + //get all tenant from master + + String tenantId = bulkDemand.getTenantId(); + requestInfo.getUserInfo().setTenantId(tenantId); + Map billingMasterData = calculatorUtils.loadBillingFrequencyMasterData(requestInfo, tenantId); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy"); + + LocalDate fromDate = LocalDate.parse(bulkDemand.getBillingPeriod().split("-")[0].trim(), formatter); + LocalDate toDate = LocalDate.parse(bulkDemand.getBillingPeriod().split("-")[1].trim(), formatter); + if(fromDate.isAfter(LocalDate.now().minusMonths(1))) { + throw new CustomException("INVALID_BILLING_CYCLE", + "Cannot generate demands for future months"); + } + + Long dayStartTime = LocalDateTime.of(fromDate.getYear(), fromDate.getMonth(), fromDate.getDayOfMonth(), 0, 0, 0) + .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + Long dayEndTime = LocalDateTime.of(toDate.getYear(), toDate.getMonth(), toDate.getDayOfMonth(), 23, 59, 59, 999000000) + .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + + List connectionNos = waterCalculatorDao.getNonMeterConnectionsList(tenantId, dayStartTime, dayEndTime);; + Set connectionSet = connectionNos.stream().collect(Collectors.toSet()); + + + if( connectionNos.size() == 0) { + List allConnections = waterCalculatorDao.searchConnectionNos(WSCalculationConstant.nonMeterdConnection, tenantId); + throw new CustomException("NO_CONNECTIONS_TO_GENERATE_DEMANDS", + "Zero Demands Generated Successfully, "+ allConnections.size() +" connections already have demands in this billing cycle!"); + } + + wsCalculationValidator.validateBulkDemandBillingPeriod(dayStartTime, dayEndTime, connectionSet, + bulkDemand.getTenantId(), (String) billingMasterData.get(WSCalculationConstant.Billing_Cycle_String)); + + HashMap demandData = new HashMap(); + demandData.put("billingMasterData", billingMasterData); + demandData.put("bulkDemand", bulkDemand); + producer.push(config.getGenerateBulkDemandTopic(), demandData);*/ + return null; + } + + + public List updateDemandToAddPenalty(Demand demand, RequestInfoWrapper requestInfoWrapper) { + /*Boolean isGetPenaltyEstimate = Boolean.valueOf(getBillCriteria.getIsGetPenaltyEstimate()); + if (getBillCriteria.getAmountExpected() == null) + getBillCriteria.setAmountExpected(BigDecimal.ZERO); + RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); + Map billingSlabMaster = new HashMap<>(); + + Map timeBasedExemptionMasterMap = new HashMap<>(); + mstrDataService.setWaterConnectionMasterValues(requestInfo, getBillCriteria.getTenantId(), billingSlabMaster, + timeBasedExemptionMasterMap); + + if (CollectionUtils.isEmpty(getBillCriteria.getConsumerCodes())) + getBillCriteria.setConsumerCodes(Collections.singletonList(getBillCriteria.getConnectionNumber())); + + DemandResponse res = mapper.convertValue( + repository.fetchResult(utils.getDemandSearchUrl(getBillCriteria), requestInfoWrapper), + DemandResponse.class); +// if (CollectionUtils.isEmpty(res.getDemands())) { +// Map map = new HashMap<>(); +// map.put(WSCalculationConstant.EMPTY_DEMAND_ERROR_CODE, WSCalculationConstant.EMPTY_DEMAND_ERROR_MESSAGE); +// throw new CustomException(map); +// } + List demandsToBeUpdated = new LinkedList<>(); + List demandResponse = new LinkedList<>(); + + // Loop through the consumerCodes and re-calculate the time base applicable + if (!CollectionUtils.isEmpty(res.getDemands())) { + List demResponse = res.getDemands(); + + + CopyOnWriteArrayList demList = new CopyOnWriteArrayList<>(demResponse); + + for(Demand demand: demList) { + if(WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(demand.getStatus().toString())){ + demList.remove(demand); + } + } + if(demList.isEmpty()) { + return res.getDemands(); + } + + Map consumerCodeToDemandMap = res.getDemands().stream() + .collect(Collectors.toMap(Demand::getId, Function.identity())); + + String tenantId = getBillCriteria.getTenantId(); + + List taxPeriods = mstrDataService.getTaxPeriodList(requestInfoWrapper.getRequestInfo(), tenantId, + WSCalculationConstant.SERVICE_FIELD_VALUE_WS); + + if(timeBasedExemptionMasterMap.get(WSCalculationConstant.WC_PENANLTY_MASTER) == null) { + mstrDataService.setWaterConnectionMasterValues(requestInfo, getBillCriteria.getTenantId().substring(0,2), billingSlabMaster, + timeBasedExemptionMasterMap); + } + + Map penaltyMaster = mstrDataService.getApplicableMaster(estimationService.getAssessmentYear(), timeBasedExemptionMasterMap.get(WSCalculationConstant.WC_PENANLTY_MASTER)); + + + if(null != penaltyMaster) { + String type = (String) penaltyMaster.get(WSCalculationConstant.TYPE_FIELD_NAME); + String subType = (String) penaltyMaster.get(WSCalculationConstant.SUBTYPE_FIELD_NAME); + + int demandListSize = demList.size(); + int demandDetailListSize = 0; + + Demand latestDemand = demList.get(demandListSize - 1); + + if(isGetPenaltyEstimate && latestDemand.getDemandDetails().stream().filter(i->i.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY)).count() > 0) { + return res.getDemands(); + } + if (latestDemand.getStatus() != null + && WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(latestDemand.getStatus().toString())) + throw new CustomException(WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR, + WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR_MSG); + if(type.equalsIgnoreCase("Flat") && subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_OUTSTANDING)) { + List demandLst = new ArrayList<>(demList); + + for(Demand demand : demandLst) { + for(DemandDetail demandDetail : demand.getDemandDetails()) { + if(demandDetail.getTaxAmount().compareTo(demandDetail.getCollectionAmount()) != 0) { + demandDetailListSize = demandDetailListSize + 1; } + } + + } + applyTimeBasedApplicables(latestDemand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate,BigDecimal.ZERO,penaltyMaster,demandDetailListSize); + demandsToBeUpdated.add(latestDemand); + + } + if((type.equalsIgnoreCase("Flat") && subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_CURRENT_MONTH)) + || (type.equalsIgnoreCase("Fixed") && subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_CURRENT_MONTH))) { + if(latestDemand.getDemandDetails().stream().filter(i->i.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)).count() > 0){ + applyTimeBasedApplicables(latestDemand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate,BigDecimal.ZERO,penaltyMaster,demandDetailListSize); + demandsToBeUpdated.add(latestDemand); + } + } + + + if(type.equalsIgnoreCase("Fixed") && (subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_OUTSTANDING) + || subType.equalsIgnoreCase(WSCalculationConstant.OUTSTANDING))) { + List demandList = new ArrayList<>(demList); + BigDecimal waterChargeApplicable = BigDecimal.ZERO; + BigDecimal oldPenalty = BigDecimal.ZERO; + demandList.remove(demandListSize - 1); + if(demandListSize > 1) { + for(Demand demand : demandList) { + for(DemandDetail demandDetail : demand.getDemandDetails()) { + if (WSCalculationConstant.TAX_APPLICABLE.contains(demandDetail.getTaxHeadMasterCode())) { + waterChargeApplicable = waterChargeApplicable.add(demandDetail.getTaxAmount()).subtract(demandDetail.getCollectionAmount()); + } + if(subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_OUTSTANDING)) { + if (demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY)) { + oldPenalty = oldPenalty.add(demandDetail.getTaxAmount()).subtract(demandDetail.getCollectionAmount()); + waterChargeApplicable = waterChargeApplicable.add(oldPenalty); + } + } + + } + } + } + + applyTimeBasedApplicables(latestDemand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate,waterChargeApplicable,penaltyMaster,demandDetailListSize); + demandsToBeUpdated.add(latestDemand); + + } + demandResponse.addAll(res.getDemands()); + } + + else { + + + if(consumerCodeToDemandMap.size() == 1) { + if (consumerCodeToDemandMap.entrySet().iterator().next().getValue().getStatus() != null + && WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(consumerCodeToDemandMap.entrySet().iterator().next().getValue().getStatus().toString())) + throw new CustomException(WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR, + WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR_MSG); + } + consumerCodeToDemandMap.forEach((id, demand) -> { + if (demand.getStatus() != null + && !WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(demand.getStatus().toString())) + applyTimeBasedApplicables(demand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate, BigDecimal.ZERO, penaltyMaster,0); +// addRoundOffTaxHead(tenantId, demand.getDemandDetails()); + demandsToBeUpdated.add(demand); + }); + } + + + // Call demand update in bulk to update the interest or penalty + if(!isGetPenaltyEstimate) { + if(demandsToBeUpdated.size() > 0) { + DemandRequest request = DemandRequest.builder().demands(demandsToBeUpdated).requestInfo(requestInfo).build(); + repository.fetchResult(utils.getUpdateDemandUrl(), request); + return res.getDemands(); + } + + } + }*/ + return null; + + } + } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java index ae575b689..a12c6f6ce 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java @@ -5,17 +5,8 @@ import javax.validation.Valid; -import org.egov.wscalculation.web.models.AdhocTaxReq; -import org.egov.wscalculation.web.models.BulkDemand; -import org.egov.wscalculation.web.models.BulkDemandResponse; -import org.egov.wscalculation.web.models.Calculation; -import org.egov.wscalculation.web.models.CalculationReq; -import org.egov.wscalculation.web.models.CalculationRes; -import org.egov.wscalculation.web.models.Demand; -import org.egov.wscalculation.web.models.DemandPenaltyResponse; -import org.egov.wscalculation.web.models.DemandResponse; -import org.egov.wscalculation.web.models.GetBillCriteria; -import org.egov.wscalculation.web.models.RequestInfoWrapper; +import org.egov.common.contract.request.RequestInfo; +import org.egov.wscalculation.web.models.*; import org.egov.wscalculation.service.DemandService; import org.egov.wscalculation.service.WSCalculationService; import org.egov.wscalculation.service.WSCalculationServiceImpl; @@ -117,4 +108,11 @@ public ResponseEntity getPenaltyDetails(@RequestBody @Val return new ResponseEntity<>(demandPenaltyResponse, HttpStatus.OK); } + + @PostMapping("/_addPenalty") + public ResponseEntity addPenalty(@RequestBody RequestInfo requestInfo, @Valid @RequestBody AddPenaltyCriteria addPenaltyCriteria) { + return demandService.addPenalty(requestInfo,addPenaltyCriteria); + + } + } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java new file mode 100644 index 000000000..5f934d1cf --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java @@ -0,0 +1,19 @@ +package org.egov.wscalculation.web.models; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class AddPenaltyCriteria { + private String limit; + private String offset; + private String tenantId; + private List tenantids; +} From 264ddace28514c901d1fc5940144cd143597ab11 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 16:53:13 +0530 Subject: [PATCH 07/63] PFM-5638: Added add Penalty api. --- .../config/WSCalculationConfiguration.java | 7 + .../constants/WSCalculationConstant.java | 1 + .../repository/DemandRepository.java | 20 ++ .../builder/DemandQueryBuilder.java | 39 +++ .../builder/WSCalculatorQueryBuilder.java | 31 --- .../wscalculation/service/DemandService.java | 227 ++---------------- .../wscalculation/util/CalculatorUtil.java | 22 ++ .../src/main/resources/application.properties | 4 + 8 files changed, 114 insertions(+), 237 deletions(-) create mode 100644 municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java 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..9e7ab48b4 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,12 @@ public class WSCalculationConfiguration { @Value("${sms.exclude.tenant}") private String smsExcludeTenant; + + @Value("${penalty.applicable.days}") + private String penaltyApplicableDays; + + @Value("${penalty.start.threshold.time}") + private Long penaltyStartThresholdTime; + } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java index 0427838ae..a5c585942 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java @@ -184,6 +184,7 @@ public class WSCalculationConstant { public static final String JSONPATH_ROOT_FOR_billingService = "$.MdmsRes.BillingService"; public static final String JSONPATH_ROOT_FOR_Allowed_PAyment = "$.MdmsRes.BillingService.PaymentService"; + public static final String JSONPATH_ROOT_FOR_Penalty = "$.MdmsRes.Penalty.Penalty"; public static final String JSON_PATH_ROOT_FOR_Allowed_PAyment = "$.MdmsRes.BillingService.BusinessService"; diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java index 6b78d5190..3f0e34add 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java @@ -1,20 +1,26 @@ package org.egov.wscalculation.repository; +import java.util.ArrayList; import java.util.List; +import java.util.Set; +import lombok.extern.slf4j.Slf4j; import org.egov.common.contract.request.RequestInfo; import org.egov.tracer.model.CustomException; import org.egov.wscalculation.config.WSCalculationConfiguration; +import org.egov.wscalculation.repository.builder.DemandQueryBuilder; import org.egov.wscalculation.web.models.Demand; import org.egov.wscalculation.web.models.DemandRequest; import org.egov.wscalculation.web.models.DemandResponse; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; import com.fasterxml.jackson.databind.ObjectMapper; @Repository +@Slf4j public class DemandRepository { @@ -27,6 +33,12 @@ public class DemandRepository { @Autowired private ObjectMapper mapper; + @Autowired + private DemandQueryBuilder queryBuilder; + + @Autowired + private JdbcTemplate jdbcTemplate; + /** * Creates demand @@ -66,5 +78,13 @@ public List updateDemand(RequestInfo requestInfo, List demands){ } } + public List getDemandsToAddPenalty(String tenantId, Long penaltyThresholdTime) { + List preparedStmtList = new ArrayList<>(); + String query = queryBuilder.getPenaltyQuery(tenantId, penaltyThresholdTime, Integer.valueOf(config.getPenaltyApplicableDays())); + System.out.println(query); + log.info("query:"+ query); + return jdbcTemplate.queryForList(query, String.class); + } + } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java new file mode 100644 index 000000000..00e0b4c1b --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -0,0 +1,39 @@ +package org.egov.wscalculation.repository.builder; + +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.Set; + +@Component +public class DemandQueryBuilder { + private String selectClause = "SELECT b.demandid FROM egbs_demanddetail_v1 b "; + private String subQuery = "SELECT dt.demandid FROM egbs_demand_v1 d LEFT OUTER JOIN egbs_demanddetail_v1 dt ON d.id = dt.demandid AND dt.taxamount > dt.collectionamount " + + "AND dt.taxheadcode = '10101'"+"AND d.status = 'ACTIVE'"; + private String firstWhereClause = "WHERE demandid IN (" ; + private String secondWhereClause = ") AND b.tenantid = '"; + + private String thresholdQueryforPenalty= "AND d."; + + String groupByClause = "GROUP BY b.demandid " + + "HAVING COUNT(*) = 1"; + + public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Integer daysToBeSubstracted ) { + long currentTimeMillis = System.currentTimeMillis(); + long tenDaysAgoMillis = Instant.ofEpochMilli(currentTimeMillis) + .minus(daysToBeSubstracted, ChronoUnit.DAYS) + .toEpochMilli(); + subQuery = subQuery + "AND d.tenantid = '"+tenantId+"'"; + subQuery = subQuery + "AND d.createdtime > " + tenDaysAgoMillis; + secondWhereClause= secondWhereClause +tenantId+"'"; + firstWhereClause = firstWhereClause + subQuery + secondWhereClause + groupByClause; + selectClause = selectClause + firstWhereClause; + StringBuilder builder = new StringBuilder(selectClause); + return builder.toString(); + } +} diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java index 08482213e..476db7821 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/WSCalculatorQueryBuilder.java @@ -277,35 +277,4 @@ public String previousBillingCycleConnectionQuery(Set connectionNos, Str return builder.toString(); } - public String getPenaltyQuery(Set connectionNos, String tenantId, Long startDate, - Long endDate, List preparedStmtList) { - - StringBuilder builder = new StringBuilder(PREVIOUS_BILLING_CYCLE_DEMAND); - - if (!CollectionUtils.isEmpty(connectionNos)) { - addClauseIfRequired(preparedStmtList, builder); - builder.append(" consumercode IN (").append(createQuery(connectionNos)).append(")"); - addToPreparedStatement(preparedStmtList, connectionNos); - } - if (startDate != null && endDate != null) { - addClauseIfRequired(preparedStmtList, builder); - builder.append(" taxperiodto between ? and ? "); - preparedStmtList.add(startDate); - preparedStmtList.add(endDate); - // todo taxperiod to is in between startdate and enddate of previous billing - // cycle - } - - if (!StringUtils.isEmpty(tenantId)) { - addClauseIfRequired(preparedStmtList, builder); - builder.append(" tenantId =? "); - preparedStmtList.add(tenantId); - } - if(!CollectionUtils.isEmpty(preparedStmtList)) - builder.append("and status not IN ('CANCELLED')"); - - System.out.println("Final query ::" + builder.toString()); - return builder.toString(); - } - } 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 709f2d04e..9bc9e2eb6 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 @@ -36,10 +36,7 @@ import org.apache.http.HttpStatus; import org.egov.common.contract.request.RequestInfo; import org.egov.common.contract.request.User; -import org.egov.mdms.model.MasterDetail; -import org.egov.mdms.model.MdmsCriteria; -import org.egov.mdms.model.MdmsCriteriaReq; -import org.egov.mdms.model.ModuleDetail; +import org.egov.mdms.model.*; import org.egov.tracer.model.CustomException; import org.egov.wscalculation.config.WSCalculationConfiguration; import org.egov.wscalculation.constants.WSCalculationConstant; @@ -1395,211 +1392,29 @@ public boolean isOnlinePaymentAllowed(RequestInfo requestInfo, String tenantId) else return true; } - - public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { - /*List demands = updateDemands(getBillCriteria, requestInfoWrapper); - - - - - //get all tenant from master - - String tenantId = bulkDemand.getTenantId(); - requestInfo.getUserInfo().setTenantId(tenantId); - Map billingMasterData = calculatorUtils.loadBillingFrequencyMasterData(requestInfo, tenantId); - - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy"); - - LocalDate fromDate = LocalDate.parse(bulkDemand.getBillingPeriod().split("-")[0].trim(), formatter); - LocalDate toDate = LocalDate.parse(bulkDemand.getBillingPeriod().split("-")[1].trim(), formatter); - if(fromDate.isAfter(LocalDate.now().minusMonths(1))) { - throw new CustomException("INVALID_BILLING_CYCLE", - "Cannot generate demands for future months"); - } - - Long dayStartTime = LocalDateTime.of(fromDate.getYear(), fromDate.getMonth(), fromDate.getDayOfMonth(), 0, 0, 0) - .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); - Long dayEndTime = LocalDateTime.of(toDate.getYear(), toDate.getMonth(), toDate.getDayOfMonth(), 23, 59, 59, 999000000) - .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); - - List connectionNos = waterCalculatorDao.getNonMeterConnectionsList(tenantId, dayStartTime, dayEndTime);; - Set connectionSet = connectionNos.stream().collect(Collectors.toSet()); - - - if( connectionNos.size() == 0) { - List allConnections = waterCalculatorDao.searchConnectionNos(WSCalculationConstant.nonMeterdConnection, tenantId); - throw new CustomException("NO_CONNECTIONS_TO_GENERATE_DEMANDS", - "Zero Demands Generated Successfully, "+ allConnections.size() +" connections already have demands in this billing cycle!"); - } - - wsCalculationValidator.validateBulkDemandBillingPeriod(dayStartTime, dayEndTime, connectionSet, - bulkDemand.getTenantId(), (String) billingMasterData.get(WSCalculationConstant.Billing_Cycle_String)); - - HashMap demandData = new HashMap(); - demandData.put("billingMasterData", billingMasterData); - demandData.put("bulkDemand", bulkDemand); - producer.push(config.getGenerateBulkDemandTopic(), demandData);*/ - return null; + public List getDemandToAddPenalty(String tenantid,Long penaltyThresholdDate){ + return demandRepository.getDemandsToAddPenalty(tenantid,penaltyThresholdDate); } + public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { + List demandids = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(),config.getPenaltyStartThresholdTime()); + log.info("demandids size:"+demandids.size()); + List masterDetails = new ArrayList<>(); + MasterDetail masterDetail =new MasterDetail("Penalty",""); + masterDetails.add(masterDetail); + ModuleDetail moduleDetail = ModuleDetail.builder().moduleName("Penalty").masterDetails(masterDetails).build(); + List moduleDetails = new ArrayList<>(); + moduleDetails.add(moduleDetail); + MdmsCriteria mdmsCriteria = MdmsCriteria.builder().tenantId(addPenaltyCriteria.getTenantId()) + .moduleDetails(moduleDetails) + .build(); + Map paymentMasterData = calculatorUtils.getPenaltyMasterForTenantId(addPenaltyCriteria.getTenantId(),mdmsCriteria,requestInfo); + String rate = (String) paymentMasterData.get("rate"); + log.info(rate); + String penaltyType = (String) paymentMasterData.get("type"); + String penaltySubType = (String) paymentMasterData.get("subType"); + log.info("Type:" + penaltyType + " Subtype:"+ penaltySubType); - public List updateDemandToAddPenalty(Demand demand, RequestInfoWrapper requestInfoWrapper) { - /*Boolean isGetPenaltyEstimate = Boolean.valueOf(getBillCriteria.getIsGetPenaltyEstimate()); - if (getBillCriteria.getAmountExpected() == null) - getBillCriteria.setAmountExpected(BigDecimal.ZERO); - RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); - Map billingSlabMaster = new HashMap<>(); - - Map timeBasedExemptionMasterMap = new HashMap<>(); - mstrDataService.setWaterConnectionMasterValues(requestInfo, getBillCriteria.getTenantId(), billingSlabMaster, - timeBasedExemptionMasterMap); - - if (CollectionUtils.isEmpty(getBillCriteria.getConsumerCodes())) - getBillCriteria.setConsumerCodes(Collections.singletonList(getBillCriteria.getConnectionNumber())); - - DemandResponse res = mapper.convertValue( - repository.fetchResult(utils.getDemandSearchUrl(getBillCriteria), requestInfoWrapper), - DemandResponse.class); -// if (CollectionUtils.isEmpty(res.getDemands())) { -// Map map = new HashMap<>(); -// map.put(WSCalculationConstant.EMPTY_DEMAND_ERROR_CODE, WSCalculationConstant.EMPTY_DEMAND_ERROR_MESSAGE); -// throw new CustomException(map); -// } - List demandsToBeUpdated = new LinkedList<>(); - List demandResponse = new LinkedList<>(); - - // Loop through the consumerCodes and re-calculate the time base applicable - if (!CollectionUtils.isEmpty(res.getDemands())) { - List demResponse = res.getDemands(); - - - CopyOnWriteArrayList demList = new CopyOnWriteArrayList<>(demResponse); - - for(Demand demand: demList) { - if(WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(demand.getStatus().toString())){ - demList.remove(demand); - } - } - if(demList.isEmpty()) { - return res.getDemands(); - } - - Map consumerCodeToDemandMap = res.getDemands().stream() - .collect(Collectors.toMap(Demand::getId, Function.identity())); - - String tenantId = getBillCriteria.getTenantId(); - - List taxPeriods = mstrDataService.getTaxPeriodList(requestInfoWrapper.getRequestInfo(), tenantId, - WSCalculationConstant.SERVICE_FIELD_VALUE_WS); - - if(timeBasedExemptionMasterMap.get(WSCalculationConstant.WC_PENANLTY_MASTER) == null) { - mstrDataService.setWaterConnectionMasterValues(requestInfo, getBillCriteria.getTenantId().substring(0,2), billingSlabMaster, - timeBasedExemptionMasterMap); - } - - Map penaltyMaster = mstrDataService.getApplicableMaster(estimationService.getAssessmentYear(), timeBasedExemptionMasterMap.get(WSCalculationConstant.WC_PENANLTY_MASTER)); - - - if(null != penaltyMaster) { - String type = (String) penaltyMaster.get(WSCalculationConstant.TYPE_FIELD_NAME); - String subType = (String) penaltyMaster.get(WSCalculationConstant.SUBTYPE_FIELD_NAME); - - int demandListSize = demList.size(); - int demandDetailListSize = 0; - - Demand latestDemand = demList.get(demandListSize - 1); - - if(isGetPenaltyEstimate && latestDemand.getDemandDetails().stream().filter(i->i.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY)).count() > 0) { - return res.getDemands(); - } - if (latestDemand.getStatus() != null - && WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(latestDemand.getStatus().toString())) - throw new CustomException(WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR, - WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR_MSG); - if(type.equalsIgnoreCase("Flat") && subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_OUTSTANDING)) { - List demandLst = new ArrayList<>(demList); - - for(Demand demand : demandLst) { - for(DemandDetail demandDetail : demand.getDemandDetails()) { - if(demandDetail.getTaxAmount().compareTo(demandDetail.getCollectionAmount()) != 0) { - demandDetailListSize = demandDetailListSize + 1; } - } - - } - applyTimeBasedApplicables(latestDemand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate,BigDecimal.ZERO,penaltyMaster,demandDetailListSize); - demandsToBeUpdated.add(latestDemand); - - } - if((type.equalsIgnoreCase("Flat") && subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_CURRENT_MONTH)) - || (type.equalsIgnoreCase("Fixed") && subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_CURRENT_MONTH))) { - if(latestDemand.getDemandDetails().stream().filter(i->i.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)).count() > 0){ - applyTimeBasedApplicables(latestDemand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate,BigDecimal.ZERO,penaltyMaster,demandDetailListSize); - demandsToBeUpdated.add(latestDemand); - } - } - - - if(type.equalsIgnoreCase("Fixed") && (subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_OUTSTANDING) - || subType.equalsIgnoreCase(WSCalculationConstant.OUTSTANDING))) { - List demandList = new ArrayList<>(demList); - BigDecimal waterChargeApplicable = BigDecimal.ZERO; - BigDecimal oldPenalty = BigDecimal.ZERO; - demandList.remove(demandListSize - 1); - if(demandListSize > 1) { - for(Demand demand : demandList) { - for(DemandDetail demandDetail : demand.getDemandDetails()) { - if (WSCalculationConstant.TAX_APPLICABLE.contains(demandDetail.getTaxHeadMasterCode())) { - waterChargeApplicable = waterChargeApplicable.add(demandDetail.getTaxAmount()).subtract(demandDetail.getCollectionAmount()); - } - if(subType.equalsIgnoreCase(WSCalculationConstant.PENALTY_OUTSTANDING)) { - if (demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY)) { - oldPenalty = oldPenalty.add(demandDetail.getTaxAmount()).subtract(demandDetail.getCollectionAmount()); - waterChargeApplicable = waterChargeApplicable.add(oldPenalty); - } - } - - } - } - } - - applyTimeBasedApplicables(latestDemand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate,waterChargeApplicable,penaltyMaster,demandDetailListSize); - demandsToBeUpdated.add(latestDemand); - - } - demandResponse.addAll(res.getDemands()); - } - - else { - - - if(consumerCodeToDemandMap.size() == 1) { - if (consumerCodeToDemandMap.entrySet().iterator().next().getValue().getStatus() != null - && WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(consumerCodeToDemandMap.entrySet().iterator().next().getValue().getStatus().toString())) - throw new CustomException(WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR, - WSCalculationConstant.EG_WS_INVALID_DEMAND_ERROR_MSG); - } - consumerCodeToDemandMap.forEach((id, demand) -> { - if (demand.getStatus() != null - && !WSCalculationConstant.DEMAND_CANCELLED_STATUS.equalsIgnoreCase(demand.getStatus().toString())) - applyTimeBasedApplicables(demand, requestInfoWrapper, timeBasedExemptionMasterMap, taxPeriods, isGetPenaltyEstimate, BigDecimal.ZERO, penaltyMaster,0); -// addRoundOffTaxHead(tenantId, demand.getDemandDetails()); - demandsToBeUpdated.add(demand); - }); - } - - - // Call demand update in bulk to update the interest or penalty - if(!isGetPenaltyEstimate) { - if(demandsToBeUpdated.size() > 0) { - DemandRequest request = DemandRequest.builder().demands(demandsToBeUpdated).requestInfo(requestInfo).build(); - repository.fetchResult(utils.getUpdateDemandUrl(), request); - return res.getDemands(); - } - - } - }*/ return null; - } - } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java index 1381ef966..afd85d4ba 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java @@ -394,5 +394,27 @@ public Map getAllowedPaymentForTenantId(String tenantId, MdmsCri + } + public Map getPenaltyMasterForTenantId(String tenantId, MdmsCriteria mdmsCriteria, RequestInfo requestInfo) { + MdmsCriteriaReq mdmsCriteriaReq = MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build(); + Object res = serviceRequestRepository.fetchResult(getMdmsSearchUrl(), mdmsCriteriaReq); + if (res == null) { + throw new CustomException("MDMS_ERROR_FOR_BILLING_FREQUENCY", "ERROR IN FETCHING THE ALLOWED PAYMENT FOR TENANTID " + tenantId); + } + log.info("Response", res); + Map mdmsres = JsonPath.read(res, WSCalculationConstant.JSONPATH_ROOT_FOR_mdmsRes); + Map mdmsPenaltyMaster = JsonPath.read(res,WSCalculationConstant.JSONPATH_ROOT_FOR_Penalty); + if(mdmsres.isEmpty() || mdmsPenaltyMaster.isEmpty()) { + log.info("Inside No MDMS response found for tenantId::::" +tenantId); + String stateLevelTenantId = tenantId.split("\\.")[0]; + mdmsCriteriaReq.getMdmsCriteria().setTenantId(stateLevelTenantId); + res = serviceRequestRepository.fetchResult(getMdmsSearchUrl(), mdmsCriteriaReq); + } + + List> jsonOutput = JsonPath.read(res, WSCalculationConstant.JSONPATH_ROOT_FOR_Penalty); + return jsonOutput.get(0); + + + } } diff --git a/municipal-services/ws-calculator/src/main/resources/application.properties b/municipal-services/ws-calculator/src/main/resources/application.properties index 9b8bb7a36..d302ef0ad 100644 --- a/municipal-services/ws-calculator/src/main/resources/application.properties +++ b/municipal-services/ws-calculator/src/main/resources/application.properties @@ -146,3 +146,7 @@ sms.demand.enabled: true sms.payment.link.enabled: true sms.bill.download.enabled: true sms.exclude.tenant="pb.testing" + +#Penalty Config +penalty.start.threshold.time= 10000000 +penalty.applicable.days= 10 From 3c9fae5501d65c17d9df78025489f52ee582095a Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 16:55:39 +0530 Subject: [PATCH 08/63] PFM-5638: Added add Penalty api. --- .../java/org/egov/wscalculation/service/DemandService.java | 3 --- 1 file changed, 3 deletions(-) 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 9bc9e2eb6..929ec0c2f 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 @@ -853,9 +853,6 @@ public List updateDemands(GetBillCriteria getBillCriteria, RequestInfoWr demandsToBeUpdated.add(demand); }); } - - log.info("Demamd to be updated:" + demandsToBeUpdated.size()); - log.info("Demand:::: " + demandsToBeUpdated.get(0)); // Call demand update in bulk to update the interest or penalty From 7843b37bd66d2c25bb052144f61d60fb2e8ef7de Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 17:24:56 +0530 Subject: [PATCH 09/63] PFM-5638: Added add Penalty api. --- .../web/controller/CalculatorController.java | 4 ++-- .../web/models/AddPenaltyCriteria.java | 6 +++--- .../web/models/PenaltyRequest.java | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/PenaltyRequest.java diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java index a12c6f6ce..b9d2e7b96 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/controller/CalculatorController.java @@ -110,8 +110,8 @@ public ResponseEntity getPenaltyDetails(@RequestBody @Val @PostMapping("/_addPenalty") - public ResponseEntity addPenalty(@RequestBody RequestInfo requestInfo, @Valid @RequestBody AddPenaltyCriteria addPenaltyCriteria) { - return demandService.addPenalty(requestInfo,addPenaltyCriteria); + public ResponseEntity addPenalty(@RequestBody PenaltyRequest penaltyRequest) { + return demandService.addPenalty(penaltyRequest.getRequestInfo(),penaltyRequest.getAddPenaltyCriteria()); } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java index 5f934d1cf..4b065e591 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/AddPenaltyCriteria.java @@ -1,5 +1,6 @@ package org.egov.wscalculation.web.models; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -12,8 +13,7 @@ @AllArgsConstructor @Builder public class AddPenaltyCriteria { - private String limit; - private String offset; + + @JsonProperty("tenantId") private String tenantId; - private List tenantids; } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/PenaltyRequest.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/PenaltyRequest.java new file mode 100644 index 000000000..c4ae96440 --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/PenaltyRequest.java @@ -0,0 +1,20 @@ +package org.egov.wscalculation.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +@Validated +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Builder +public class PenaltyRequest { + @JsonProperty("requestInfo") + private RequestInfo requestInfo; + + @JsonProperty("addPenaltyCriteria") + private AddPenaltyCriteria addPenaltyCriteria; +} From e4ae5d6448c6904490271ecf52bad49cd109d4da Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 17:59:50 +0530 Subject: [PATCH 10/63] PFM-5638: Added add Penalty api. --- .../java/org/egov/wscalculation/service/DemandService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 929ec0c2f..c0e2fb176 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 @@ -1397,9 +1397,9 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add List demandids = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(),config.getPenaltyStartThresholdTime()); log.info("demandids size:"+demandids.size()); List masterDetails = new ArrayList<>(); - MasterDetail masterDetail =new MasterDetail("Penalty",""); + MasterDetail masterDetail =new MasterDetail("Penalty","[?(@)]"); masterDetails.add(masterDetail); - ModuleDetail moduleDetail = ModuleDetail.builder().moduleName("Penalty").masterDetails(masterDetails).build(); + ModuleDetail moduleDetail = ModuleDetail.builder().moduleName("ws-services-calculation").masterDetails(masterDetails).build(); List moduleDetails = new ArrayList<>(); moduleDetails.add(moduleDetail); MdmsCriteria mdmsCriteria = MdmsCriteria.builder().tenantId(addPenaltyCriteria.getTenantId()) From 88ea266329d618c258c0493147d15d9276f8c705 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 19:53:58 +0530 Subject: [PATCH 11/63] PFM-5638: Added add Penalty api. --- .../wscalculation/service/DemandService.java | 83 ++++++++++++++++++- 1 file changed, 80 insertions(+), 3 deletions(-) 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 c0e2fb176..ce9f36a85 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 @@ -622,6 +622,19 @@ public List searchDemand(String tenantId, Set consumerCodes, Lon } + public List searchDemandBydemandId(String tenantId, Set demandids, + RequestInfo requestInfo) { + Object result = serviceRequestRepository.fetchResult( + getDemandSearchURLByDemandId(tenantId, demandids), + RequestInfoWrapper.builder().requestInfo(requestInfo).build()); + try { + return mapper.convertValue(result, DemandResponse.class).getDemands(); + } catch (IllegalArgumentException e) { + throw new CustomException("PARSING_ERROR", "Failed to parse response from Demand Search"); + } + + } + /** * Creates demand Search url based on tenantId,businessService, and * @@ -704,6 +717,17 @@ public StringBuilder getDemandSearchURL(String tenantId, Set consumerCod return url; } + public StringBuilder getDemandSearchURLByDemandId(String tenantId, Set demandIds) { + StringBuilder url = new StringBuilder(configs.getBillingServiceHost()); + url.append(configs.getDemandSearchEndPoint()); + url.append("?"); + url.append("tenantId="); + url.append(tenantId); + url.append("&"); + url.append("demandId="); + url.append(StringUtils.join(demandIds, ',')); + return url; + } /** * * @param getBillCriteria Bill Criteria @@ -1394,8 +1418,8 @@ public List getDemandToAddPenalty(String tenantid,Long penaltyThreshold } public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { - List demandids = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(),config.getPenaltyStartThresholdTime()); - log.info("demandids size:"+demandids.size()); + List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(),config.getPenaltyStartThresholdTime()); + log.info("demandids size:"+demandIds.size()); List masterDetails = new ArrayList<>(); MasterDetail masterDetail =new MasterDetail("Penalty","[?(@)]"); masterDetails.add(masterDetail); @@ -1411,7 +1435,60 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add String penaltyType = (String) paymentMasterData.get("type"); String penaltySubType = (String) paymentMasterData.get("subType"); log.info("Type:" + penaltyType + " Subtype:"+ penaltySubType); + demandIds.stream().forEach(demandId ->{ + Set demandids = new HashSet<>(); + demandids.add(demandId); + List demands = searchDemandBydemandId(addPenaltyCriteria.getTenantId(),demandids,requestInfo); + if(!CollectionUtils.isEmpty(demands)) { + Demand demand = demands.get(0); + Boolean isPenaltyExistForDemand = demand.getDemandDetails().stream().anyMatch(demandDetail -> { + return demandDetail.getTaxHeadMasterCode().equalsIgnoreCase("WS_TIME_PENALTY"); + }); + if(!isPenaltyExistForDemand) { + if(CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { + + demand.setDemandDetails(addTimePenalty(rate,penaltyType,penaltySubType,demand)); + demands.add(demand); + List demandRes = demandRepository.updateDemand(requestInfo, demands); + log.info("DemandResponse size:" +demandRes.size()); + if(!CollectionUtils.isEmpty(demandRes)) { + log.info("Demand res::" + demandRes.get(0)); + log.info("Demand res:" , demandRes.get(0)); + fetchBillDate(demandRes,requestInfo); + } + } + } + } + }); + return new ResponseEntity<>(org.springframework.http.HttpStatus.ACCEPTED); + } - return null; + public List addTimePenalty(String rate, String type, String SubType,Demand demand) { + + BigDecimal taxPercentage = BigDecimal.valueOf(Double.valueOf(rate)); + List demandDetailList= demand.getDemandDetails(); + DemandDetail waterChargeDemandDetails = (DemandDetail) demandDetailList.stream().filter(demandDetail -> demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)); + BigDecimal netPayableAmountWithouttax= waterChargeDemandDetails.getTaxAmount().subtract(waterChargeDemandDetails.getCollectionAmount()); + if(netPayableAmountWithouttax.signum()> 0) { + BigDecimal tax = netPayableAmountWithouttax.multiply(taxPercentage.divide(WSCalculationConstant.HUNDRED)); + //round off to next higest number + tax = roundOffTax(tax); + DemandDetail timeDemandDetail = DemandDetail.builder().demandId(demand.getId()) + .taxHeadMasterCode(WSCalculationConstant.WS_TIME_PENALTY) + .taxAmount(tax) + .collectionAmount(BigDecimal.ZERO) + .tenantId(demand.getTenantId()).build(); + + demandDetailList.add(timeDemandDetail); + } + return demandDetailList; + + } + + public BigDecimal roundOffTax (BigDecimal tax) { + + // Round the value up to the next highest integer + BigDecimal roundedValue = tax.setScale(0, RoundingMode.CEILING); + return roundedValue; } } From da9154880a99f7531aa439dae1527845d46532de Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 20:14:02 +0530 Subject: [PATCH 12/63] PFM-5638: Added add Penalty api. --- .../org/egov/wscalculation/service/DemandService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 ce9f36a85..f36197359 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 @@ -726,6 +726,7 @@ public StringBuilder getDemandSearchURLByDemandId(String tenantId, Set d url.append("&"); url.append("demandId="); url.append(StringUtils.join(demandIds, ',')); + log.info("Search demand url:"+url); return url; } /** @@ -1438,17 +1439,18 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add demandIds.stream().forEach(demandId ->{ Set demandids = new HashSet<>(); demandids.add(demandId); - List demands = searchDemandBydemandId(addPenaltyCriteria.getTenantId(),demandids,requestInfo); - if(!CollectionUtils.isEmpty(demands)) { + List demands = searchDemandBydemandId(addPenaltyCriteria.getTenantId(),demandids,requestInfo); + if(!CollectionUtils.isEmpty(demands)) { Demand demand = demands.get(0); Boolean isPenaltyExistForDemand = demand.getDemandDetails().stream().anyMatch(demandDetail -> { return demandDetail.getTaxHeadMasterCode().equalsIgnoreCase("WS_TIME_PENALTY"); }); + log.info("isPenaltyExistForDemand : "+isPenaltyExistForDemand); if(!isPenaltyExistForDemand) { if(CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { - demand.setDemandDetails(addTimePenalty(rate,penaltyType,penaltySubType,demand)); demands.add(demand); + log.info("Demand:"+ demands); List demandRes = demandRepository.updateDemand(requestInfo, demands); log.info("DemandResponse size:" +demandRes.size()); if(!CollectionUtils.isEmpty(demandRes)) { @@ -1481,6 +1483,7 @@ public List addTimePenalty(String rate, String type, String SubTyp demandDetailList.add(timeDemandDetail); } + log.info("demandDetailList:"+demandDetailList); return demandDetailList; } From 8308ff7dc0874ce1a4ddfbaa887dbf70113b69e7 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 20:45:10 +0530 Subject: [PATCH 13/63] PFM-5638: Added add Penalty api. --- .../org/egov/wscalculation/constants/WSCalculationConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java index a5c585942..159e51fa0 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java @@ -184,7 +184,7 @@ public class WSCalculationConstant { public static final String JSONPATH_ROOT_FOR_billingService = "$.MdmsRes.BillingService"; public static final String JSONPATH_ROOT_FOR_Allowed_PAyment = "$.MdmsRes.BillingService.PaymentService"; - public static final String JSONPATH_ROOT_FOR_Penalty = "$.MdmsRes.Penalty.Penalty"; + public static final String JSONPATH_ROOT_FOR_Penalty = "$.MdmsRes.ws-services-calculation.Penalty"; public static final String JSON_PATH_ROOT_FOR_Allowed_PAyment = "$.MdmsRes.BillingService.BusinessService"; From e5000a51445d1e2596f1bbe694cb45d0b45c842f Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 20:58:13 +0530 Subject: [PATCH 14/63] PFM-5638: Added add Penalty api. --- .../egov/wscalculation/constants/WSCalculationConstant.java | 3 +++ .../main/java/org/egov/wscalculation/util/CalculatorUtil.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java index 159e51fa0..cd2ca1378 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/constants/WSCalculationConstant.java @@ -184,8 +184,11 @@ public class WSCalculationConstant { public static final String JSONPATH_ROOT_FOR_billingService = "$.MdmsRes.BillingService"; public static final String JSONPATH_ROOT_FOR_Allowed_PAyment = "$.MdmsRes.BillingService.PaymentService"; + public static final String JSONPATH_ROOT_FOR_ws_service_calculator = "$.MdmsRes.ws-services-calculation"; public static final String JSONPATH_ROOT_FOR_Penalty = "$.MdmsRes.ws-services-calculation.Penalty"; + + public static final String JSON_PATH_ROOT_FOR_Allowed_PAyment = "$.MdmsRes.BillingService.BusinessService"; public static final String Quaterly_Billing_Period = "quarterly"; diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java index afd85d4ba..dc11204fd 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/util/CalculatorUtil.java @@ -403,7 +403,7 @@ public Map getPenaltyMasterForTenantId(String tenantId, MdmsCrit } log.info("Response", res); Map mdmsres = JsonPath.read(res, WSCalculationConstant.JSONPATH_ROOT_FOR_mdmsRes); - Map mdmsPenaltyMaster = JsonPath.read(res,WSCalculationConstant.JSONPATH_ROOT_FOR_Penalty); + Map mdmsPenaltyMaster = JsonPath.read(res,WSCalculationConstant.JSONPATH_ROOT_FOR_ws_service_calculator); if(mdmsres.isEmpty() || mdmsPenaltyMaster.isEmpty()) { log.info("Inside No MDMS response found for tenantId::::" +tenantId); String stateLevelTenantId = tenantId.split("\\.")[0]; From fa53295cacac270d6b9dc6d056b7b166444d4468 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 21:14:25 +0530 Subject: [PATCH 15/63] PFM-5638: Added add Penalty api. --- .../org/egov/wscalculation/service/DemandService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 f36197359..f0516f6c5 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 @@ -1431,9 +1431,9 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add .moduleDetails(moduleDetails) .build(); Map paymentMasterData = calculatorUtils.getPenaltyMasterForTenantId(addPenaltyCriteria.getTenantId(),mdmsCriteria,requestInfo); - String rate = (String) paymentMasterData.get("rate"); - log.info(rate); - String penaltyType = (String) paymentMasterData.get("type"); + Integer rate = (Integer) paymentMasterData.get("rate"); + log.info("Rate"+String.valueOf(rate)); + String penaltyType = String.valueOf(paymentMasterData.get("type")); String penaltySubType = (String) paymentMasterData.get("subType"); log.info("Type:" + penaltyType + " Subtype:"+ penaltySubType); demandIds.stream().forEach(demandId ->{ @@ -1465,7 +1465,7 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add return new ResponseEntity<>(org.springframework.http.HttpStatus.ACCEPTED); } - public List addTimePenalty(String rate, String type, String SubType,Demand demand) { + public List addTimePenalty(Integer rate, String type, String SubType,Demand demand) { BigDecimal taxPercentage = BigDecimal.valueOf(Double.valueOf(rate)); List demandDetailList= demand.getDemandDetails(); From 162aef4aa0c03220244396ebc6a569ce554b553c Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 21:33:14 +0530 Subject: [PATCH 16/63] PFM-5638: Added add Penalty api. --- .../java/org/egov/wscalculation/service/DemandService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 f0516f6c5..99bce83bc 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 @@ -1447,7 +1447,8 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add }); log.info("isPenaltyExistForDemand : "+isPenaltyExistForDemand); if(!isPenaltyExistForDemand) { - if(CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { + log.info("inside if"); + if(!CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { demand.setDemandDetails(addTimePenalty(rate,penaltyType,penaltySubType,demand)); demands.add(demand); log.info("Demand:"+ demands); From 61d5bf5f651f936d08967b131336c81bd0aff8c0 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 21:55:32 +0530 Subject: [PATCH 17/63] PFM-5638: Added add Penalty api. --- .../wscalculation/service/DemandService.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) 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 99bce83bc..992e3efdd 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 @@ -1470,20 +1470,28 @@ public List addTimePenalty(Integer rate, String type, String SubTy BigDecimal taxPercentage = BigDecimal.valueOf(Double.valueOf(rate)); List demandDetailList= demand.getDemandDetails(); - DemandDetail waterChargeDemandDetails = (DemandDetail) demandDetailList.stream().filter(demandDetail -> demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)); - BigDecimal netPayableAmountWithouttax= waterChargeDemandDetails.getTaxAmount().subtract(waterChargeDemandDetails.getCollectionAmount()); - if(netPayableAmountWithouttax.signum()> 0) { - BigDecimal tax = netPayableAmountWithouttax.multiply(taxPercentage.divide(WSCalculationConstant.HUNDRED)); - //round off to next higest number - tax = roundOffTax(tax); - DemandDetail timeDemandDetail = DemandDetail.builder().demandId(demand.getId()) - .taxHeadMasterCode(WSCalculationConstant.WS_TIME_PENALTY) - .taxAmount(tax) - .collectionAmount(BigDecimal.ZERO) - .tenantId(demand.getTenantId()).build(); - - demandDetailList.add(timeDemandDetail); + DemandDetail waterChargeDemandDetails = null; + if(!CollectionUtils.isEmpty(demandDetailList)) { + if(demandDetailList.get(0).getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)){ + log.info("Inside if of addTimePenalty"); + //mapper.convertValue(demandDetailList.stream().filter(demandDetail -> demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)), DemandDetail.class) ; + waterChargeDemandDetails=demandDetailList.get(0); + BigDecimal netPayableAmountWithouttax= waterChargeDemandDetails.getTaxAmount().subtract(waterChargeDemandDetails.getCollectionAmount()); + if(netPayableAmountWithouttax.signum()> 0) { + BigDecimal tax = netPayableAmountWithouttax.multiply(taxPercentage.divide(WSCalculationConstant.HUNDRED)); + //round off to next higest number + tax = roundOffTax(tax); + DemandDetail timeDemandDetail = DemandDetail.builder().demandId(demand.getId()) + .taxHeadMasterCode(WSCalculationConstant.WS_TIME_PENALTY) + .taxAmount(tax) + .collectionAmount(BigDecimal.ZERO) + .tenantId(demand.getTenantId()).build(); + + demandDetailList.add(timeDemandDetail); + } + } } + log.info("demandDetailList:"+demandDetailList); return demandDetailList; From 5fe91cfa5566cef85d0f3340d42f12307e0025af Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 21:59:39 +0530 Subject: [PATCH 18/63] PFM-5638: Added add Penalty api. --- .../egov/wscalculation/service/DemandService.java | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) 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 992e3efdd..b456cecd7 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 @@ -12,19 +12,7 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.TextStyle; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Function; import java.util.stream.Collectors; From 93adc54b7ac642023871df231073beec73455142 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 12 Mar 2024 22:47:59 +0530 Subject: [PATCH 19/63] PFM-5638: Added add Penalty api. --- .../main/java/org/egov/wscalculation/service/DemandService.java | 1 + 1 file changed, 1 insertion(+) 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 b456cecd7..cf859f81f 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 @@ -1438,6 +1438,7 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add log.info("inside if"); if(!CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { demand.setDemandDetails(addTimePenalty(rate,penaltyType,penaltySubType,demand)); + demands.clear(); demands.add(demand); log.info("Demand:"+ demands); List demandRes = demandRepository.updateDemand(requestInfo, demands); From 207d0585d795c899089575f2ddfb400f8faa13cc Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 13 Mar 2024 11:18:33 +0530 Subject: [PATCH 20/63] PFM-5638: Added add Penalty api. --- .../ws-calculator/src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/municipal-services/ws-calculator/src/main/resources/application.properties b/municipal-services/ws-calculator/src/main/resources/application.properties index d302ef0ad..85fb4db5b 100644 --- a/municipal-services/ws-calculator/src/main/resources/application.properties +++ b/municipal-services/ws-calculator/src/main/resources/application.properties @@ -149,4 +149,4 @@ sms.exclude.tenant="pb.testing" #Penalty Config penalty.start.threshold.time= 10000000 -penalty.applicable.days= 10 +penalty.applicable.days= 180 From 5473ec016b140231eb5370c7b3fca95b1207c651 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 13 Mar 2024 11:25:41 +0530 Subject: [PATCH 21/63] PFM-5638: Added add Penalty api. --- .../ws-calculator/src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/municipal-services/ws-calculator/src/main/resources/application.properties b/municipal-services/ws-calculator/src/main/resources/application.properties index 85fb4db5b..11318056f 100644 --- a/municipal-services/ws-calculator/src/main/resources/application.properties +++ b/municipal-services/ws-calculator/src/main/resources/application.properties @@ -149,4 +149,4 @@ sms.exclude.tenant="pb.testing" #Penalty Config penalty.start.threshold.time= 10000000 -penalty.applicable.days= 180 +penalty.applicable.days= 45 From 035f968a97c2320863aea796b41dc332544f1fd1 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 13 Mar 2024 12:47:25 +0530 Subject: [PATCH 22/63] PFM-5638: Added limit to test in UAT --- .../builder/DemandQueryBuilder.java | 5 +- .../wscalculation/service/DemandService.java | 63 ++++++++++--------- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index 00e0b4c1b..5e07cddda 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -21,15 +21,16 @@ public class DemandQueryBuilder { private String thresholdQueryforPenalty= "AND d."; String groupByClause = "GROUP BY b.demandid " + - "HAVING COUNT(*) = 1"; + "HAVING COUNT(*) = 1 limit 10"; public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Integer daysToBeSubstracted ) { + //TODO: find out days long currentTimeMillis = System.currentTimeMillis(); long tenDaysAgoMillis = Instant.ofEpochMilli(currentTimeMillis) .minus(daysToBeSubstracted, ChronoUnit.DAYS) .toEpochMilli(); subQuery = subQuery + "AND d.tenantid = '"+tenantId+"'"; - subQuery = subQuery + "AND d.createdtime > " + tenDaysAgoMillis; + subQuery = subQuery + "AND d.createdtime < " + tenDaysAgoMillis + " order by d.createdtime asc "; secondWhereClause= secondWhereClause +tenantId+"'"; firstWhereClause = firstWhereClause + subQuery + secondWhereClause + groupByClause; selectClause = selectClause + firstWhereClause; 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 cf859f81f..9483225f2 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 @@ -1424,38 +1424,42 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add String penaltyType = String.valueOf(paymentMasterData.get("type")); String penaltySubType = (String) paymentMasterData.get("subType"); log.info("Type:" + penaltyType + " Subtype:"+ penaltySubType); - demandIds.stream().forEach(demandId ->{ - Set demandids = new HashSet<>(); - demandids.add(demandId); - List demands = searchDemandBydemandId(addPenaltyCriteria.getTenantId(),demandids,requestInfo); - if(!CollectionUtils.isEmpty(demands)) { - Demand demand = demands.get(0); - Boolean isPenaltyExistForDemand = demand.getDemandDetails().stream().anyMatch(demandDetail -> { - return demandDetail.getTaxHeadMasterCode().equalsIgnoreCase("WS_TIME_PENALTY"); - }); - log.info("isPenaltyExistForDemand : "+isPenaltyExistForDemand); - if(!isPenaltyExistForDemand) { - log.info("inside if"); - if(!CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { - demand.setDemandDetails(addTimePenalty(rate,penaltyType,penaltySubType,demand)); - demands.clear(); - demands.add(demand); - log.info("Demand:"+ demands); - List demandRes = demandRepository.updateDemand(requestInfo, demands); - log.info("DemandResponse size:" +demandRes.size()); - if(!CollectionUtils.isEmpty(demandRes)) { - log.info("Demand res::" + demandRes.get(0)); - log.info("Demand res:" , demandRes.get(0)); - fetchBillDate(demandRes,requestInfo); - } - } - } - } - }); + if(rate>0) { + demandIds.stream().forEach(demandId -> { + Set demandids = new HashSet<>(); + demandids.add(demandId); + List demands = searchDemandBydemandId(addPenaltyCriteria.getTenantId(), demandids, requestInfo); + if (!CollectionUtils.isEmpty(demands)) { + Demand demand = demands.get(0); + Boolean isPenaltyExistForDemand = demand.getDemandDetails().stream().anyMatch(demandDetail -> { + return demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY); + }); + log.info("isPenaltyExistForDemand : " + isPenaltyExistForDemand); + if (!isPenaltyExistForDemand) { + log.info("inside if"); + if (!CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { + demand.setDemandDetails(addTimePenalty(rate, penaltyType, penaltySubType, demand)); + demands.clear(); + demands.add(demand); + log.info("Demand:" + demands); + List demandRes = demandRepository.updateDemand(requestInfo, demands); + log.info("DemandResponse size:" + demandRes.size()); + if (!CollectionUtils.isEmpty(demandRes)) { + log.info("Demand res::" + demandRes.get(0)); + log.info("Demand res:", demandRes.get(0)); + fetchBillDate(demandRes, requestInfo); + } + } + } + } + }); + } return new ResponseEntity<>(org.springframework.http.HttpStatus.ACCEPTED); } public List addTimePenalty(Integer rate, String type, String SubType,Demand demand) { + // TODO: if type is fixed annd subtype is curretmonnth than only add penalty + //TODO : check for metered connection also what is taxheadcode BigDecimal taxPercentage = BigDecimal.valueOf(Double.valueOf(rate)); List demandDetailList= demand.getDemandDetails(); @@ -1489,7 +1493,6 @@ public List addTimePenalty(Integer rate, String type, String SubTy public BigDecimal roundOffTax (BigDecimal tax) { // Round the value up to the next highest integer - BigDecimal roundedValue = tax.setScale(0, RoundingMode.CEILING); - return roundedValue; + return tax.setScale(0, RoundingMode.CEILING); } } From 9f9c1fca2cf173f6eaa3603147b3777c146fe6c4 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 13 Mar 2024 13:54:55 +0530 Subject: [PATCH 23/63] PFM-5638: Added limit to test in UAT --- .../wscalculation/repository/builder/DemandQueryBuilder.java | 4 ++-- .../ws-calculator/src/main/resources/application.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index 5e07cddda..8df6a86df 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -21,7 +21,7 @@ public class DemandQueryBuilder { private String thresholdQueryforPenalty= "AND d."; String groupByClause = "GROUP BY b.demandid " + - "HAVING COUNT(*) = 1 limit 10"; + "HAVING COUNT(*) = 1 "; public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Integer daysToBeSubstracted ) { //TODO: find out days @@ -30,7 +30,7 @@ public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Intege .minus(daysToBeSubstracted, ChronoUnit.DAYS) .toEpochMilli(); subQuery = subQuery + "AND d.tenantid = '"+tenantId+"'"; - subQuery = subQuery + "AND d.createdtime < " + tenDaysAgoMillis + " order by d.createdtime asc "; + subQuery = subQuery + "AND d.createdtime < " + tenDaysAgoMillis; secondWhereClause= secondWhereClause +tenantId+"'"; firstWhereClause = firstWhereClause + subQuery + secondWhereClause + groupByClause; selectClause = selectClause + firstWhereClause; diff --git a/municipal-services/ws-calculator/src/main/resources/application.properties b/municipal-services/ws-calculator/src/main/resources/application.properties index 11318056f..d302ef0ad 100644 --- a/municipal-services/ws-calculator/src/main/resources/application.properties +++ b/municipal-services/ws-calculator/src/main/resources/application.properties @@ -149,4 +149,4 @@ sms.exclude.tenant="pb.testing" #Penalty Config penalty.start.threshold.time= 10000000 -penalty.applicable.days= 45 +penalty.applicable.days= 10 From 5eea17089c67a121dc2becd5dfebc95fa35e3b2d Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 13 Mar 2024 14:39:46 +0530 Subject: [PATCH 24/63] PFM-5638: Added add penaltyApi --- .../config/WSCalculationConfiguration.java | 7 +- .../repository/DemandRepository.java | 2 +- .../builder/DemandQueryBuilder.java | 7 +- .../wscalculation/service/DemandService.java | 89 ++++++++++--------- .../src/main/resources/application.properties | 3 +- 5 files changed, 58 insertions(+), 50 deletions(-) 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 9e7ab48b4..eb63ec460 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 @@ -250,11 +250,12 @@ public class WSCalculationConfiguration { @Value("${sms.exclude.tenant}") private String smsExcludeTenant; - @Value("${penalty.applicable.days}") - private String penaltyApplicableDays; + @Value("${penalty.applicable.in.days}") + private Integer penaltyApplicableDays; @Value("${penalty.start.threshold.time}") private Long penaltyStartThresholdTime; - + @Value("${is.penalty.feature.enable}") + private boolean isPenaltyEnabled; } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java index 3f0e34add..b3573c564 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java @@ -80,7 +80,7 @@ public List updateDemand(RequestInfo requestInfo, List demands){ public List getDemandsToAddPenalty(String tenantId, Long penaltyThresholdTime) { List preparedStmtList = new ArrayList<>(); - String query = queryBuilder.getPenaltyQuery(tenantId, penaltyThresholdTime, Integer.valueOf(config.getPenaltyApplicableDays())); + String query = queryBuilder.getPenaltyQuery(tenantId, penaltyThresholdTime, config.getPenaltyApplicableDays()); System.out.println(query); log.info("query:"+ query); return jdbcTemplate.queryForList(query, String.class); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index 8df6a86df..d9cfb4e8f 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -29,8 +29,11 @@ public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Intege long tenDaysAgoMillis = Instant.ofEpochMilli(currentTimeMillis) .minus(daysToBeSubstracted, ChronoUnit.DAYS) .toEpochMilli(); - subQuery = subQuery + "AND d.tenantid = '"+tenantId+"'"; - subQuery = subQuery + "AND d.createdtime < " + tenDaysAgoMillis; + subQuery = subQuery + " AND d.tenantid = '"+tenantId+"'"; + subQuery = subQuery + " AND d.createdtime < " + tenDaysAgoMillis; + if(!ObjectUtils.isEmpty(penaltyThresholdDate) && penaltyThresholdDate > 0) { + subQuery = subQuery + " AND d.taxperiodfrom > " + penaltyThresholdDate; + } secondWhereClause= secondWhereClause +tenantId+"'"; firstWhereClause = firstWhereClause + subQuery + secondWhereClause + groupByClause; selectClause = selectClause + firstWhereClause; 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 9483225f2..05c2a3616 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 @@ -1407,52 +1407,55 @@ public List getDemandToAddPenalty(String tenantid,Long penaltyThreshold } public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { - List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(),config.getPenaltyStartThresholdTime()); - log.info("demandids size:"+demandIds.size()); - List masterDetails = new ArrayList<>(); - MasterDetail masterDetail =new MasterDetail("Penalty","[?(@)]"); - masterDetails.add(masterDetail); - ModuleDetail moduleDetail = ModuleDetail.builder().moduleName("ws-services-calculation").masterDetails(masterDetails).build(); - List moduleDetails = new ArrayList<>(); - moduleDetails.add(moduleDetail); - MdmsCriteria mdmsCriteria = MdmsCriteria.builder().tenantId(addPenaltyCriteria.getTenantId()) - .moduleDetails(moduleDetails) - .build(); - Map paymentMasterData = calculatorUtils.getPenaltyMasterForTenantId(addPenaltyCriteria.getTenantId(),mdmsCriteria,requestInfo); - Integer rate = (Integer) paymentMasterData.get("rate"); - log.info("Rate"+String.valueOf(rate)); - String penaltyType = String.valueOf(paymentMasterData.get("type")); - String penaltySubType = (String) paymentMasterData.get("subType"); - log.info("Type:" + penaltyType + " Subtype:"+ penaltySubType); - if(rate>0) { - demandIds.stream().forEach(demandId -> { - Set demandids = new HashSet<>(); - demandids.add(demandId); - List demands = searchDemandBydemandId(addPenaltyCriteria.getTenantId(), demandids, requestInfo); - if (!CollectionUtils.isEmpty(demands)) { - Demand demand = demands.get(0); - Boolean isPenaltyExistForDemand = demand.getDemandDetails().stream().anyMatch(demandDetail -> { - return demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY); - }); - log.info("isPenaltyExistForDemand : " + isPenaltyExistForDemand); - if (!isPenaltyExistForDemand) { - log.info("inside if"); - if (!CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { - demand.setDemandDetails(addTimePenalty(rate, penaltyType, penaltySubType, demand)); - demands.clear(); - demands.add(demand); - log.info("Demand:" + demands); - List demandRes = demandRepository.updateDemand(requestInfo, demands); - log.info("DemandResponse size:" + demandRes.size()); - if (!CollectionUtils.isEmpty(demandRes)) { - log.info("Demand res::" + demandRes.get(0)); - log.info("Demand res:", demandRes.get(0)); - fetchBillDate(demandRes, requestInfo); + if(config.isPenaltyEnabled()) { + List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(), config.getPenaltyStartThresholdTime()); + log.info("demandids size:" + demandIds.size()); + List masterDetails = new ArrayList<>(); + MasterDetail masterDetail = new MasterDetail("Penalty", "[?(@)]"); + masterDetails.add(masterDetail); + ModuleDetail moduleDetail = ModuleDetail.builder().moduleName("ws-services-calculation").masterDetails(masterDetails).build(); + List moduleDetails = new ArrayList<>(); + moduleDetails.add(moduleDetail); + MdmsCriteria mdmsCriteria = MdmsCriteria.builder().tenantId(addPenaltyCriteria.getTenantId()) + .moduleDetails(moduleDetails) + .build(); + Map paymentMasterData = calculatorUtils.getPenaltyMasterForTenantId(addPenaltyCriteria.getTenantId(), mdmsCriteria, requestInfo); + Integer rate = (Integer) paymentMasterData.get("rate"); + log.info("Rate" + String.valueOf(rate)); + String penaltyType = String.valueOf(paymentMasterData.get("type")); + String penaltySubType = (String) paymentMasterData.get("subType"); + log.info("Type:" + penaltyType + " Subtype:" + penaltySubType); + if (rate > 0) { + demandIds.stream().forEach(demandId -> { + Set demandids = new HashSet<>(); + demandids.add(demandId); + List demands = searchDemandBydemandId(addPenaltyCriteria.getTenantId(), demandids, requestInfo); + if (!CollectionUtils.isEmpty(demands)) { + Demand demand = demands.get(0); + Boolean isPenaltyExistForDemand = demand.getDemandDetails().stream().anyMatch(demandDetail -> { + return demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY); + }); + log.info("isPenaltyExistForDemand : " + isPenaltyExistForDemand); + if (!isPenaltyExistForDemand) { + log.info("inside if"); + if (!CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { + demand.setDemandDetails(addTimePenalty(rate, penaltyType, penaltySubType, demand)); + demands.clear(); + demands.add(demand); + log.info("Demand:" + demands); + List demandRes = demandRepository.updateDemand(requestInfo, demands); + log.info("DemandResponse size:" + demandRes.size()); + if (!CollectionUtils.isEmpty(demandRes)) { + log.info("Demand res::" + demandRes.get(0)); + log.info("Demand res:", demandRes.get(0)); + fetchBillDate(demandRes, requestInfo); + } } } } - } - }); + }); + } + return new ResponseEntity<>(org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED); } return new ResponseEntity<>(org.springframework.http.HttpStatus.ACCEPTED); } diff --git a/municipal-services/ws-calculator/src/main/resources/application.properties b/municipal-services/ws-calculator/src/main/resources/application.properties index d302ef0ad..a4cf5233e 100644 --- a/municipal-services/ws-calculator/src/main/resources/application.properties +++ b/municipal-services/ws-calculator/src/main/resources/application.properties @@ -149,4 +149,5 @@ sms.exclude.tenant="pb.testing" #Penalty Config penalty.start.threshold.time= 10000000 -penalty.applicable.days= 10 +penalty.applicable.in.days= 10 +is.penalty.feature.enable= true From 382f716cdcb77c87eb1bee12401a49a4665aa1f3 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 14:06:18 +0530 Subject: [PATCH 25/63] PFM-5638: Added topic to reduce time. --- .../config/WSCalculationConfiguration.java | 3 +++ .../consumer/DemandGenerationConsumer.java | 21 +++++++----------- .../wscalculation/service/DemandService.java | 22 +++++-------------- .../src/main/resources/application.properties | 1 + 4 files changed, 18 insertions(+), 29 deletions(-) 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 eb63ec460..c5b9da834 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 @@ -258,4 +258,7 @@ public class WSCalculationConfiguration { @Value("${is.penalty.feature.enable}") private boolean isPenaltyEnabled; + + @Value("${egov.update.demand.add.penalty}") + private String updateAddPenaltytopic; } 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..7517b165c 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 @@ -16,6 +16,7 @@ import java.util.Set; import java.util.stream.Collectors; +import com.fasterxml.jackson.core.type.TypeReference; import org.apache.commons.lang3.StringUtils; import org.egov.common.contract.request.RequestInfo; import org.egov.tracer.model.CustomException; @@ -33,19 +34,7 @@ import org.egov.wscalculation.util.WSCalculationUtil; import org.egov.wscalculation.validator.WSCalculationValidator; import org.egov.wscalculation.validator.WSCalculationWorkflowValidator; -import org.egov.wscalculation.web.models.Action; -import org.egov.wscalculation.web.models.ActionItem; -import org.egov.wscalculation.web.models.BulkDemand; -import org.egov.wscalculation.web.models.CalculationCriteria; -import org.egov.wscalculation.web.models.CalculationReq; -import org.egov.wscalculation.web.models.Category; -import org.egov.wscalculation.web.models.Demand; -import org.egov.wscalculation.web.models.Event; -import org.egov.wscalculation.web.models.EventRequest; -import org.egov.wscalculation.web.models.OwnerInfo; -import org.egov.wscalculation.web.models.Recipient; -import org.egov.wscalculation.web.models.SMSRequest; -import org.egov.wscalculation.web.models.Source; +import org.egov.wscalculation.web.models.*; import org.egov.wscalculation.web.models.users.UserDetailResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.kafka.annotation.KafkaListener; @@ -547,4 +536,10 @@ public void generateBulkDemandForULB(HashMap messageData) { } + @KafkaListener(topics = { + "${egov.update.demand.add.penalty}" }, containerFactory = "kafkaListenerContainerFactory") + public void updateAddPenalty(HashMap messageData) { + DemandRequest demandRequest = mapper.convertValue(messageData, DemandRequest.class); + demandService.updateDemandAddPenalty(demandRequest.getRequestInfo(), demandRequest.getDemands()); + } } 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 05c2a3616..ac1fc08a9 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 @@ -1409,7 +1409,6 @@ public List getDemandToAddPenalty(String tenantid,Long penaltyThreshold public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { if(config.isPenaltyEnabled()) { List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(), config.getPenaltyStartThresholdTime()); - log.info("demandids size:" + demandIds.size()); List masterDetails = new ArrayList<>(); MasterDetail masterDetail = new MasterDetail("Penalty", "[?(@)]"); masterDetails.add(masterDetail); @@ -1421,10 +1420,8 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add .build(); Map paymentMasterData = calculatorUtils.getPenaltyMasterForTenantId(addPenaltyCriteria.getTenantId(), mdmsCriteria, requestInfo); Integer rate = (Integer) paymentMasterData.get("rate"); - log.info("Rate" + String.valueOf(rate)); String penaltyType = String.valueOf(paymentMasterData.get("type")); String penaltySubType = (String) paymentMasterData.get("subType"); - log.info("Type:" + penaltyType + " Subtype:" + penaltySubType); if (rate > 0) { demandIds.stream().forEach(demandId -> { Set demandids = new HashSet<>(); @@ -1435,21 +1432,13 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add Boolean isPenaltyExistForDemand = demand.getDemandDetails().stream().anyMatch(demandDetail -> { return demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_TIME_PENALTY); }); - log.info("isPenaltyExistForDemand : " + isPenaltyExistForDemand); if (!isPenaltyExistForDemand) { - log.info("inside if"); if (!CollectionUtils.isEmpty(demand.getDemandDetails()) && demand.getDemandDetails().size() == 1) { demand.setDemandDetails(addTimePenalty(rate, penaltyType, penaltySubType, demand)); demands.clear(); demands.add(demand); - log.info("Demand:" + demands); - List demandRes = demandRepository.updateDemand(requestInfo, demands); - log.info("DemandResponse size:" + demandRes.size()); - if (!CollectionUtils.isEmpty(demandRes)) { - log.info("Demand res::" + demandRes.get(0)); - log.info("Demand res:", demandRes.get(0)); - fetchBillDate(demandRes, requestInfo); - } + DemandRequest demandRequest = DemandRequest.builder().requestInfo(requestInfo).demands(demands).build(); + producer.push(config.getUpdateAddPenaltytopic(), demandRequest); } } } @@ -1469,7 +1458,6 @@ public List addTimePenalty(Integer rate, String type, String SubTy DemandDetail waterChargeDemandDetails = null; if(!CollectionUtils.isEmpty(demandDetailList)) { if(demandDetailList.get(0).getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)){ - log.info("Inside if of addTimePenalty"); //mapper.convertValue(demandDetailList.stream().filter(demandDetail -> demandDetail.getTaxHeadMasterCode().equalsIgnoreCase(WSCalculationConstant.WS_CHARGE)), DemandDetail.class) ; waterChargeDemandDetails=demandDetailList.get(0); BigDecimal netPayableAmountWithouttax= waterChargeDemandDetails.getTaxAmount().subtract(waterChargeDemandDetails.getCollectionAmount()); @@ -1487,8 +1475,6 @@ public List addTimePenalty(Integer rate, String type, String SubTy } } } - - log.info("demandDetailList:"+demandDetailList); return demandDetailList; } @@ -1498,4 +1484,8 @@ public BigDecimal roundOffTax (BigDecimal tax) { // Round the value up to the next highest integer return tax.setScale(0, RoundingMode.CEILING); } + + public void updateDemandAddPenalty(RequestInfo requestInfo , List demands) { + demandRepository.updateDemand(requestInfo,demands); + } } diff --git a/municipal-services/ws-calculator/src/main/resources/application.properties b/municipal-services/ws-calculator/src/main/resources/application.properties index a4cf5233e..d983bd124 100644 --- a/municipal-services/ws-calculator/src/main/resources/application.properties +++ b/municipal-services/ws-calculator/src/main/resources/application.properties @@ -151,3 +151,4 @@ sms.exclude.tenant="pb.testing" penalty.start.threshold.time= 10000000 penalty.applicable.in.days= 10 is.penalty.feature.enable= true +egov.update.demand.add.penalty= egov-update-demand-add-penalty \ No newline at end of file From d57780eea766db96d0f1277da1698c05caca69a1 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 18:18:45 +0530 Subject: [PATCH 26/63] PFM-5638: Added log line to check . --- .../wscalculation/repository/DemandRepository.java | 1 - .../repository/builder/DemandQueryBuilder.java | 7 ++++--- .../org/egov/wscalculation/service/DemandService.java | 10 ++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java index b3573c564..1b51e45ff 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java @@ -81,7 +81,6 @@ public List updateDemand(RequestInfo requestInfo, List demands){ public List getDemandsToAddPenalty(String tenantId, Long penaltyThresholdTime) { List preparedStmtList = new ArrayList<>(); String query = queryBuilder.getPenaltyQuery(tenantId, penaltyThresholdTime, config.getPenaltyApplicableDays()); - System.out.println(query); log.info("query:"+ query); return jdbcTemplate.queryForList(query, String.class); } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index d9cfb4e8f..6fee74a97 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -1,5 +1,6 @@ package org.egov.wscalculation.repository.builder; +import jdk.jpackage.internal.Log; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -18,9 +19,7 @@ public class DemandQueryBuilder { private String firstWhereClause = "WHERE demandid IN (" ; private String secondWhereClause = ") AND b.tenantid = '"; - private String thresholdQueryforPenalty= "AND d."; - - String groupByClause = "GROUP BY b.demandid " + + String groupByClause = " GROUP BY b.demandid " + "HAVING COUNT(*) = 1 "; public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Integer daysToBeSubstracted ) { @@ -38,6 +37,8 @@ public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Intege firstWhereClause = firstWhereClause + subQuery + secondWhereClause + groupByClause; selectClause = selectClause + firstWhereClause; StringBuilder builder = new StringBuilder(selectClause); + Log.info("Query formed :" + builder.toString()); return builder.toString(); + } } 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 ac1fc08a9..c2a326302 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 @@ -1419,7 +1419,12 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add .moduleDetails(moduleDetails) .build(); Map paymentMasterData = calculatorUtils.getPenaltyMasterForTenantId(addPenaltyCriteria.getTenantId(), mdmsCriteria, requestInfo); - Integer rate = (Integer) paymentMasterData.get("rate"); + Integer rate = 0; + try { + rate= (Integer) paymentMasterData.get("rate"); + }catch (Exception e) { + rate = 0; + } String penaltyType = String.valueOf(paymentMasterData.get("type")); String penaltySubType = (String) paymentMasterData.get("subType"); if (rate > 0) { @@ -1443,8 +1448,9 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add } } }); + } else { + return new ResponseEntity<>(org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED); } - return new ResponseEntity<>(org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED); } return new ResponseEntity<>(org.springframework.http.HttpStatus.ACCEPTED); } From 4451c82bea89d5f9527195049e04f7476ec873ba Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 18:32:12 +0530 Subject: [PATCH 27/63] PFM-5638: Added log line to check . --- .../repository/builder/DemandQueryBuilder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index 6fee74a97..2b2161e38 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -1,6 +1,7 @@ package org.egov.wscalculation.repository.builder; -import jdk.jpackage.internal.Log; + +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -12,6 +13,7 @@ import java.util.Set; @Component +@Slf4j public class DemandQueryBuilder { private String selectClause = "SELECT b.demandid FROM egbs_demanddetail_v1 b "; private String subQuery = "SELECT dt.demandid FROM egbs_demand_v1 d LEFT OUTER JOIN egbs_demanddetail_v1 dt ON d.id = dt.demandid AND dt.taxamount > dt.collectionamount " + @@ -37,7 +39,7 @@ public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Intege firstWhereClause = firstWhereClause + subQuery + secondWhereClause + groupByClause; selectClause = selectClause + firstWhereClause; StringBuilder builder = new StringBuilder(selectClause); - Log.info("Query formed :" + builder.toString()); + log.info("Query formed :" + builder.toString()); return builder.toString(); } From befc2fa5795751bc489f220487b1a9084a285fcd Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 18:37:46 +0530 Subject: [PATCH 28/63] PFM-5638: added changes for Penalty Schedular. --- .../java/org/egov/config/PenaltyShedularConfiguration.java | 1 - .../src/main/java/org/egov/job/PenaltySchedularJob.java | 7 ++----- .../src/main/java/org/egov/model/AddPenaltyCriteria.java | 3 --- .../Penalty/src/main/java/org/egov/util/MDMSClient.java | 4 ++-- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java b/utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java index ce7c8ea0b..86fc7b389 100644 --- a/utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java +++ b/utilities/Penalty/src/main/java/org/egov/config/PenaltyShedularConfiguration.java @@ -4,7 +4,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Import; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; diff --git a/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java b/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java index b24b92645..63e4c7f58 100644 --- a/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java +++ b/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java @@ -10,12 +10,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; -import org.springframework.http.*; import org.springframework.stereotype.Component; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -39,7 +37,6 @@ public void run(ApplicationArguments args) throws Exception { try { List tenantList = mdmsClient.getTenants(); - System.out.println(tenantList.size()); tenantList=tenantList.stream().filter( tenant -> { return adapterConfiguration.getPenaltyEnabledDivisionlist().contains(tenant.getDivisionCode()); @@ -54,7 +51,7 @@ public void run(ApplicationArguments args) throws Exception { }); } catch (Exception e) { - log.error("Exception occurred while running PenaltySchedularJob", e); + log.info("Exception occurred while running PenaltySchedularJob", e); } } @@ -67,7 +64,7 @@ public void addPenaltyEventToWaterCalculator(AddPenaltyCriteria penaltyCriteria) log.info("Posted request to add Penalty for tenant:" + penaltyCriteria.getTenantId()); } catch (RestClientException e) { - log.error("Error while calling to water calculator service for tenant :" + penaltyCriteria.getTenantId() + " ERROR MESSAGE:" + e.getMessage(), e.getCause()); + log.info("Error while calling to water calculator service for tenant :" + penaltyCriteria.getTenantId() + " ERROR MESSAGE:" + e.getMessage(), e.getCause()); } } } diff --git a/utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java b/utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java index b929ff747..954d5a20a 100644 --- a/utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java +++ b/utilities/Penalty/src/main/java/org/egov/model/AddPenaltyCriteria.java @@ -4,8 +4,6 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; - -import javax.validation.constraints.NotNull; import java.util.List; @Data @@ -15,7 +13,6 @@ public class AddPenaltyCriteria { private String limit; private String offset; - @NotNull private String tenantId; private List tenantids; } diff --git a/utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java b/utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java index 40e780b68..542af33cd 100644 --- a/utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java +++ b/utilities/Penalty/src/main/java/org/egov/util/MDMSClient.java @@ -72,7 +72,7 @@ protected void loadTenantsFromMdms() { } if (mdmsResponse != null && (mdmsResponse.getMdmsRes() == null || mdmsResponse.getMdmsRes().isEmpty())) { - log.error("Tenants file is missing in mdms!!"); + log.info("Tenants file is missing in mdms!!"); } else { if (mdmsResponse.getMdmsRes().get(PenaltySchedularConstant.MDMS_MODULE_NAME) != null && mdmsResponse.getMdmsRes().get(PenaltySchedularConstant.MDMS_MODULE_NAME) .get(PenaltySchedularConstant.MDMS_TENANT_MASTER_NAME) != null) { @@ -88,7 +88,7 @@ protected void loadTenantsFromMdms() { } } catch (IOException e) { - log.error("Error occurred while getting the account to gp mapping from MDMS", e); + log.info("Error occurred while getting the account to gp mapping from MDMS", e); } } From 25e61c79bc0b73256ad0e2312d1273cbf3ba3854 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 18:45:53 +0530 Subject: [PATCH 29/63] PFM-5638: Added log line to check . --- .../org/egov/wscalculation/service/DemandService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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 c2a326302..655ba7742 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 @@ -1419,12 +1419,8 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add .moduleDetails(moduleDetails) .build(); Map paymentMasterData = calculatorUtils.getPenaltyMasterForTenantId(addPenaltyCriteria.getTenantId(), mdmsCriteria, requestInfo); - Integer rate = 0; - try { - rate= (Integer) paymentMasterData.get("rate"); - }catch (Exception e) { - rate = 0; - } + + Integer rate= (Integer) paymentMasterData.get("rate"); String penaltyType = String.valueOf(paymentMasterData.get("type")); String penaltySubType = (String) paymentMasterData.get("subType"); if (rate > 0) { From fb54fe9a8093ea8d9400a9ff8025a96af29a67a0 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 19:05:13 +0530 Subject: [PATCH 30/63] PFM-5638: added changes for Penalty Schedular. --- utilities/Penalty/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utilities/Penalty/pom.xml b/utilities/Penalty/pom.xml index 33855dfd6..05de62088 100644 --- a/utilities/Penalty/pom.xml +++ b/utilities/Penalty/pom.xml @@ -10,10 +10,10 @@ org.egov - penalty-schedular + egov-penalty-schedular 1.0-SNAPSHOT - penalty-schedular - penalty schedular + egov-penalty-schedular + egov-penalty schedular org.springframework.boot From 6e3e776d1a59bf8ccd7b98d82653c06fddedb381 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 19:16:38 +0530 Subject: [PATCH 31/63] PFM-5638: added changes for Penalty Schedular. --- utilities/Penalty/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/utilities/Penalty/pom.xml b/utilities/Penalty/pom.xml index 05de62088..81b5f02eb 100644 --- a/utilities/Penalty/pom.xml +++ b/utilities/Penalty/pom.xml @@ -127,9 +127,6 @@ - 19 - 19 - UTF-8 1.8 2.17.1 42.3.3 From 0357dc2badf8a869b292603e7b6f3f64882c2685 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 19:25:45 +0530 Subject: [PATCH 32/63] PFM-5638: Added log line to check . --- .../repository/builder/DemandQueryBuilder.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index 2b2161e38..b776d5451 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -15,13 +15,13 @@ @Component @Slf4j public class DemandQueryBuilder { - private String selectClause = "SELECT b.demandid FROM egbs_demanddetail_v1 b "; - private String subQuery = "SELECT dt.demandid FROM egbs_demand_v1 d LEFT OUTER JOIN egbs_demanddetail_v1 dt ON d.id = dt.demandid AND dt.taxamount > dt.collectionamount " + + private static String selectClause = "SELECT b.demandid FROM egbs_demanddetail_v1 b "; + private static String subQuery = "SELECT dt.demandid FROM egbs_demand_v1 d LEFT OUTER JOIN egbs_demanddetail_v1 dt ON d.id = dt.demandid AND dt.taxamount > dt.collectionamount " + "AND dt.taxheadcode = '10101'"+"AND d.status = 'ACTIVE'"; - private String firstWhereClause = "WHERE demandid IN (" ; - private String secondWhereClause = ") AND b.tenantid = '"; + private static String firstWhereClause = "WHERE demandid IN (" ; + private static String secondWhereClause = ") AND b.tenantid = '"; - String groupByClause = " GROUP BY b.demandid " + + private static String groupByClause = " GROUP BY b.demandid " + "HAVING COUNT(*) = 1 "; public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Integer daysToBeSubstracted ) { From 7c28ce4225872ee76b8586b01a89d55111ca8e27 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 14 Mar 2024 20:02:41 +0530 Subject: [PATCH 33/63] PFM-5638: Added change in Query --- .../builder/DemandQueryBuilder.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index b776d5451..75d322fec 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -15,13 +15,13 @@ @Component @Slf4j public class DemandQueryBuilder { - private static String selectClause = "SELECT b.demandid FROM egbs_demanddetail_v1 b "; - private static String subQuery = "SELECT dt.demandid FROM egbs_demand_v1 d LEFT OUTER JOIN egbs_demanddetail_v1 dt ON d.id = dt.demandid AND dt.taxamount > dt.collectionamount " + + private final static String selectClause = "SELECT b.demandid FROM egbs_demanddetail_v1 b "; + private final static String subQuery = "SELECT dt.demandid FROM egbs_demand_v1 d LEFT OUTER JOIN egbs_demanddetail_v1 dt ON d.id = dt.demandid AND dt.taxamount > dt.collectionamount " + "AND dt.taxheadcode = '10101'"+"AND d.status = 'ACTIVE'"; - private static String firstWhereClause = "WHERE demandid IN (" ; - private static String secondWhereClause = ") AND b.tenantid = '"; + private final static String firstWhereClause = "WHERE demandid IN (" ; + private final static String secondWhereClause = ") AND b.tenantid = '"; - private static String groupByClause = " GROUP BY b.demandid " + + private final static String groupByClause = " GROUP BY b.demandid " + "HAVING COUNT(*) = 1 "; public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Integer daysToBeSubstracted ) { @@ -30,15 +30,14 @@ public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Intege long tenDaysAgoMillis = Instant.ofEpochMilli(currentTimeMillis) .minus(daysToBeSubstracted, ChronoUnit.DAYS) .toEpochMilli(); - subQuery = subQuery + " AND d.tenantid = '"+tenantId+"'"; - subQuery = subQuery + " AND d.createdtime < " + tenDaysAgoMillis; - if(!ObjectUtils.isEmpty(penaltyThresholdDate) && penaltyThresholdDate > 0) { - subQuery = subQuery + " AND d.taxperiodfrom > " + penaltyThresholdDate; - } - secondWhereClause= secondWhereClause +tenantId+"'"; - firstWhereClause = firstWhereClause + subQuery + secondWhereClause + groupByClause; - selectClause = selectClause + firstWhereClause; - StringBuilder builder = new StringBuilder(selectClause); + String subStringQuery ; + subStringQuery = subQuery + " AND d.tenantid = '"+tenantId+"'" + + " AND d.createdtime < " + tenDaysAgoMillis + " AND d.taxperiodfrom > " + penaltyThresholdDate; + String firstStringWhereClause; + firstStringWhereClause = firstWhereClause + subStringQuery + secondWhereClause + tenantId+"'"+ groupByClause; + String query ; + query = selectClause + firstStringWhereClause; + StringBuilder builder = new StringBuilder(query); log.info("Query formed :" + builder.toString()); return builder.toString(); From e5a07fa76fd9991c99ee46305f6ed39c0b287b96 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 22 Apr 2024 10:13:24 +0530 Subject: [PATCH 34/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../egov/demand/service/DemandService.java | 86 +++++++++++++++++-- .../web/controller/DemandController.java | 12 +++ 2 files changed, 89 insertions(+), 9 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 7d717c049..4a31ea0da 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -42,14 +42,7 @@ import static org.egov.demand.util.Constants.ADVANCE_TAXHEAD_JSONPATH_CODE; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import javax.validation.Valid; @@ -358,7 +351,7 @@ public List getDemands(DemandCriteria demandCriteria, RequestInfo reques } } } - + if (!CollectionUtils.isEmpty(demands) && !CollectionUtils.isEmpty(payers)) demands = demandEnrichmentUtil.enrichPayer(demands, payers); @@ -373,7 +366,82 @@ public void update(DemandRequest demandRequest, PaymentBackUpdateAudit paymentBa demandRepository.update(demandRequest, paymentBackUpdateAudit); } + public List getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { + demandValidatorV1.validateDemandCriteria(demandCriteria, requestInfo); + + UserSearchRequest userSearchRequest = null; + List payers = null; + List demands = null; + + String userUri = applicationProperties.getUserServiceHostName() + .concat(applicationProperties.getUserServiceSearchPath()); + + /* + * user type is CITIZEN by default because only citizen can have demand or payer can be null + */ + String citizenTenantId = demandCriteria.getTenantId().split("\\.")[0]; + + /* + * If payer related data is provided first then user search has to be made first followed by demand search + */ + if (demandCriteria.getEmail() != null || demandCriteria.getMobileNumber() != null) { + + userSearchRequest = UserSearchRequest.builder().requestInfo(requestInfo) + .tenantId(citizenTenantId).emailId(demandCriteria.getEmail()) + .mobileNumber(demandCriteria.getMobileNumber()).build(); + + payers = mapper.convertValue(serviceRequestRepository.fetchResult(userUri, userSearchRequest), UserResponse.class).getUser(); + + if(CollectionUtils.isEmpty(payers)) + return new ArrayList<>(); + + Set ownerIds = payers.stream().map(User::getUuid).collect(Collectors.toSet()); + demandCriteria.setPayer(ownerIds); + demands = demandRepository.getDemands(demandCriteria); + + } else { + + /* + * If no payer related data given then search demand first then enrich payer(user) data + */ + demands = demandRepository.getDemands(demandCriteria); + if (!demands.isEmpty()) { + + Set payerUuids = demands.stream().filter(demand -> null != demand.getPayer()) + .map(demand -> demand.getPayer().getUuid()).collect(Collectors.toSet()); + + if (!CollectionUtils.isEmpty(payerUuids)) { + + userSearchRequest = UserSearchRequest.builder().requestInfo(requestInfo).uuid(payerUuids).build(); + + payers = mapper.convertValue(serviceRequestRepository.fetchResult(userUri, userSearchRequest), + UserResponse.class).getUser(); + } + } + } + + if (!CollectionUtils.isEmpty(demands) && !CollectionUtils.isEmpty(payers)) + demands = demandEnrichmentUtil.enrichPayer(demands, payers); + + Map> demandMap = new HashMap<>(); + + for (Demand demand : demands) { + Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); + List demandDetails = demand.getDemandDetails(); + demandMap.put(taxPeriodFrom, demandDetails); + } + log.info("Demand Details:",demandMap); + // Print the demand map + for (Map.Entry> entry : demandMap.entrySet()) { + log.info("Tax Period From: " ,entry.getKey()); + System.out.println("Demand Details:"); + for (DemandDetail detail : entry.getValue()) { + log.info("DemandDetails:",detail); + } + } + return demands; + } /** * Calls the demand apportion API if any advance amoount is available for that comsumer code * @param demandRequest The demand request for create diff --git a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java index 6d3331a67..9eba440c7 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java @@ -162,5 +162,17 @@ public ResponseEntity history(@RequestBody RequestInfoWrapper requestInfoWrap responseInfo(responseFactory.getResponseInfo(requestInfo, HttpStatus.OK)).build(); return new ResponseEntity<>(response, HttpStatus.OK); } + + @PostMapping("_getAggregateDemandDetails") + public ResponseEntity getAggregatedDemandDetails(@RequestBody RequestInfoWrapper requestInfoWrapper, + @ModelAttribute @Valid DemandCriteria demandCriteria) { + + RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); + + List demands = demandService.getAllDemands(demandCriteria, requestInfo); + DemandResponse response = DemandResponse.builder().demands(demands) + .responseInfo(responseFactory.getResponseInfo(requestInfo, HttpStatus.OK)).build(); + return new ResponseEntity<>(response, HttpStatus.OK); + } } \ No newline at end of file From 8779aea21e9bf5a5c5c50da3b49b9cb82a796485 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 22 Apr 2024 11:41:32 +0530 Subject: [PATCH 35/63] PFM-5638: added changes for Penalty Schedular. --- .../org/egov/job/PenaltySchedularJob.java | 7 +++++-- .../java/org/egov/model/PenaltyRequest.java | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 utilities/Penalty/src/main/java/org/egov/model/PenaltyRequest.java diff --git a/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java b/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java index 63e4c7f58..bb80024a5 100644 --- a/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java +++ b/utilities/Penalty/src/main/java/org/egov/job/PenaltySchedularJob.java @@ -3,8 +3,10 @@ import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.egov.common.contract.request.RequestInfo; import org.egov.config.PenaltyShedularConfiguration; import org.egov.model.AddPenaltyCriteria; +import org.egov.model.PenaltyRequest; import org.egov.model.Tenant; import org.egov.util.MDMSClient; import org.springframework.beans.factory.annotation.Autowired; @@ -56,11 +58,12 @@ public void run(ApplicationArguments args) throws Exception { } public void addPenaltyEventToWaterCalculator(AddPenaltyCriteria penaltyCriteria) { + PenaltyRequest penaltyRequest = PenaltyRequest.builder().requestInfo(RequestInfo.builder().build()).addPenaltyCriteria(penaltyCriteria).build(); log.info("Posting request to add Penalty for tenantid:" +penaltyCriteria.getTenantId()); - + log.info("Penalty Request", penaltyRequest); if (penaltyCriteria.getTenantId() != null) { try { - restTemplate.put(getWaterConnnectionAddPennanltyUrl(), penaltyCriteria); + restTemplate.put(getWaterConnnectionAddPennanltyUrl(), penaltyRequest); log.info("Posted request to add Penalty for tenant:" + penaltyCriteria.getTenantId()); } catch (RestClientException e) { diff --git a/utilities/Penalty/src/main/java/org/egov/model/PenaltyRequest.java b/utilities/Penalty/src/main/java/org/egov/model/PenaltyRequest.java new file mode 100644 index 000000000..47d6724c8 --- /dev/null +++ b/utilities/Penalty/src/main/java/org/egov/model/PenaltyRequest.java @@ -0,0 +1,21 @@ +package org.egov.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; +import org.egov.common.contract.request.RequestInfo; +import org.springframework.validation.annotation.Validated; + +@Validated +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Builder +public class PenaltyRequest { + @JsonProperty("requestInfo") + private RequestInfo requestInfo; + + @JsonProperty("addPenaltyCriteria") + private AddPenaltyCriteria addPenaltyCriteria; +} + From af45981ac362778bc51b72d1788330490bc34ed0 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 22 Apr 2024 14:05:32 +0530 Subject: [PATCH 36/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../main/java/org/egov/demand/service/DemandService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 4a31ea0da..2811c6edb 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -368,7 +368,7 @@ public void update(DemandRequest demandRequest, PaymentBackUpdateAudit paymentBa public List getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { - demandValidatorV1.validateDemandCriteria(demandCriteria, requestInfo); + //demandValidatorV1.validateDemandCriteria(demandCriteria, requestInfo); UserSearchRequest userSearchRequest = null; List payers = null; @@ -431,13 +431,13 @@ public List getAllDemands(DemandCriteria demandCriteria, RequestInfo req List demandDetails = demand.getDemandDetails(); demandMap.put(taxPeriodFrom, demandDetails); } - log.info("Demand Details:",demandMap); + log.info("Demand Details:"+demandMap); // Print the demand map for (Map.Entry> entry : demandMap.entrySet()) { - log.info("Tax Period From: " ,entry.getKey()); + log.info("Tax Period From: " + entry.getKey()); System.out.println("Demand Details:"); for (DemandDetail detail : entry.getValue()) { - log.info("DemandDetails:",detail); + log.info("DemandDetails:"+detail); } } return demands; From af70c3365bb89da5efaebd091789d49a2c9e6c2d Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 22 Apr 2024 14:21:39 +0530 Subject: [PATCH 37/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../egov/demand/service/DemandService.java | 36 +++++-------------- .../web/controller/DemandController.java | 7 ++-- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 2811c6edb..2c06d3c84 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -366,7 +366,7 @@ public void update(DemandRequest demandRequest, PaymentBackUpdateAudit paymentBa demandRepository.update(demandRequest, paymentBackUpdateAudit); } - public List getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { + public Map> getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { //demandValidatorV1.validateDemandCriteria(demandCriteria, requestInfo); @@ -385,39 +385,22 @@ public List getAllDemands(DemandCriteria demandCriteria, RequestInfo req /* * If payer related data is provided first then user search has to be made first followed by demand search */ - if (demandCriteria.getEmail() != null || demandCriteria.getMobileNumber() != null) { - - userSearchRequest = UserSearchRequest.builder().requestInfo(requestInfo) - .tenantId(citizenTenantId).emailId(demandCriteria.getEmail()) - .mobileNumber(demandCriteria.getMobileNumber()).build(); - - payers = mapper.convertValue(serviceRequestRepository.fetchResult(userUri, userSearchRequest), UserResponse.class).getUser(); - - if(CollectionUtils.isEmpty(payers)) - return new ArrayList<>(); - - Set ownerIds = payers.stream().map(User::getUuid).collect(Collectors.toSet()); - demandCriteria.setPayer(ownerIds); - demands = demandRepository.getDemands(demandCriteria); - - } else { /* * If no payer related data given then search demand first then enrich payer(user) data */ - demands = demandRepository.getDemands(demandCriteria); - if (!demands.isEmpty()) { + demands = demandRepository.getDemands(demandCriteria); + if (!demands.isEmpty()) { - Set payerUuids = demands.stream().filter(demand -> null != demand.getPayer()) - .map(demand -> demand.getPayer().getUuid()).collect(Collectors.toSet()); + Set payerUuids = demands.stream().filter(demand -> null != demand.getPayer()) + .map(demand -> demand.getPayer().getUuid()).collect(Collectors.toSet()); - if (!CollectionUtils.isEmpty(payerUuids)) { + if (!CollectionUtils.isEmpty(payerUuids)) { - userSearchRequest = UserSearchRequest.builder().requestInfo(requestInfo).uuid(payerUuids).build(); + userSearchRequest = UserSearchRequest.builder().requestInfo(requestInfo).uuid(payerUuids).build(); - payers = mapper.convertValue(serviceRequestRepository.fetchResult(userUri, userSearchRequest), + payers = mapper.convertValue(serviceRequestRepository.fetchResult(userUri, userSearchRequest), UserResponse.class).getUser(); - } } } @@ -435,12 +418,11 @@ public List getAllDemands(DemandCriteria demandCriteria, RequestInfo req // Print the demand map for (Map.Entry> entry : demandMap.entrySet()) { log.info("Tax Period From: " + entry.getKey()); - System.out.println("Demand Details:"); for (DemandDetail detail : entry.getValue()) { log.info("DemandDetails:"+detail); } } - return demands; + return demandMap; } /** * Calls the demand apportion API if any advance amoount is available for that comsumer code diff --git a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java index 9eba440c7..5aff19c61 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java @@ -48,6 +48,7 @@ import org.egov.demand.config.ApplicationProperties; import org.egov.demand.model.Demand; import org.egov.demand.model.DemandCriteria; +import org.egov.demand.model.DemandDetail; import org.egov.demand.model.DemandHistory; import org.egov.demand.producer.Producer; import org.egov.demand.service.DemandService; @@ -169,10 +170,8 @@ public ResponseEntity getAggregatedDemandDetails(@RequestBody RequestInfoWrap RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); - List demands = demandService.getAllDemands(demandCriteria, requestInfo); - DemandResponse response = DemandResponse.builder().demands(demands) - .responseInfo(responseFactory.getResponseInfo(requestInfo, HttpStatus.OK)).build(); - return new ResponseEntity<>(response, HttpStatus.OK); + Map> demands = demandService.getAllDemands(demandCriteria, requestInfo); + return new ResponseEntity<>(demandCriteria, HttpStatus.OK); } } \ No newline at end of file From ff52ad21ec92fc6fe3057adf9cfc3bdd6ebbc41c Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 22 Apr 2024 14:30:56 +0530 Subject: [PATCH 38/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../java/org/egov/demand/web/controller/DemandController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java index 5aff19c61..10e306295 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java @@ -171,7 +171,7 @@ public ResponseEntity getAggregatedDemandDetails(@RequestBody RequestInfoWrap RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); Map> demands = demandService.getAllDemands(demandCriteria, requestInfo); - return new ResponseEntity<>(demandCriteria, HttpStatus.OK); + return new ResponseEntity<>(demands, HttpStatus.OK); } } \ No newline at end of file From 0a10f0d7ba7db1bc8d0593cea10e592c2bb18bf7 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 22 Apr 2024 14:41:08 +0530 Subject: [PATCH 39/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../main/java/org/egov/demand/service/DemandService.java | 6 ++++-- .../org/egov/demand/web/controller/DemandController.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 2c06d3c84..1dc9abd9e 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -366,7 +366,7 @@ public void update(DemandRequest demandRequest, PaymentBackUpdateAudit paymentBa demandRepository.update(demandRequest, paymentBackUpdateAudit); } - public Map> getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { + public List>> getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { //demandValidatorV1.validateDemandCriteria(demandCriteria, requestInfo); @@ -408,6 +408,7 @@ public Map> getAllDemands(DemandCriteria demandCriteria demands = demandEnrichmentUtil.enrichPayer(demands, payers); Map> demandMap = new HashMap<>(); + List>> demandDetailsList = null; for (Demand demand : demands) { Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); @@ -415,6 +416,7 @@ public Map> getAllDemands(DemandCriteria demandCriteria demandMap.put(taxPeriodFrom, demandDetails); } log.info("Demand Details:"+demandMap); + demandDetailsList.add(demandMap); // Print the demand map for (Map.Entry> entry : demandMap.entrySet()) { log.info("Tax Period From: " + entry.getKey()); @@ -422,7 +424,7 @@ public Map> getAllDemands(DemandCriteria demandCriteria log.info("DemandDetails:"+detail); } } - return demandMap; + return demandDetailsList; } /** * Calls the demand apportion API if any advance amoount is available for that comsumer code diff --git a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java index 10e306295..cd9190043 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java @@ -170,7 +170,7 @@ public ResponseEntity getAggregatedDemandDetails(@RequestBody RequestInfoWrap RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); - Map> demands = demandService.getAllDemands(demandCriteria, requestInfo); + List>> demands = demandService.getAllDemands(demandCriteria, requestInfo); return new ResponseEntity<>(demands, HttpStatus.OK); } From c29b7159e9134c391f36ba4c882f371db9f5d4c8 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 22 Apr 2024 14:49:50 +0530 Subject: [PATCH 40/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 1dc9abd9e..a57599bfb 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -408,7 +408,7 @@ public List>> getAllDemands(DemandCriteria demandCr demands = demandEnrichmentUtil.enrichPayer(demands, payers); Map> demandMap = new HashMap<>(); - List>> demandDetailsList = null; + List>> demandDetailsList = new ArrayList<>(); for (Demand demand : demands) { Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); From 331f4fb74a683a9c0b18fbda2f0dc9feac9e111e Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 13:14:00 +0530 Subject: [PATCH 41/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index a57599bfb..1f6cd36d1 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -412,7 +412,10 @@ public List>> getAllDemands(DemandCriteria demandCr for (Demand demand : demands) { Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); - List demandDetails = demand.getDemandDetails(); + List demandDetails = demand.getDemandDetails(); + demandDetails.stream() + .filter(detail -> detail.getTaxAmount().compareTo(detail.getCollectionAmount()) > 0) // Filter condition + .collect(Collectors.toList()); demandMap.put(taxPeriodFrom, demandDetails); } log.info("Demand Details:"+demandMap); From c846728805baa1adbdacb288859090cd6f803ee3 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 13:39:48 +0530 Subject: [PATCH 42/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 1f6cd36d1..1dc975aa2 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -413,10 +413,11 @@ public List>> getAllDemands(DemandCriteria demandCr for (Demand demand : demands) { Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); List demandDetails = demand.getDemandDetails(); - demandDetails.stream() + List filteredDemandDetaillist=demandDetails.stream() .filter(detail -> detail.getTaxAmount().compareTo(detail.getCollectionAmount()) > 0) // Filter condition .collect(Collectors.toList()); - demandMap.put(taxPeriodFrom, demandDetails); + if(!demandDetails.isEmpty()) + demandMap.put(taxPeriodFrom, demandDetails); } log.info("Demand Details:"+demandMap); demandDetailsList.add(demandMap); From 09d4c569e720f218b13f00f459f795e1a2b0572d Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 13:52:27 +0530 Subject: [PATCH 43/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 1dc975aa2..3058a24d1 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -416,8 +416,8 @@ public List>> getAllDemands(DemandCriteria demandCr List filteredDemandDetaillist=demandDetails.stream() .filter(detail -> detail.getTaxAmount().compareTo(detail.getCollectionAmount()) > 0) // Filter condition .collect(Collectors.toList()); - if(!demandDetails.isEmpty()) - demandMap.put(taxPeriodFrom, demandDetails); + if(!filteredDemandDetaillist.isEmpty()) + demandMap.put(taxPeriodFrom, filteredDemandDetaillist); } log.info("Demand Details:"+demandMap); demandDetailsList.add(demandMap); From 72ec7bfe20a1b91ba7cd313284aedf60e8c65314 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 15:00:31 +0530 Subject: [PATCH 44/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 3058a24d1..01f652da5 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -414,7 +414,7 @@ public List>> getAllDemands(DemandCriteria demandCr Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); List demandDetails = demand.getDemandDetails(); List filteredDemandDetaillist=demandDetails.stream() - .filter(detail -> detail.getTaxAmount().compareTo(detail.getCollectionAmount()) > 0) // Filter condition + .filter(detail -> !detail.getTaxAmount().subtract(detail.getCollectionAmount()).equals(BigDecimal.ZERO) ) // Filter condition .collect(Collectors.toList()); if(!filteredDemandDetaillist.isEmpty()) demandMap.put(taxPeriodFrom, filteredDemandDetaillist); From 53850c387f9f4327b567461e2bc3db7e5eee9550 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 16:43:30 +0530 Subject: [PATCH 45/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 01f652da5..a3a702f03 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -414,7 +414,7 @@ public List>> getAllDemands(DemandCriteria demandCr Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); List demandDetails = demand.getDemandDetails(); List filteredDemandDetaillist=demandDetails.stream() - .filter(detail -> !detail.getTaxAmount().subtract(detail.getCollectionAmount()).equals(BigDecimal.ZERO) ) // Filter condition + .filter(detail -> !(detail.getTaxAmount().subtract(detail.getCollectionAmount())).equals(BigDecimal.ZERO) ) // Filter condition .collect(Collectors.toList()); if(!filteredDemandDetaillist.isEmpty()) demandMap.put(taxPeriodFrom, filteredDemandDetaillist); From b144989a5b465840fd775a6a5f9ad516b490443f Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 16:51:15 +0530 Subject: [PATCH 46/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index a3a702f03..adfd2a3b7 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -414,7 +414,10 @@ public List>> getAllDemands(DemandCriteria demandCr Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); List demandDetails = demand.getDemandDetails(); List filteredDemandDetaillist=demandDetails.stream() - .filter(detail -> !(detail.getTaxAmount().subtract(detail.getCollectionAmount())).equals(BigDecimal.ZERO) ) // Filter condition + .filter(detail -> { + log.info("Amount : "+detail.getTaxAmount().subtract(detail.getCollectionAmount())); + return !(detail.getTaxAmount().subtract(detail.getCollectionAmount())).equals(BigDecimal.ZERO); + }) // Filter condition .collect(Collectors.toList()); if(!filteredDemandDetaillist.isEmpty()) demandMap.put(taxPeriodFrom, filteredDemandDetaillist); From ecf2dcb902ea0faf111fc04678f68eac0791b44e Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 16:52:35 +0530 Subject: [PATCH 47/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index adfd2a3b7..af24719c1 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -416,7 +416,7 @@ public List>> getAllDemands(DemandCriteria demandCr List filteredDemandDetaillist=demandDetails.stream() .filter(detail -> { log.info("Amount : "+detail.getTaxAmount().subtract(detail.getCollectionAmount())); - return !(detail.getTaxAmount().subtract(detail.getCollectionAmount())).equals(BigDecimal.ZERO); + return !((detail.getTaxAmount().subtract(detail.getCollectionAmount())).equals(BigDecimal.ZERO)); }) // Filter condition .collect(Collectors.toList()); if(!filteredDemandDetaillist.isEmpty()) From 33f0862a251f730bbeeb66e1eb6bea266a90f262 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Wed, 24 Apr 2024 18:08:47 +0530 Subject: [PATCH 48/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../main/java/org/egov/demand/service/DemandService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index af24719c1..db2a485eb 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -415,15 +415,15 @@ public List>> getAllDemands(DemandCriteria demandCr List demandDetails = demand.getDemandDetails(); List filteredDemandDetaillist=demandDetails.stream() .filter(detail -> { - log.info("Amount : "+detail.getTaxAmount().subtract(detail.getCollectionAmount())); - return !((detail.getTaxAmount().subtract(detail.getCollectionAmount())).equals(BigDecimal.ZERO)); + BigDecimal difference = detail.getTaxAmount().subtract(detail.getCollectionAmount()); + return (difference.compareTo(BigDecimal.ZERO))!= 0; }) // Filter condition .collect(Collectors.toList()); if(!filteredDemandDetaillist.isEmpty()) demandMap.put(taxPeriodFrom, filteredDemandDetaillist); } log.info("Demand Details:"+demandMap); - demandDetailsList.add(demandMap); + demandDetailsList.add(demandMap); // Print the demand map for (Map.Entry> entry : demandMap.entrySet()) { log.info("Tax Period From: " + entry.getKey()); From 7831337a66a3dd56489d56a6c235e8d4a9030b58 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 25 Apr 2024 13:48:00 +0530 Subject: [PATCH 49/63] PFM-5638: Added Api to give all Demand details based on Dates --- .../src/main/java/org/egov/demand/service/DemandService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index db2a485eb..4bf393ffa 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -416,14 +416,15 @@ public List>> getAllDemands(DemandCriteria demandCr List filteredDemandDetaillist=demandDetails.stream() .filter(detail -> { BigDecimal difference = detail.getTaxAmount().subtract(detail.getCollectionAmount()); - return (difference.compareTo(BigDecimal.ZERO))!= 0; + return (difference.compareTo(BigDecimal.ZERO)) != 0; }) // Filter condition .collect(Collectors.toList()); + log.info("Filtered List:"+filteredDemandDetaillist); if(!filteredDemandDetaillist.isEmpty()) demandMap.put(taxPeriodFrom, filteredDemandDetaillist); } log.info("Demand Details:"+demandMap); - demandDetailsList.add(demandMap); + demandDetailsList.add(demandMap); // Print the demand map for (Map.Entry> entry : demandMap.entrySet()) { log.info("Tax Period From: " + entry.getKey()); From 0dab9142736cf404fbbda694955218d403b6e3af Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Thu, 25 Apr 2024 15:27:37 +0530 Subject: [PATCH 50/63] PFM-5638: Added the PenaltyApplicabledays from penalty master call. --- .../wscalculation/repository/DemandRepository.java | 4 ++-- .../org/egov/wscalculation/service/DemandService.java | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java index 1b51e45ff..5d0cf2b07 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java @@ -78,9 +78,9 @@ public List updateDemand(RequestInfo requestInfo, List demands){ } } - public List getDemandsToAddPenalty(String tenantId, Long penaltyThresholdTime) { + public List getDemandsToAddPenalty(String tenantId, Long penaltyThresholdTime, Integer penaltyApplicableAfterDays) { List preparedStmtList = new ArrayList<>(); - String query = queryBuilder.getPenaltyQuery(tenantId, penaltyThresholdTime, config.getPenaltyApplicableDays()); + String query = queryBuilder.getPenaltyQuery(tenantId, penaltyThresholdTime, penaltyApplicableAfterDays); log.info("query:"+ query); return jdbcTemplate.queryForList(query, String.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 655ba7742..7f8fa01d8 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 @@ -19,6 +19,7 @@ import javax.validation.Valid; +import io.swagger.models.auth.In; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpStatus; @@ -1402,13 +1403,13 @@ public boolean isOnlinePaymentAllowed(RequestInfo requestInfo, String tenantId) else return true; } - public List getDemandToAddPenalty(String tenantid,Long penaltyThresholdDate){ - return demandRepository.getDemandsToAddPenalty(tenantid,penaltyThresholdDate); + public List getDemandToAddPenalty(String tenantid,Long penaltyThresholdDate,Integer penaltyApplicableAfterDays){ + return demandRepository.getDemandsToAddPenalty(tenantid,penaltyThresholdDate,penaltyApplicableAfterDays); } public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { if(config.isPenaltyEnabled()) { - List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(), config.getPenaltyStartThresholdTime()); + List masterDetails = new ArrayList<>(); MasterDetail masterDetail = new MasterDetail("Penalty", "[?(@)]"); masterDetails.add(masterDetail); @@ -1423,6 +1424,9 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add Integer rate= (Integer) paymentMasterData.get("rate"); String penaltyType = String.valueOf(paymentMasterData.get("type")); String penaltySubType = (String) paymentMasterData.get("subType"); + String startingDay = (String) paymentMasterData.get("startingDay"); + Integer applicableAfterDays = (Integer) paymentMasterData.get("applicableAfterDays"); + List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(), config.getPenaltyStartThresholdTime(),applicableAfterDays); if (rate > 0) { demandIds.stream().forEach(demandId -> { Set demandids = new HashSet<>(); From 23b60ee704753d6417a73217a900d00dc88ae486 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 29 Apr 2024 15:38:39 +0530 Subject: [PATCH 51/63] PFM-5638: Added the vvalues for all the WS_charge Penalty advance inn Onne API --- .../model/AggregatedDemandDetailResponse.java | 39 ++++++ .../egov/demand/service/DemandService.java | 118 ++++++++++++++++-- .../web/controller/DemandController.java | 7 +- 3 files changed, 147 insertions(+), 17 deletions(-) create mode 100644 business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java diff --git a/business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java b/business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java new file mode 100644 index 000000000..52691c9fc --- /dev/null +++ b/business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java @@ -0,0 +1,39 @@ +package org.egov.demand.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import javax.validation.constraints.NotNull; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AggregatedDemandDetailResponse { + + private List>> mapOfDemandDetailList; + + private BigDecimal advanceAvailable; + + private BigDecimal advanceAdjusted; + + private BigDecimal remainingAdvance; + + private BigDecimal currentmonthBill; + + private BigDecimal currentMonthPenalty; + + private BigDecimal currentmonthTotalDue; + + private BigDecimal totalAreas; + + private BigDecimal totalAreasWithPenalty; + + private BigDecimal netdue; + + private BigDecimal netDueWithPenalty; +} diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 4bf393ffa..83eff7434 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -53,16 +53,8 @@ import org.egov.demand.amendment.model.AmendmentUpdate; import org.egov.demand.amendment.model.enums.AmendmentStatus; import org.egov.demand.config.ApplicationProperties; -import org.egov.demand.model.ApportionDemandResponse; -import org.egov.demand.model.AuditDetails; +import org.egov.demand.model.*; import org.egov.demand.model.BillV2.BillStatus; -import org.egov.demand.model.Demand; -import org.egov.demand.model.DemandApportionRequest; -import org.egov.demand.model.DemandCriteria; -import org.egov.demand.model.DemandDetail; -import org.egov.demand.model.DemandHistory; -import org.egov.demand.model.PaymentBackUpdateAudit; -import org.egov.demand.model.UpdateBillCriteria; import org.egov.demand.repository.AmendmentRepository; import org.egov.demand.repository.BillRepositoryV2; import org.egov.demand.repository.DemandRepository; @@ -366,7 +358,7 @@ public void update(DemandRequest demandRequest, PaymentBackUpdateAudit paymentBa demandRepository.update(demandRequest, paymentBackUpdateAudit); } - public List>> getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { + public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteria, RequestInfo requestInfo) { //demandValidatorV1.validateDemandCriteria(demandCriteria, requestInfo); @@ -425,14 +417,116 @@ public List>> getAllDemands(DemandCriteria demandCr } log.info("Demand Details:"+demandMap); demandDetailsList.add(demandMap); - // Print the demand map + // Sorting the list of maps based on the key in descending order + List>> sortedDemandDetailsList = demandDetailsList.stream() + .sorted((mapA, mapB) -> { + Long keyA = mapA.keySet().stream().findFirst().orElse(0L); + Long keyB = mapB.keySet().stream().findFirst().orElse(0L); + return keyB.compareTo(keyA); // Descending order + }) + .collect(Collectors.toList()); + + List currentMonthDemandDetailList = new ArrayList<>(); + if (!sortedDemandDetailsList.isEmpty()) { + Map> firstMap = sortedDemandDetailsList.get(0); + firstMap.forEach((key, value) -> { + currentMonthDemandDetailList.addAll(value); // Get all details from the first map + }); + } + // Extract RemainingMonthDemandDetailList + List remainingMonthDemandDetailList = new ArrayList<>(); + if (sortedDemandDetailsList.size() > 1) { + for (int i = 1; i < sortedDemandDetailsList.size(); i++) { + Map> map = sortedDemandDetailsList.get(i); + map.forEach((key, value) -> { + remainingMonthDemandDetailList.addAll(value); // Collect all details from the other maps + }); + } + } + log.info("currentMonthDemandDetailList"+currentMonthDemandDetailList); + log.info("remainingMonthDemandDetailList"+remainingMonthDemandDetailList); + BigDecimal currentmonthBill = BigDecimal.ZERO; + BigDecimal currentMonthPenalty = BigDecimal.ZERO; + BigDecimal currentmonthTotalDue = BigDecimal.ZERO; + BigDecimal advanceAvailable = BigDecimal.ZERO; + BigDecimal advanceAdjusted = BigDecimal.ZERO; + BigDecimal remainingAdvance = BigDecimal.ZERO; + BigDecimal totalAreas = BigDecimal.ZERO; + BigDecimal totalAreasWithPenalty = BigDecimal.ZERO; + BigDecimal netdue = BigDecimal.ZERO; + BigDecimal netDueWithPenalty = BigDecimal.ZERO; + + currentmonthBill = currentMonthDemandDetailList.stream() + .filter(dd -> dd.getTaxHeadMasterCode().equals("10101")) // filter by taxHeadCode + .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount())) // map to the balance between taxAmount and collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); + currentMonthPenalty = currentMonthDemandDetailList.stream() + .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_TIME_PENALTY")) // filter by taxHeadCode + .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount())) // map to the balance between taxAmount and collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); + currentmonthTotalDue = currentmonthBill.add(currentMonthPenalty); + + //Tax headcode for WScharges,legacypenalty,legacyarea + List taxHeadCodesToFilterWithoutPenalty = Arrays.asList("10101", "10201", "10101"); + + // Initialize the variable for the sum of taxAmount - collectedAmount for the filtered tax head codes + totalAreas = remainingMonthDemandDetailList.stream() + .filter(dd -> taxHeadCodesToFilterWithoutPenalty.contains(dd.getTaxHeadMasterCode())) // Filter by tax head codes + .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount())) // Calculate taxAmount - collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); // Sum all results + + BigDecimal penaltyInRemainingMonth= remainingMonthDemandDetailList.stream() + .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_TIME_PENALTY")) // filter by taxHeadCode + .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount())) // map to the balance between taxAmount and collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); + + totalAreasWithPenalty = totalAreas.add(penaltyInRemainingMonth); + + netdue=currentmonthBill.add(totalAreas); + netDueWithPenalty =currentmonthTotalDue.add(totalAreasWithPenalty); + + BigDecimal currentMonthAdvanceAvailable=currentMonthPenalty = currentMonthDemandDetailList.stream() + .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode + .map(dd -> dd.getTaxAmount()) // map to the balance between taxAmount and collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal currentMonthAdvanceCollected=currentMonthPenalty = currentMonthDemandDetailList.stream() + .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode + .map(dd -> dd.getCollectionAmount()) // map to the balance between taxAmount and collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal remainingMonthAdvanceAvailable=currentMonthPenalty = remainingMonthDemandDetailList.stream() + .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode + .map(dd -> dd.getTaxAmount()) // map to the balance between taxAmount and collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal remainingMonthAdvanceCollected=currentMonthPenalty = remainingMonthDemandDetailList.stream() + .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode + .map(dd -> dd.getCollectionAmount()) // map to the balance between taxAmount and collectedAmount + .reduce(BigDecimal.ZERO, BigDecimal::add); + advanceAvailable = currentMonthAdvanceAvailable.add(remainingMonthAdvanceAvailable); + advanceAdjusted = currentMonthAdvanceCollected.add(remainingMonthAdvanceCollected); + remainingAdvance=advanceAdjusted.subtract(advanceAdjusted); + for (Map.Entry> entry : demandMap.entrySet()) { log.info("Tax Period From: " + entry.getKey()); for (DemandDetail detail : entry.getValue()) { log.info("DemandDetails:"+detail); } } - return demandDetailsList; + //BigDecimal currentMonthBill + AggregatedDemandDetailResponse aggregatedDemandDetailResponse = AggregatedDemandDetailResponse.builder() + .mapOfDemandDetailList(sortedDemandDetailsList) + .currentmonthBill(currentmonthBill) + .currentMonthPenalty(currentMonthPenalty) + .currentmonthTotalDue(currentmonthTotalDue) + .totalAreas(totalAreas) + .totalAreasWithPenalty(totalAreasWithPenalty) + .netdue(netdue) + .netDueWithPenalty(netDueWithPenalty) + .advanceAdjusted(advanceAdjusted) + .advanceAvailable(advanceAvailable) + .remainingAdvance(remainingAdvance).build(); + + + return aggregatedDemandDetailResponse; } /** * Calls the demand apportion API if any advance amoount is available for that comsumer code diff --git a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java index cd9190043..c4b1e28d6 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/web/controller/DemandController.java @@ -46,10 +46,7 @@ import org.egov.common.contract.request.RequestInfo; import org.egov.demand.config.ApplicationProperties; -import org.egov.demand.model.Demand; -import org.egov.demand.model.DemandCriteria; -import org.egov.demand.model.DemandDetail; -import org.egov.demand.model.DemandHistory; +import org.egov.demand.model.*; import org.egov.demand.producer.Producer; import org.egov.demand.service.DemandService; import org.egov.demand.util.migration.DemandMigration; @@ -170,7 +167,7 @@ public ResponseEntity getAggregatedDemandDetails(@RequestBody RequestInfoWrap RequestInfo requestInfo = requestInfoWrapper.getRequestInfo(); - List>> demands = demandService.getAllDemands(demandCriteria, requestInfo); + AggregatedDemandDetailResponse demands = demandService.getAllDemands(demandCriteria, requestInfo); return new ResponseEntity<>(demands, HttpStatus.OK); } From 1af1ef5ef94d7b884d76f98532c3cb8b6ba044c1 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 29 Apr 2024 17:09:11 +0530 Subject: [PATCH 52/63] PFM-5638: Added the vvalues for all the WS_charge Penalty advance inn Onne API --- .../java/org/egov/demand/service/DemandService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 83eff7434..27d2b86e7 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -422,10 +422,12 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri .sorted((mapA, mapB) -> { Long keyA = mapA.keySet().stream().findFirst().orElse(0L); Long keyB = mapB.keySet().stream().findFirst().orElse(0L); - return keyB.compareTo(keyA); // Descending order + return -keyB.compareTo(keyA); // Descending order }) .collect(Collectors.toList()); + log.info("Sorted map:"+sortedDemandDetailsList); + List currentMonthDemandDetailList = new ArrayList<>(); if (!sortedDemandDetailsList.isEmpty()) { Map> firstMap = sortedDemandDetailsList.get(0); @@ -485,19 +487,19 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri netdue=currentmonthBill.add(totalAreas); netDueWithPenalty =currentmonthTotalDue.add(totalAreasWithPenalty); - BigDecimal currentMonthAdvanceAvailable=currentMonthPenalty = currentMonthDemandDetailList.stream() + BigDecimal currentMonthAdvanceAvailable=currentMonthDemandDetailList.stream() .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode .map(dd -> dd.getTaxAmount()) // map to the balance between taxAmount and collectedAmount .reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal currentMonthAdvanceCollected=currentMonthPenalty = currentMonthDemandDetailList.stream() + BigDecimal currentMonthAdvanceCollected= currentMonthDemandDetailList.stream() .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode .map(dd -> dd.getCollectionAmount()) // map to the balance between taxAmount and collectedAmount .reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal remainingMonthAdvanceAvailable=currentMonthPenalty = remainingMonthDemandDetailList.stream() + BigDecimal remainingMonthAdvanceAvailable = remainingMonthDemandDetailList.stream() .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode .map(dd -> dd.getTaxAmount()) // map to the balance between taxAmount and collectedAmount .reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal remainingMonthAdvanceCollected=currentMonthPenalty = remainingMonthDemandDetailList.stream() + BigDecimal remainingMonthAdvanceCollected= remainingMonthDemandDetailList.stream() .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode .map(dd -> dd.getCollectionAmount()) // map to the balance between taxAmount and collectedAmount .reduce(BigDecimal.ZERO, BigDecimal::add); From 380838bfed1597f2907fecbc5e3fc125621444b2 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 29 Apr 2024 17:11:37 +0530 Subject: [PATCH 53/63] PFM-5638: Added the vvalues for all the WS_charge Penalty advance inn Onne API --- .../main/java/org/egov/demand/service/DemandService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 27d2b86e7..36365cffa 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -466,6 +466,7 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_TIME_PENALTY")) // filter by taxHeadCode .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount())) // map to the balance between taxAmount and collectedAmount .reduce(BigDecimal.ZERO, BigDecimal::add); + log.info("currentMonthPenalty" + currentMonthPenalty); currentmonthTotalDue = currentmonthBill.add(currentMonthPenalty); //Tax headcode for WScharges,legacypenalty,legacyarea @@ -484,8 +485,8 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri totalAreasWithPenalty = totalAreas.add(penaltyInRemainingMonth); - netdue=currentmonthBill.add(totalAreas); - netDueWithPenalty =currentmonthTotalDue.add(totalAreasWithPenalty); + netdue = currentmonthBill.add(totalAreas); + netDueWithPenalty = currentmonthTotalDue.add(totalAreasWithPenalty); BigDecimal currentMonthAdvanceAvailable=currentMonthDemandDetailList.stream() .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_ADVANCE_CARRYFORWARD")) // filter by taxHeadCode @@ -505,7 +506,7 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri .reduce(BigDecimal.ZERO, BigDecimal::add); advanceAvailable = currentMonthAdvanceAvailable.add(remainingMonthAdvanceAvailable); advanceAdjusted = currentMonthAdvanceCollected.add(remainingMonthAdvanceCollected); - remainingAdvance=advanceAdjusted.subtract(advanceAdjusted); + remainingAdvance = advanceAdjusted.subtract(advanceAdjusted); for (Map.Entry> entry : demandMap.entrySet()) { log.info("Tax Period From: " + entry.getKey()); From 2cfb607842bb62f6896d03776097ad243651d1d2 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 29 Apr 2024 17:12:32 +0530 Subject: [PATCH 54/63] PFM-5638: Added the vvalues for all the WS_charge Penalty advance inn Onne API --- .../src/main/java/org/egov/demand/service/DemandService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 36365cffa..5d54590f7 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -462,10 +462,12 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri .filter(dd -> dd.getTaxHeadMasterCode().equals("10101")) // filter by taxHeadCode .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount())) // map to the balance between taxAmount and collectedAmount .reduce(BigDecimal.ZERO, BigDecimal::add); + log.info("currentMonthDemandDetailList::::"+currentMonthDemandDetailList); currentMonthPenalty = currentMonthDemandDetailList.stream() .filter(dd -> dd.getTaxHeadMasterCode().equals("WS_TIME_PENALTY")) // filter by taxHeadCode .map(dd -> dd.getTaxAmount().subtract(dd.getCollectionAmount())) // map to the balance between taxAmount and collectedAmount .reduce(BigDecimal.ZERO, BigDecimal::add); + log.info("currentMonthDemandDetailListafter::::"+currentMonthDemandDetailList); log.info("currentMonthPenalty" + currentMonthPenalty); currentmonthTotalDue = currentmonthBill.add(currentMonthPenalty); From 7aba6b3c711ca635eed2b21f426c1f62fcc5c015 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 29 Apr 2024 17:40:48 +0530 Subject: [PATCH 55/63] PFM-5638: Added the vvalues for all the WS_charge Penalty advance inn Onne API --- .../egov/demand/service/DemandService.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 5d54590f7..61644ad4e 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -399,30 +399,32 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri if (!CollectionUtils.isEmpty(demands) && !CollectionUtils.isEmpty(payers)) demands = demandEnrichmentUtil.enrichPayer(demands, payers); - Map> demandMap = new HashMap<>(); + List>> demandDetailsList = new ArrayList<>(); for (Demand demand : demands) { + Map> demandMap = new HashMap<>(); Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); List demandDetails = demand.getDemandDetails(); - List filteredDemandDetaillist=demandDetails.stream() + List filteredDemandDetaillist = demandDetails.stream() .filter(detail -> { BigDecimal difference = detail.getTaxAmount().subtract(detail.getCollectionAmount()); return (difference.compareTo(BigDecimal.ZERO)) != 0; }) // Filter condition .collect(Collectors.toList()); log.info("Filtered List:"+filteredDemandDetaillist); - if(!filteredDemandDetaillist.isEmpty()) + if(!filteredDemandDetaillist.isEmpty()) { demandMap.put(taxPeriodFrom, filteredDemandDetaillist); + demandDetailsList.add(demandMap); + } } - log.info("Demand Details:"+demandMap); - demandDetailsList.add(demandMap); + log.info("demandDetailsList:"+demandDetailsList); // Sorting the list of maps based on the key in descending order List>> sortedDemandDetailsList = demandDetailsList.stream() .sorted((mapA, mapB) -> { Long keyA = mapA.keySet().stream().findFirst().orElse(0L); Long keyB = mapB.keySet().stream().findFirst().orElse(0L); - return -keyB.compareTo(keyA); // Descending order + return keyB.compareTo(keyA); // Descending order }) .collect(Collectors.toList()); @@ -510,12 +512,6 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri advanceAdjusted = currentMonthAdvanceCollected.add(remainingMonthAdvanceCollected); remainingAdvance = advanceAdjusted.subtract(advanceAdjusted); - for (Map.Entry> entry : demandMap.entrySet()) { - log.info("Tax Period From: " + entry.getKey()); - for (DemandDetail detail : entry.getValue()) { - log.info("DemandDetails:"+detail); - } - } //BigDecimal currentMonthBill AggregatedDemandDetailResponse aggregatedDemandDetailResponse = AggregatedDemandDetailResponse.builder() .mapOfDemandDetailList(sortedDemandDetailsList) From 99c64349ee86f3ef62275724309f708a1252931e Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 29 Apr 2024 17:55:07 +0530 Subject: [PATCH 56/63] PFM-5638: Added the vvalues for all the WS_charge Penalty advance inn Onne API --- .../src/main/java/org/egov/demand/service/DemandService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 61644ad4e..9c9c6d340 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -510,7 +510,7 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri .reduce(BigDecimal.ZERO, BigDecimal::add); advanceAvailable = currentMonthAdvanceAvailable.add(remainingMonthAdvanceAvailable); advanceAdjusted = currentMonthAdvanceCollected.add(remainingMonthAdvanceCollected); - remainingAdvance = advanceAdjusted.subtract(advanceAdjusted); + remainingAdvance = advanceAvailable.subtract(advanceAdjusted); //BigDecimal currentMonthBill AggregatedDemandDetailResponse aggregatedDemandDetailResponse = AggregatedDemandDetailResponse.builder() From f4b349cfba78ee6cf3cf690b2731e1daec97743c Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 30 Apr 2024 10:15:05 +0530 Subject: [PATCH 57/63] PFM-5638: Added the vvalues for all the WS_charge Penalty advance inn Onne API --- .../src/main/java/org/egov/demand/service/DemandService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 9c9c6d340..be8de09e9 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -474,7 +474,7 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri currentmonthTotalDue = currentmonthBill.add(currentMonthPenalty); //Tax headcode for WScharges,legacypenalty,legacyarea - List taxHeadCodesToFilterWithoutPenalty = Arrays.asList("10101", "10201", "10101"); + List taxHeadCodesToFilterWithoutPenalty = Arrays.asList("10102", "10201", "10101"); // Initialize the variable for the sum of taxAmount - collectedAmount for the filtered tax head codes totalAreas = remainingMonthDemandDetailList.stream() From b472b96bb11b10f0fca85b3d8d557b9b3ad0c923 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 20 May 2024 14:03:09 +0530 Subject: [PATCH 58/63] PFM-5638: Added the Applicable penalty values for all the WS_charge Penalty advance inn Onne API --- .../model/AggregatedDemandDetailResponse.java | 2 ++ .../egov/demand/service/DemandService.java | 32 +++++++++++++++++-- .../java/org/egov/demand/util/Constants.java | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java b/business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java index 52691c9fc..7e3d0ebb2 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/model/AggregatedDemandDetailResponse.java @@ -36,4 +36,6 @@ public class AggregatedDemandDetailResponse { private BigDecimal netdue; private BigDecimal netDueWithPenalty; + + private BigDecimal totalApplicablePenalty; } diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index be8de09e9..f6b6ac052 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -39,9 +39,8 @@ */ package org.egov.demand.service; -import static org.egov.demand.util.Constants.ADVANCE_TAXHEAD_JSONPATH_CODE; - import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -68,6 +67,10 @@ import org.egov.demand.web.contract.UserSearchRequest; import org.egov.demand.web.contract.factory.ResponseFactory; import org.egov.demand.web.validator.DemandValidatorV1; +import org.egov.mdms.model.MasterDetail; +import org.egov.mdms.model.MdmsCriteria; +import org.egov.mdms.model.MdmsCriteriaReq; +import org.egov.mdms.model.ModuleDetail; import org.egov.tracer.model.CustomException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -81,6 +84,8 @@ import lombok.extern.slf4j.Slf4j; +import static org.egov.demand.util.Constants.*; + @Service @Slf4j public class DemandService { @@ -459,6 +464,7 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri BigDecimal totalAreasWithPenalty = BigDecimal.ZERO; BigDecimal netdue = BigDecimal.ZERO; BigDecimal netDueWithPenalty = BigDecimal.ZERO; + BigDecimal totalApplicablePenalty =BigDecimal.ZERO; currentmonthBill = currentMonthDemandDetailList.stream() .filter(dd -> dd.getTaxHeadMasterCode().equals("10101")) // filter by taxHeadCode @@ -472,6 +478,25 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri log.info("currentMonthDemandDetailListafter::::"+currentMonthDemandDetailList); log.info("currentMonthPenalty" + currentMonthPenalty); currentmonthTotalDue = currentmonthBill.add(currentMonthPenalty); + if(currentMonthPenalty.equals(BigDecimal.ZERO)) { + List masterDetails = new ArrayList<>(); + MasterDetail masterDetail = new MasterDetail("Penalty", "[?(@)]"); + masterDetails.add(masterDetail); + ModuleDetail moduleDetail = ModuleDetail.builder().moduleName("ws-services-calculation").masterDetails(masterDetails).build(); + List moduleDetails = new ArrayList<>(); + moduleDetails.add(moduleDetail); + MdmsCriteria mdmsCriteria = MdmsCriteria.builder().tenantId(demandCriteria.getTenantId()) + .moduleDetails(moduleDetails) + .build(); + MdmsCriteriaReq mdmsreq = MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build(); + DocumentContext mdmsData = util.getAttributeValues(mdmsreq); + Map paymentMasterData = mdmsData.read(PENALTY_PATH_CODE); + Integer rate= (Integer) paymentMasterData.get("rate"); + String penaltyType = String.valueOf(paymentMasterData.get("type")); + totalApplicablePenalty = currentmonthBill.multiply(new BigDecimal(rate).divide(new BigDecimal(100))); + totalApplicablePenalty= totalApplicablePenalty.setScale(0, RoundingMode.CEILING); + } + //Tax headcode for WScharges,legacypenalty,legacyarea List taxHeadCodesToFilterWithoutPenalty = Arrays.asList("10102", "10201", "10101"); @@ -524,7 +549,8 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri .netDueWithPenalty(netDueWithPenalty) .advanceAdjusted(advanceAdjusted) .advanceAvailable(advanceAvailable) - .remainingAdvance(remainingAdvance).build(); + .remainingAdvance(remainingAdvance) + .totalApplicablePenalty(totalApplicablePenalty).build(); return aggregatedDemandDetailResponse; diff --git a/business-services/billing-service/src/main/java/org/egov/demand/util/Constants.java b/business-services/billing-service/src/main/java/org/egov/demand/util/Constants.java index 7ddff20a9..61af1d62f 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/util/Constants.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/util/Constants.java @@ -20,6 +20,7 @@ public class Constants { public static final String TAXPERIOD_PATH_CODE = "$.MdmsRes.BillingService.TaxPeriod"; public static final String TAXHEADMASTER_PATH_CODE = "$.MdmsRes.BillingService.TaxHeadMaster"; public static final String BUSINESSSERVICE_PATH_CODE = "$.MdmsRes.BillingService.BusinessService.*.code"; + public static final String PENALTY_PATH_CODE = "$.MdmsRes.ws-services-calculation.Penalty"; public static final String BUSINESSSERVICE_MODULE_PATH = "$.MdmsRes.BillingService.BusinessService"; From 90e2bf906712b03bfc8515ff07b6e258506aca56 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Mon, 20 May 2024 14:41:19 +0530 Subject: [PATCH 59/63] PFM-5638: Added the Applicable penalty values for all the WS_charge Penalty advance inn Onne API --- .../org/egov/demand/service/DemandService.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index f6b6ac052..28020b784 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -490,11 +490,16 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri .build(); MdmsCriteriaReq mdmsreq = MdmsCriteriaReq.builder().mdmsCriteria(mdmsCriteria).requestInfo(requestInfo).build(); DocumentContext mdmsData = util.getAttributeValues(mdmsreq); - Map paymentMasterData = mdmsData.read(PENALTY_PATH_CODE); - Integer rate= (Integer) paymentMasterData.get("rate"); - String penaltyType = String.valueOf(paymentMasterData.get("type")); - totalApplicablePenalty = currentmonthBill.multiply(new BigDecimal(rate).divide(new BigDecimal(100))); - totalApplicablePenalty= totalApplicablePenalty.setScale(0, RoundingMode.CEILING); + if (!mdmsData.equals(null)) { + List> paymentMasterDataList = mdmsData.read(PENALTY_PATH_CODE); + Map paymentMasterData = paymentMasterDataList.get(0); + Integer rate = (Integer) paymentMasterData.get("rate"); + String penaltyType = String.valueOf(paymentMasterData.get("type")); + totalApplicablePenalty = currentmonthBill.multiply(new BigDecimal(rate).divide(new BigDecimal(100))); + totalApplicablePenalty = totalApplicablePenalty.setScale(0, RoundingMode.CEILING); + } else { + log.info("MDMS data is Null Penalty not connfigured"); + } } From ec75eb48761f388fac52588fd4e01a2ed345044b Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Tue, 21 May 2024 16:00:14 +0530 Subject: [PATCH 60/63] PFM-5638: Added the PenaltyApplicabledays from penalty master call. --- .../main/java/org/egov/demand/service/DemandService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java index 28020b784..79d43b2eb 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/service/DemandService.java @@ -386,7 +386,9 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri /* * If no payer related data given then search demand first then enrich payer(user) data */ + log.info("demandCriteria::"+demandCriteria); demands = demandRepository.getDemands(demandCriteria); + log.info("demands:"+demands); if (!demands.isEmpty()) { Set payerUuids = demands.stream().filter(demand -> null != demand.getPayer()) @@ -400,14 +402,16 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri UserResponse.class).getUser(); } } + log.info("demannds::"+demands); if (!CollectionUtils.isEmpty(demands) && !CollectionUtils.isEmpty(payers)) demands = demandEnrichmentUtil.enrichPayer(demands, payers); - + log.info("demannddddds::"+demands); List>> demandDetailsList = new ArrayList<>(); for (Demand demand : demands) { + log.info("Inside demand"); Map> demandMap = new HashMap<>(); Long taxPeriodFrom = (Long) demand.getTaxPeriodFrom(); List demandDetails = demand.getDemandDetails(); From 4a7d82904a79532d3e39de88e193b091f739a8be Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Fri, 24 May 2024 16:01:26 +0530 Subject: [PATCH 61/63] ISTE-44: Added demand change audit db script from ws-calculator service --- .../egov/wscalculation/config/WSCalculationConfiguration.java | 3 ++- .../org/egov/wscalculation/repository/DemandRepository.java | 3 ++- .../wscalculation/repository/builder/DemandQueryBuilder.java | 3 ++- .../java/org/egov/wscalculation/service/DemandService.java | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) 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 c5b9da834..7764b9808 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 @@ -1,6 +1,7 @@ package org.egov.wscalculation.config; import java.math.BigDecimal; +import java.math.BigInteger; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -254,7 +255,7 @@ public class WSCalculationConfiguration { private Integer penaltyApplicableDays; @Value("${penalty.start.threshold.time}") - private Long penaltyStartThresholdTime; + private BigInteger penaltyStartThresholdTime; @Value("${is.penalty.feature.enable}") private boolean isPenaltyEnabled; diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java index 5d0cf2b07..e7e0dbb15 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/DemandRepository.java @@ -1,5 +1,6 @@ package org.egov.wscalculation.repository; +import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -78,7 +79,7 @@ public List updateDemand(RequestInfo requestInfo, List demands){ } } - public List getDemandsToAddPenalty(String tenantId, Long penaltyThresholdTime, Integer penaltyApplicableAfterDays) { + public List getDemandsToAddPenalty(String tenantId, BigInteger penaltyThresholdTime, Integer penaltyApplicableAfterDays) { List preparedStmtList = new ArrayList<>(); String query = queryBuilder.getPenaltyQuery(tenantId, penaltyThresholdTime, penaltyApplicableAfterDays); log.info("query:"+ query); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java index 75d322fec..d29e92174 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/builder/DemandQueryBuilder.java @@ -7,6 +7,7 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; +import java.math.BigInteger; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.List; @@ -24,7 +25,7 @@ public class DemandQueryBuilder { private final static String groupByClause = " GROUP BY b.demandid " + "HAVING COUNT(*) = 1 "; - public String getPenaltyQuery(String tenantId, Long penaltyThresholdDate, Integer daysToBeSubstracted ) { + public String getPenaltyQuery(String tenantId, BigInteger penaltyThresholdDate, Integer daysToBeSubstracted ) { //TODO: find out days long currentTimeMillis = System.currentTimeMillis(); long tenDaysAgoMillis = Instant.ofEpochMilli(currentTimeMillis) 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 7f8fa01d8..95baccbab 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 @@ -1403,13 +1403,15 @@ public boolean isOnlinePaymentAllowed(RequestInfo requestInfo, String tenantId) else return true; } - public List getDemandToAddPenalty(String tenantid,Long penaltyThresholdDate,Integer penaltyApplicableAfterDays){ + public List getDemandToAddPenalty(String tenantid,BigInteger penaltyThresholdDate,Integer penaltyApplicableAfterDays){ return demandRepository.getDemandsToAddPenalty(tenantid,penaltyThresholdDate,penaltyApplicableAfterDays); } public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, AddPenaltyCriteria addPenaltyCriteria) { if(config.isPenaltyEnabled()) { + if (requestInfo.getUserInfo().equals(null)) { + } List masterDetails = new ArrayList<>(); MasterDetail masterDetail = new MasterDetail("Penalty", "[?(@)]"); masterDetails.add(masterDetail); From cf43add706ca01eff9046a9feb64f3a2a114a9c8 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Fri, 24 May 2024 16:39:15 +0530 Subject: [PATCH 62/63] ISTE-44: Added demand change audit db script from ws-calculator service --- ...2405230601__wc_create_demand_audit_ddl.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 municipal-services/ws-calculator/src/main/resources/db/migration/ddl/V202405230601__wc_create_demand_audit_ddl.sql 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 From fa449c47380ae66621400fd23e5bea9251ddf309 Mon Sep 17 00:00:00 2001 From: debasishchakraborty-egovt Date: Fri, 24 May 2024 17:16:52 +0530 Subject: [PATCH 63/63] ISTE-44: Added demand change audit db script from ws-calculator service --- .../config/WSCalculationConfiguration.java | 2 +- .../wscalculation/service/DemandService.java | 2 +- ...2405230601__wc_create_demand_audit_ddl.sql | 18 ------------------ 3 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 municipal-services/ws-calculator/src/main/resources/db/migration/ddl/V202405230601__wc_create_demand_audit_ddl.sql 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 7764b9808..43bd663ba 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 @@ -255,7 +255,7 @@ public class WSCalculationConfiguration { private Integer penaltyApplicableDays; @Value("${penalty.start.threshold.time}") - private BigInteger penaltyStartThresholdTime; + private String penaltyStartThresholdTime; @Value("${is.penalty.feature.enable}") private boolean isPenaltyEnabled; 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 95baccbab..a7efaad06 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 @@ -1428,7 +1428,7 @@ public ResponseEntity addPenalty(@Valid RequestInfo requestInfo, Add String penaltySubType = (String) paymentMasterData.get("subType"); String startingDay = (String) paymentMasterData.get("startingDay"); Integer applicableAfterDays = (Integer) paymentMasterData.get("applicableAfterDays"); - List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(), config.getPenaltyStartThresholdTime(),applicableAfterDays); + List demandIds = getDemandToAddPenalty(addPenaltyCriteria.getTenantId(), new BigInteger(config.getPenaltyStartThresholdTime()),applicableAfterDays); if (rate > 0) { demandIds.stream().forEach(demandId -> { Set demandids = new HashSet<>(); 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 deleted file mode 100644 index 813ea1dbc..000000000 --- a/municipal-services/ws-calculator/src/main/resources/db/migration/ddl/V202405230601__wc_create_demand_audit_ddl.sql +++ /dev/null @@ -1,18 +0,0 @@ -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