diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java index c95a6aa18..84f89fff7 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/WaterDaoImpl.java @@ -49,6 +49,9 @@ @Repository public class WaterDaoImpl implements WaterDao { + @Autowired + private DemandNotGeneratedRowMapper demandNotGeneratedRowMapper; + @Autowired private InactiveConsumerReportRowMapper inactiveConsumerReportRowMapper; @Autowired @@ -665,4 +668,18 @@ public List getInactiveConsumerReport(Long monthStar inactiveConsumerReportList=jdbcTemplate.query(inactive_consumer_query.toString(), preparedStatement.toArray(),inactiveConsumerReportRowMapper); return inactiveConsumerReportList; } + + public List getConsumersByPreviousMeterReading(Long previousMeterReading, String tenantId) + { + StringBuilder query=new StringBuilder(wsQueryBuilder.DEMAND_NOT_GENERATED_QUERY); + + List preparedStatement=new ArrayList<>(); + preparedStatement.add(tenantId); + preparedStatement.add(previousMeterReading); + preparedStatement.add(tenantId); + + log.info("Query for consumer demand not generated "+ query +" prepared statement "+ preparedStatement); + List consumersDemandNotGeneratedList=jdbcTemplate.query(query.toString(),preparedStatement.toArray(),demandNotGeneratedRowMapper); + return consumersDemandNotGeneratedList; + } } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java index c2a12d432..58ec99739 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/builder/WsQueryBuilder.java @@ -169,6 +169,13 @@ public class WsQueryBuilder { + " connectionno IN (SELECT distinct connectionno FROM eg_ws_connection WHERE status='Inactive' AND" + " lastmodifiedtime >= ? AND lastmodifiedtime <= ? AND tenantid=?) " + " order by connectionno,lastmodifiedtime desc"; + + public static final String DEMAND_NOT_GENERATED_QUERY="select distinct conn.connectionno as connectionno from eg_ws_connection conn " + + "INNER JOIN eg_ws_service wc ON wc.connection_id = conn.id WHERE conn.status='Active' " + + "AND conn.tenantid=? and wc.connectiontype='Non_Metered' and conn.previousreadingdate=? and connectionno NOT IN " + + "(select distinct consumercode from egbs_demand_v1 d inner join egbs_demanddetail_v1 dd on dd.demandid = d.id " + + "where dd.taxheadcode='10101' and d.status ='ACTIVE' and d.businessservice='WS' and " + + "d.tenantid=?) order by connectionno;"; /** * diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/DemandNotGeneratedRowMapper.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/DemandNotGeneratedRowMapper.java new file mode 100644 index 000000000..d42e53595 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/DemandNotGeneratedRowMapper.java @@ -0,0 +1,26 @@ +package org.egov.waterconnection.repository.rowmapper; + +import org.egov.waterconnection.web.models.ConsumersDemandNotGenerated; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.stereotype.Component; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +@Component +public class DemandNotGeneratedRowMapper implements ResultSetExtractor> { + @Override + public List extractData(ResultSet resultSet) throws SQLException, DataAccessException { + List consumersDemandNotGeneratedList=new ArrayList<>(); + while(resultSet.next()) + { + ConsumersDemandNotGenerated consumersDemandNotGenerated=new ConsumersDemandNotGenerated(); + consumersDemandNotGenerated.setConsumerCode(resultSet.getString("connectionno")); + consumersDemandNotGeneratedList.add(consumersDemandNotGenerated); + } + return consumersDemandNotGeneratedList; + } +} diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java index 0c72cd1f8..e4c9ed73b 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterService.java @@ -53,4 +53,5 @@ List collectionReport(String paymentStartDate, String paym List inactiveConsumerReport(String monthStartDate,String monthEndDate,String tenantId, @Valid Integer offset, @Valid Integer limit, RequestInfo requestInfo); + WaterConnectionResponse getConsumersWithDemandNotGenerated(String previousMeterReading, String tenantId,RequestInfo requestInfo); } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java index 704683d4b..ba0803984 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WaterServiceImpl.java @@ -842,4 +842,24 @@ public List inactiveConsumerReport(String monthStart List inactiveConsumerReport=waterDaoImpl.getInactiveConsumerReport(monthStartDateTime,mothEndDateTime,tenantId,offset,limit); return inactiveConsumerReport; } + + @Override + public WaterConnectionResponse getConsumersWithDemandNotGenerated(String previousMeterReading, String tenantId ,RequestInfo requestInfo) + { + Long previousReadingEpoch; + try { + previousReadingEpoch = Long.parseLong(previousMeterReading); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid format for previousMeterReading. Expected a timestamp in milliseconds.", e); + } + + List list=waterDaoImpl.getConsumersByPreviousMeterReading(previousReadingEpoch,tenantId); + Set connectionNo=new HashSet<>(); + for(ConsumersDemandNotGenerated connection:list) + { + connectionNo.add(connection.getConsumerCode()); + } + SearchCriteria criteria=SearchCriteria.builder().connectionNoSet(connectionNo).tenantId(tenantId).build(); + return search(criteria,requestInfo); + } } \ No newline at end of file diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java index cd462ba50..f4da10f1f 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/controller/WaterController.java @@ -235,4 +235,13 @@ public ResponseEntity countWCbyDe return new ResponseEntity<>(response, HttpStatus.OK); } + @PostMapping("/consumers/demand-not-generated") + public ResponseEntity getConsumersWithDemandNotGenerated(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper,@RequestParam(value="previousMeterReading") String previousMeterReading,@RequestParam (value="tenantId") String tenantId) + { + WaterConnectionResponse response= waterService.getConsumersWithDemandNotGenerated(previousMeterReading,tenantId,requestInfoWrapper.getRequestInfo()); + response.setResponseInfo( + responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(), true)); + return new ResponseEntity<>(response, HttpStatus.OK); + } + } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/ConsumersDemandNotGenerated.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/ConsumersDemandNotGenerated.java new file mode 100644 index 000000000..95c8e8e0b --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/ConsumersDemandNotGenerated.java @@ -0,0 +1,13 @@ +package org.egov.waterconnection.web.models; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Data +public class ConsumersDemandNotGenerated { + private String consumerCode; +}