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 1caa7154e..2217e87bc 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 @@ -281,9 +281,9 @@ private void generateDemandAndSendnotification(RequestInfo requestInfo, String t .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); - List connectionNos = waterCalculatorDao.getNonMeterConnectionsList(tenantId, dayStartTime, dayEndTime); + Map connectionNos = waterCalculatorDao.getNonMeterConnectionsList(tenantId, dayStartTime, dayEndTime); - List meteredConnectionNos = waterCalculatorDao.getConnectionsNoList(tenantId, + Map meteredConnectionNos = waterCalculatorDao.getConnectionsNoList(tenantId, WSCalculationConstant.meteredConnectionType); @@ -300,13 +300,28 @@ private void generateDemandAndSendnotification(RequestInfo requestInfo, String t String assessmentYear = estimationService.getAssessmentYear(); ArrayList failedConnectionNos = new ArrayList(); - for (String connectionNo : connectionNos) { + for (Map.Entry entry : connectionNos.entrySet()) { + String connectionNo = entry.getKey(); CalculationCriteria calculationCriteria = CalculationCriteria.builder().tenantId(tenantId) .assessmentYear(assessmentYear).connectionNo(connectionNo).from(dayStartTime).to(dayEndTime).build(); List calculationCriteriaList = new ArrayList<>(); calculationCriteriaList.add(calculationCriteria); - CalculationReq calculationReq = CalculationReq.builder().calculationCriteria(calculationCriteriaList) - .requestInfo(requestInfo).isconnectionCalculation(true).build(); + + CalculationReq calculationReq = null; + if(entry.getValue().equalsIgnoreCase("advance")) { + calculationReq = CalculationReq.builder().calculationCriteria(calculationCriteriaList) + .requestInfo(requestInfo).isconnectionCalculation(true).isAdvanceCalculation(false). + isAdvanceDemand(true).build(); + + + } + else { + calculationReq = CalculationReq.builder().calculationCriteria(calculationCriteriaList) + .requestInfo(requestInfo).isconnectionCalculation(true).isAdvanceCalculation(false). + isAdvanceDemand(false).build(); + } + + Map masterMap = mDataService.loadMasterData(calculationReq.getRequestInfo(), calculationReq.getCalculationCriteria().get(0).getTenantId()); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDao.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDao.java index 6eac8bc87..a85dba038 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDao.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDao.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Set; import org.egov.wscalculation.web.models.MeterConnectionRequest; @@ -22,14 +23,14 @@ public interface WSCalculationDao { int isMeterReadingConnectionExist(List ids); - List getConnectionsNoList(String tenantId, String connectionType); + Map getConnectionsNoList(String tenantId, String connectionType); List getTenantId(); int isBillingPeriodExists(String connectionNo, String billingPeriod); Boolean isDemandExists(String tenantId, Long bilingDate,Long endTime, Set connectionNos); - List getNonMeterConnectionsList(String tenantId, Long dayStartTime, Long dayEndTime); + Map getNonMeterConnectionsList(String tenantId, Long dayStartTime, Long dayEndTime); Boolean isConnectionExists(String tenantId, Long startTime, Long endTime, Set connectionNos); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDaoImpl.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDaoImpl.java index 892ef1305..2c41165b5 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDaoImpl.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/WSCalculationDaoImpl.java @@ -4,10 +4,12 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.egov.wscalculation.producer.WSCalculationProducer; import org.egov.wscalculation.repository.builder.WSCalculatorQueryBuilder; +import org.egov.wscalculation.repository.rowmapper.DemandListSchedulerRowMapper; import org.egov.wscalculation.repository.rowmapper.DemandSchedulerRowMapper; import org.egov.wscalculation.repository.rowmapper.MeterReadingCurrentReadingRowMapper; import org.egov.wscalculation.repository.rowmapper.MeterReadingRowMapper; @@ -42,6 +44,9 @@ public class WSCalculationDaoImpl implements WSCalculationDao { @Autowired private DemandSchedulerRowMapper demandSchedulerRowMapper; + + @Autowired + private DemandListSchedulerRowMapper demandListSchedulerRowMapper; @Value("${egov.meterservice.createmeterconnection}") private String createMeterConnection; @@ -125,19 +130,19 @@ public ArrayList searchConnectionNos(String connectionType, String tenan } @Override - public List getConnectionsNoList(String tenantId, String connectionType) { + public Map getConnectionsNoList(String tenantId, String connectionType) { List preparedStatement = new ArrayList<>(); String query = queryBuilder.getConnectionNumberList(tenantId, connectionType, preparedStatement); log.info("water " + connectionType + " connection list : " + query); - return jdbcTemplate.query(query, preparedStatement.toArray(), demandSchedulerRowMapper); + return jdbcTemplate.query(query, preparedStatement.toArray(), demandListSchedulerRowMapper); } @Override - public List getNonMeterConnectionsList(String tenantId, Long dayStartTime, Long dayEndTime) { + public Map getNonMeterConnectionsList(String tenantId, Long dayStartTime, Long dayEndTime) { List preparedStatement = new ArrayList<>(); String query = queryBuilder.getNonMeteredConnectionsList(tenantId, dayStartTime, dayEndTime, preparedStatement); log.info("water NMconnection list query: " + query); - return jdbcTemplate.query(query, preparedStatement.toArray(), demandSchedulerRowMapper); + return jdbcTemplate.query(query, preparedStatement.toArray(), demandListSchedulerRowMapper); } @Override 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 548e84092..9396bd68e 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 @@ -35,7 +35,7 @@ public class WSCalculatorQueryBuilder { private final static String connectionNoWaterConnectionSearchQuery = "SELECT conn.connectionNo as connectionno FROM eg_ws_service wc INNER JOIN eg_ws_connection conn ON wc.connection_id = conn.id "; - private static final String connectionNoListQuery = "SELECT distinct(conn.connectionno) FROM eg_ws_connection conn INNER JOIN eg_ws_service ws ON conn.id = ws.connection_id"; + private static final String connectionNoListQuery = "SELECT distinct(conn.connectionno),conn.paymenttype FROM eg_ws_connection conn INNER JOIN eg_ws_service ws ON conn.id = ws.connection_id"; private static final String distinctTenantIdsCriteria = "SELECT distinct(tenantid) FROM eg_ws_connection ws"; @@ -43,7 +43,7 @@ public class WSCalculatorQueryBuilder { private static final String PREVIOUS_BILLING_CYCLE_CONNECTION = " select count(*) from eg_ws_connection "; - private static final String nonmeteredConnectionList = " select distinct(conn.connectionno) from eg_ws_connection conn join eg_ws_service ws on conn.id=ws.connection_id where ws.connectiontype='Non_Metered' and conn.status not IN ('Inactive') and conn.connectionno not in ( select distinct(consumercode) from egbs_demand_v1 d where d.businessservice='WS' "; + private static final String nonmeteredConnectionList = " select distinct(conn.connectionno),conn.paymenttype from eg_ws_connection conn join eg_ws_service ws on conn.id=ws.connection_id where ws.connectiontype='Non_Metered' and conn.status not IN ('Inactive') and conn.connectionno not in ( select distinct(consumercode) from egbs_demand_v1 d where d.businessservice='WS' "; public String getDistinctTenantIds() { return distinctTenantIdsCriteria; diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/rowmapper/DemandListSchedulerRowMapper.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/rowmapper/DemandListSchedulerRowMapper.java new file mode 100644 index 000000000..47db9cafb --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/repository/rowmapper/DemandListSchedulerRowMapper.java @@ -0,0 +1,26 @@ +package org.egov.wscalculation.repository.rowmapper; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +@Component +public class DemandListSchedulerRowMapper implements ResultSetExtractor> { + + @Override + public Map extractData(ResultSet rs) throws SQLException, DataAccessException { + Map connectionAndConsumerTypeLists = new HashMap<>(); + + while (rs.next()) { + connectionAndConsumerTypeLists.put(rs.getString("connectionno"), rs.getString("paymenttype")); + } + return connectionAndConsumerTypeLists; + } +} \ No newline at end of file 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 99b216e4d..7766d7799 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 @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Function; +import java.util.stream.Collector; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; @@ -141,7 +142,7 @@ public class DemandService { * generated or updated */ public List generateDemand(RequestInfo requestInfo, List calculations, - Map masterMap, boolean isForConnectionNo, boolean isWSUpdateSMS, boolean isAdvance) { + Map masterMap, boolean isForConnectionNo, boolean isWSUpdateSMS, boolean isAdvance, boolean isAdvanceDemand) { @SuppressWarnings("unchecked") Map financialYearMaster = (Map) masterMap .get(WSCalculationConstant.BILLING_PERIOD); @@ -188,7 +189,7 @@ public List generateDemand(RequestInfo requestInfo, List ca } List createdDemands = new ArrayList<>(); if (!CollectionUtils.isEmpty(createCalculations)) - createdDemands = createDemand(requestInfo, createCalculations, masterMap, isForConnectionNo, isWSUpdateSMS,isAdvance); + createdDemands = createDemand(requestInfo, createCalculations, masterMap, isForConnectionNo, isWSUpdateSMS,isAdvance,isAdvanceDemand); if (!CollectionUtils.isEmpty(updateCalculations)) createdDemands = updateDemandForCalculation(requestInfo, updateCalculations, fromDate, toDate, @@ -204,7 +205,7 @@ public List generateDemand(RequestInfo requestInfo, List ca * @return Returns list of demands */ private List createDemand(RequestInfo requestInfo, List calculations, - Map masterMap, boolean isForConnectionNO, boolean isWSUpdateSMS, boolean isAdvance) { + Map masterMap, boolean isForConnectionNO, boolean isWSUpdateSMS, boolean isAdvance, boolean isAdvanceDemand) { List demands = new LinkedList<>(); List smsRequests = new LinkedList<>(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("d/MM/uuuu"); @@ -314,9 +315,11 @@ private List createDemand(RequestInfo requestInfo, List cal } } } - log.info("Demand Object" + demands.toString()); - List demandRes = demandRepository.saveDemand(requestInfo, demands); + log.info("Demand Object" + demands.toString()); + List demandRes = demandRepository.saveDemand(requestInfo, demands); + + return demandRes; } @@ -894,11 +897,11 @@ public void generateBulkDemandForTenantId(BulkDemand bulkDemand) { 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()); - + Map connectionNosAndConsumerTypes = waterCalculatorDao.getNonMeterConnectionsList(tenantId, dayStartTime, dayEndTime);; - if( connectionNos.size() == 0) { + Set connectionSet = connectionNosAndConsumerTypes.keySet().stream().collect(Collectors.toSet()); + + if( connectionNosAndConsumerTypes.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!"); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/EstimationService.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/EstimationService.java index 36b6db9dc..ed666f75d 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/EstimationService.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/EstimationService.java @@ -129,13 +129,23 @@ private List getEstimatesForTax(Map waterCh if(!isAdvanceCalculation) { if(connection.getArrears()!=null) { - estimates.add(TaxHeadEstimate.builder().taxHeadCode(isconnectionCalculation ? WSCalculationConstant.WS_CHARGE :WSCalculationConstant.WS_CHARGE_ARREAR) - .estimateAmount(waterCharge.get("arrears").setScale(2, 2)).build()); + if(isconnectionCalculation) { + estimates.add(TaxHeadEstimate.builder().taxHeadCode(WSCalculationConstant.WS_CHARGE) + .estimateAmount(waterCharge.get("waterCharge").setScale(2, 2)).build()); + }else { + estimates.add(TaxHeadEstimate.builder().taxHeadCode(WSCalculationConstant.WS_CHARGE_ARREAR) + .estimateAmount(waterCharge.get("arrears").setScale(2, 2)).build()); + } + } if(connection.getPenalty()!=null) { estimates.add(TaxHeadEstimate.builder().taxHeadCode(isconnectionCalculation ? WSCalculationConstant.WS_CHARGE :WSCalculationConstant.WS_PENALTY) .estimateAmount(waterCharge.get("penalty").setScale(2, 2)).build()); } + else { + estimates.add(TaxHeadEstimate.builder().taxHeadCode(WSCalculationConstant.WS_CHARGE) + .estimateAmount(waterCharge.get("waterCharge").setScale(2, 2)).build()); + } }else { estimates.add(TaxHeadEstimate.builder().taxHeadCode(isconnectionCalculation ? WSCalculationConstant.WS_CHARGE :WSCalculationConstant.ADVANCE_COLLECTION) .estimateAmount(waterCharge.get("advance").setScale(2, 2)).build()); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java index 3fb77d6f2..f6a875b08 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/WSCalculationServiceImpl.java @@ -134,10 +134,10 @@ public List getCalculation(CalculationReq request) { if(request.getIsAdvanceCalculation() != null && request.getIsAdvanceCalculation().booleanValue()) { demandService.generateDemand(request.getRequestInfo(), calculations, masterMap, - request.getIsconnectionCalculation(), isWSUpdateSMS, request.getIsAdvanceCalculation()); + request.getIsconnectionCalculation(), isWSUpdateSMS, request.getIsAdvanceCalculation(), false); }else { demandService.generateDemand(request.getRequestInfo(), calculations, masterMap, - request.getIsconnectionCalculation(), isWSUpdateSMS, false); + request.getIsconnectionCalculation(), isWSUpdateSMS, false, false); } unsetWaterConnection(calculations); return calculations; @@ -152,7 +152,7 @@ public List getCalculation(CalculationReq request) { */ public List bulkDemandGeneration(CalculationReq request, Map masterMap) { List calculations = getCalculations(request, masterMap); - demandService.generateDemand(request.getRequestInfo(), calculations, masterMap, true, false, false); + demandService.generateDemand(request.getRequestInfo(), calculations, masterMap, true, false, request.getIsAdvanceCalculation(), request.getIsAdvanceDemand()); return calculations; } @@ -267,7 +267,7 @@ List getCalculations(CalculationReq request, Map ma List calculations = new ArrayList<>(request.getCalculationCriteria().size()); for (CalculationCriteria criteria : request.getCalculationCriteria()) { Map estimationMap = null; - if(request.getIsAdvanceCalculation() == null) { + if(request.getIsAdvanceCalculation() == null || (!request.getIsAdvanceCalculation().booleanValue())) { estimationMap = estimationService.getEstimationMap(criteria, request.getRequestInfo(), masterMap,request.getIsconnectionCalculation(),false); }else { diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/CalculationReq.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/CalculationReq.java index 19cc1401e..e254e915f 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/CalculationReq.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/CalculationReq.java @@ -43,6 +43,9 @@ public class CalculationReq { private Boolean isconnectionCalculation; private Boolean isAdvanceCalculation; + + private Boolean isAdvanceDemand; + @Valid @NotNull