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 9fbfdfd01..c95a6aa18 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 @@ -2,7 +2,6 @@ import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -12,7 +11,6 @@ import javax.validation.Valid; -import org.apache.commons.lang3.StringUtils; import org.egov.common.contract.request.RequestInfo; import org.egov.common.contract.request.Role; import org.egov.common.contract.request.User; @@ -67,6 +65,9 @@ public class WaterDaoImpl implements WaterDao { @Autowired private OpenWaterRowMapper openWaterRowMapper; + + @Autowired + private WcbyDemandRowMapper wcbyDemandRowMapper; @Autowired private ReportRowMapper reportRowMapper; @@ -159,7 +160,26 @@ public void updateWaterConnection(WaterConnectionRequest waterConnectionRequest, waterConnectionProducer.push(wsConfiguration.getWorkFlowUpdateTopic(), waterConnectionRequest); } } - + public WaterConnectionByDemandGenerationDateResponse getWaterConnectionByDemandDate (SearchCriteria criteria, RequestInfo requestInfo) { + + List waterConnectionByPreviousReadingDateList = new ArrayList<>(); + List waterConnectionByDemandGenerationDateList = new ArrayList<>(); + WaterConnectionByDemandGenerationDateResponse response = new WaterConnectionByDemandGenerationDateResponse(); + List preparedStatement = new ArrayList<>(); + String query1 = wsQueryBuilder.getQueryForWCCountForPreviousreadingdate(criteria, preparedStatement, requestInfo); + if (query1 == null) + return null; + waterConnectionByPreviousReadingDateList = jdbcTemplate.query(query1, preparedStatement.toArray(), wcbyDemandRowMapper); + String query2 = wsQueryBuilder.getQueryForWCCountbyDemandDate(criteria, preparedStatement, requestInfo); + + if (query2 == null) + return null; + waterConnectionByDemandGenerationDateList = jdbcTemplate.query(query2, preparedStatement.toArray(), wcbyDemandRowMapper); + response.setWaterConnectionByDemandGenerationDates(waterConnectionByDemandGenerationDateList); + response.setWaterConnectionByDemandNotGeneratedDates(waterConnectionByPreviousReadingDateList); + return response; + } + /** * push object to create meter reading * 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 90915b808..a9b335eea 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 @@ -66,6 +66,12 @@ public class WsQueryBuilder { + "eg_ws_connectionholder connectionholder ON connectionholder.connectionid = conn.id" + LEFT_OUTER_JOIN_STRING + "eg_ws_roadcuttinginfo roadcuttingInfo ON roadcuttingInfo.wsid = conn.id"; + private static final String WATER_CONNNECTION_BY_DEMANNDDATE = "SELECT ((select distinct d.taxperiodto as taxperiodto from egbs_demand_v1 d where d.status = 'ACTIVE' and d.businessservice = 'WS' and d.consumercode = conn.connectionno order by d.taxperiodto desc limit 1)) as taxperiodto, count(*) as count" + + " FROM eg_ws_connection conn INNER JOIN eg_ws_service wc ON wc.connection_id = conn.id and wc.connectiontype='Non_Metered'and conn.status='Active'"; + + private static final String WATER_CONNECTION_BY_PREVIOUSREADINNDATE = "select previousreadingdate as taxperiodto , count(*) as count from eg_ws_connection conn"; + + private static final String CONSUMERCODE_IN_DEMANDTABLE= "select consumercode from egbs_demand_v1 d"; private static final String PAGINATION_WRAPPER = "{} {orderby} {pagination}"; private static final String ORDER_BY_CLAUSE = " ORDER BY wc.appCreatedDate DESC"; @@ -704,4 +710,24 @@ private String addOrderByClauseForPlaneSearch(SearchCriteria criteria) { return builder.toString(); } + public String getQueryForWCCountbyDemandDate(SearchCriteria criteria, List preparedStatement, + RequestInfo requestInfo) { + if (criteria.isEmpty() || criteria.getTenantId().isEmpty()) + return null; + StringBuilder query = new StringBuilder(WATER_CONNNECTION_BY_DEMANNDDATE); + applyFiltersForPlaneSearch(query,preparedStatement,criteria); + query.append(" GROUP BY taxperiodto "); + return query.toString(); + } + + public String getQueryForWCCountForPreviousreadingdate(SearchCriteria criteria, List preparedStatement, + RequestInfo requestInfo) { + if (criteria.isEmpty() || criteria.getTenantId().isEmpty()) + return null; + StringBuilder query = new StringBuilder(WATER_CONNECTION_BY_PREVIOUSREADINNDATE); + query.append(" INNER JOIN eg_ws_service wc ON wc.connection_id = conn.id WHERE conn.status='Active' AND conn.tenantid='"+criteria.getTenantId()+"' and wc.connectiontype='Non_Metered' and connectionno NOT IN (" + CONSUMERCODE_IN_DEMANDTABLE+" where d.businessservice='WS' and d.tenantid='"+criteria.getTenantId()+"') "); + query.append(" GROUP BY taxperiodto "); + return query.toString(); + } + } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/WcbyDemandRowMapper.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/WcbyDemandRowMapper.java new file mode 100644 index 000000000..c45544f94 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/WcbyDemandRowMapper.java @@ -0,0 +1,32 @@ +package org.egov.waterconnection.repository.rowmapper; + +import lombok.extern.slf4j.Slf4j; +import org.egov.waterconnection.web.models.WaterConnectionByDemandGenerationDate; +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 +@Slf4j +public class WcbyDemandRowMapper implements ResultSetExtractor> { + + @Override + public List extractData(ResultSet rs) throws SQLException, DataAccessException { + List waterDemandGenerationDateResponseList = new ArrayList(); + while (rs.next()) { + String taxperiodto = String.valueOf(rs.getLong("taxperiodto")); + if (!taxperiodto.isEmpty() && !taxperiodto.equalsIgnoreCase("0")) { + WaterConnectionByDemandGenerationDate waterDemandGenerationDateResponse = new WaterConnectionByDemandGenerationDate(); + waterDemandGenerationDateResponse.setDate(Long.valueOf(taxperiodto)); + waterDemandGenerationDateResponse.setCount(Integer.valueOf(rs.getInt("count"))); + waterDemandGenerationDateResponseList.add(waterDemandGenerationDateResponse); + } + + } + return waterDemandGenerationDateResponseList; + } +} 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 ac3d91a67..0c72cd1f8 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 @@ -7,9 +7,7 @@ import org.egov.common.contract.request.RequestInfo; import org.egov.waterconnection.web.models.*; import org.egov.waterconnection.web.models.BillReportData; -import org.egov.waterconnection.web.models.BillReportResponse; import org.egov.waterconnection.web.models.CollectionReportData; -import org.egov.waterconnection.web.models.Feedback; import org.egov.waterconnection.web.models.FeedbackRequest; import org.egov.waterconnection.web.models.FeedbackSearchCriteria; @@ -30,7 +28,8 @@ public interface WaterService { List createWaterConnection(WaterConnectionRequest waterConnectionRequest); WaterConnectionResponse search(SearchCriteria criteria, RequestInfo requestInfo); - + + WaterConnectionByDemandGenerationDateResponse countWCbyDemandGennerationDate(SearchCriteria criteria, RequestInfo requestInfo); List updateWaterConnection(WaterConnectionRequest waterConnectionRequest); void submitFeedback( FeedbackRequest feedbackrequest); 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 2782ef0f1..704683d4b 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 @@ -201,6 +201,10 @@ public WaterConnectionResponse search(SearchCriteria criteria, RequestInfo reque return waterConnection; } + public WaterConnectionByDemandGenerationDateResponse countWCbyDemandGennerationDate(SearchCriteria criteria, RequestInfo requestInfo) { + return getWCbyDemandGennerationDate(criteria, requestInfo); + } + /** * * @param criteria WaterConnectionSearchCriteria contains search criteria on @@ -211,6 +215,9 @@ public WaterConnectionResponse search(SearchCriteria criteria, RequestInfo reque public WaterConnectionResponse getWaterConnectionsList(SearchCriteria criteria, RequestInfo requestInfo) { return waterDaoImpl.getWaterConnectionList(criteria, requestInfo); } + public WaterConnectionByDemandGenerationDateResponse getWCbyDemandGennerationDate(SearchCriteria criteria, RequestInfo requestInfo) { + return waterDaoImpl.getWaterConnectionByDemandDate(criteria, requestInfo); + } /** * 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 5a9e6be54..cd462ba50 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 @@ -41,7 +41,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; -import io.swagger.models.parameters.QueryParameter; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -230,4 +229,10 @@ public ResponseEntity inactiveConsumerReport(@Va return new ResponseEntity<>(response,HttpStatus.OK); } + @RequestMapping(value = "/_countWCbyDemandGenerationDate", method = RequestMethod.POST) + public ResponseEntity countWCbyDemandGenerationDate(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper, @Valid @ModelAttribute SearchCriteria criteria) { + WaterConnectionByDemandGenerationDateResponse response = waterService.countWCbyDemandGennerationDate(criteria, requestInfoWrapper.getRequestInfo()); + return new ResponseEntity<>(response, HttpStatus.OK); + } + } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDate.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDate.java new file mode 100644 index 000000000..d54b10281 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDate.java @@ -0,0 +1,16 @@ +package org.egov.waterconnection.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Builder +public class WaterConnectionByDemandGenerationDate { + @JsonProperty("count") + Integer count; + @JsonProperty("taxperiodto") + private Long date; +} diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDateResponse.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDateResponse.java new file mode 100644 index 000000000..9f661f603 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/WaterConnectionByDemandGenerationDateResponse.java @@ -0,0 +1,18 @@ +package org.egov.waterconnection.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +import java.util.List; +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Builder +public class WaterConnectionByDemandGenerationDateResponse { + + @JsonProperty("WaterConnectionsDemandGenerated") + List waterConnectionByDemandGenerationDates; + @JsonProperty("WaterConnectionsDemandNotGenerated") + List waterConnectionByDemandNotGeneratedDates; +}