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 fd81fc59a..9393b861e 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 @@ -21,6 +21,8 @@ import org.egov.waterconnection.constants.WCConstants; import org.egov.waterconnection.producer.WaterConnectionProducer; import org.egov.waterconnection.repository.builder.WsQueryBuilder; +import org.egov.waterconnection.repository.rowmapper.*; +import org.egov.waterconnection.web.models.*; import org.egov.waterconnection.repository.rowmapper.BillingCycleRowMapper; import org.egov.waterconnection.repository.rowmapper.CollectionRowMapper; import org.egov.waterconnection.repository.rowmapper.FeedbackRowMapper; @@ -49,6 +51,8 @@ @Repository public class WaterDaoImpl implements WaterDao { + @Autowired + private InactiveConsumerReportRowMapper inactiveConsumerReportRowMapper; @Autowired private WaterConnectionProducer waterConnectionProducer; @@ -602,6 +606,40 @@ public List getCollectionReportData(Long payStartDateTime, collectionReportList = jdbcTemplate.query(query.toString(), preparedStatement.toArray(), collectionReportRowMapper); return collectionReportList; } - + public List getInactiveConsumerReport(Long monthStartDateTime, Long monthEndDateTime, @Valid String tenantId, @Valid Integer offset, @Valid Integer limit) + { + StringBuilder inactive_consumer_query=new StringBuilder(wsQueryBuilder.INACTIVE_CONSUMER_QUERY); + + List preparedStatement=new ArrayList<>(); + preparedStatement.add(monthStartDateTime); + preparedStatement.add(monthEndDateTime); + preparedStatement.add(tenantId); + preparedStatement.add(monthStartDateTime); + preparedStatement.add(monthEndDateTime); + preparedStatement.add(tenantId); + + Integer newlimit=wsConfiguration.getDefaultLimit(); + Integer newoffset= wsConfiguration.getDefaultOffset(); + if(limit==null && offset==null) + newlimit=wsConfiguration.getMaxLimit(); + if(limit!=null && limit<=wsConfiguration.getMaxLimit()) + newlimit=limit; + if(limit!=null && limit>=wsConfiguration.getMaxLimit()) + newlimit=wsConfiguration.getMaxLimit(); + + if(offset!=null) + newoffset=offset; + + if (newlimit>0){ + inactive_consumer_query.append(" offset ? limit ? ;"); + preparedStatement.add(newoffset); + preparedStatement.add(newlimit); + } + + List inactiveConsumerReportList=new ArrayList<>(); + log.info("Query of inactive consumer:"+ inactive_consumer_query.toString() +"prepared statement of inactive consumer"+ preparedStatement); + inactiveConsumerReportList=jdbcTemplate.query(inactive_consumer_query.toString(), preparedStatement.toArray(),inactiveConsumerReportRowMapper); + return inactiveConsumerReportList; + } } 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 ac3d93643..da6067e73 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 @@ -43,6 +43,8 @@ public class WsQueryBuilder { private static final String INNER_JOIN_STRING = "INNER JOIN"; private static final String LEFT_OUTER_JOIN_STRING = " LEFT OUTER JOIN "; + + private static final String UNION_STRING=" UNION "; // private static final String Offset_Limit_String = "OFFSET ? LIMIT ?"; // private static String holderSelectValues = "{HOLDERSELECTVALUES}"; @@ -153,6 +155,14 @@ public class WsQueryBuilder { + " AND pay.transactiondate BETWEEN ? AND ? AND conn.tenantId = ? " + " AND pay.paymentstatus!='CANCELLED' GROUP BY conn.tenantId,conn.connectionno,conn.oldConnectionno," + " connectionholder.userid,pay.paymentmode ORDER BY conn.connectionno "; + + public static final String INACTIVE_CONSUMER_QUERY= "SELECT connectionno AS connectionno,status AS status,lastmodifiedby " + + " AS lastmodifiedbyUuid,lastmodifiedtime AS lastmodifiedtime FROM eg_ws_connection_audit WHERE connectionno " + + " IN (SELECT distinct connectionno FROM eg_ws_connection_audit WHERE status='Inactive' AND lastmodifiedtime >= ? AND" + + " lastmodifiedtime <= ? AND tenantid=?) " + UNION_STRING + " SELECT connectionno,status,lastmodifiedby,lastmodifiedtime FROM eg_ws_connection WHERE" + + " connectionno IN (SELECT distinct connectionno FROM eg_ws_connection WHERE status='Inactive' AND" + + " lastmodifiedtime >= ? AND lastmodifiedtime <= ? AND tenantid=?) " + + " order by connectionno,lastmodifiedtime desc"; /** * diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/InactiveConsumerReportRowMapper.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/InactiveConsumerReportRowMapper.java new file mode 100644 index 000000000..971ebbbe6 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/repository/rowmapper/InactiveConsumerReportRowMapper.java @@ -0,0 +1,64 @@ +package org.egov.waterconnection.repository.rowmapper; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.egov.waterconnection.service.UserService; +import org.egov.waterconnection.web.models.CollectionReportData; +import org.egov.waterconnection.web.models.InactiveConsumerReportData; +import org.egov.waterconnection.web.models.OwnerInfo; +import org.egov.waterconnection.web.models.users.UserDetailResponse; +import org.egov.waterconnection.web.models.users.UserSearchRequest; +import org.springframework.beans.factory.annotation.Autowired; +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.*; +@Component +public class InactiveConsumerReportRowMapper implements ResultSetExtractor> { + @Autowired + private ObjectMapper mapper; + + @Autowired + private UserService userService; + + @Override + public List extractData(ResultSet resultSet) throws SQLException, DataAccessException { + List inactiveConsumerReportList=new ArrayList<>(); + while(resultSet.next()) + { + InactiveConsumerReportData inactiveConsumerReportData=new InactiveConsumerReportData(); + inactiveConsumerReportData.setConnectionno(resultSet.getString("connectionno")); + inactiveConsumerReportData.setStatus(resultSet.getString("status")); + inactiveConsumerReportData.setInactiveDate(resultSet.getLong("lastmodifiedtime")); + inactiveConsumerReportData.setInactivatedByUuid(resultSet.getString("lastmodifiedbyUuid")); + inactiveConsumerReportList.add(inactiveConsumerReportData); + } + if(!inactiveConsumerReportList.isEmpty()) { + enrichConnectionHolderDetails(inactiveConsumerReportList); + } + return inactiveConsumerReportList; + } + public void enrichConnectionHolderDetails(List inactiveConsumerReportList) + { + Set lastModifiedByUuid= new HashSet<>(); + for(InactiveConsumerReportData inactiveConsumerReportData:inactiveConsumerReportList) + { + lastModifiedByUuid.add(inactiveConsumerReportData.getInactivatedByUuid()); + } + UserSearchRequest userSearchRequest=new UserSearchRequest(); + userSearchRequest.setUuid(lastModifiedByUuid); + UserDetailResponse userDetailResponse = userService.getUser(userSearchRequest); + enrichConnectionHolderInfo(userDetailResponse, inactiveConsumerReportList); + + } + + private void enrichConnectionHolderInfo(UserDetailResponse userDetailResponse, + List inactiveConsumerReportList) { + List connectionHolderInfos = userDetailResponse.getUser(); + Map userIdToConnectionHolderMap = new HashMap<>(); + connectionHolderInfos.forEach(user -> userIdToConnectionHolderMap.put(user.getUuid(), user)); + inactiveConsumerReportList.forEach(inactiveConsumerReportData-> inactiveConsumerReportData.setInactivatedByName(userIdToConnectionHolderMap.get(inactiveConsumerReportData.getInactivatedByUuid()).getName())); + } +} 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 4ea0f45d1..ac3d91a67 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 @@ -5,6 +5,7 @@ import javax.validation.Valid; 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; @@ -50,5 +51,7 @@ public interface WaterService { List collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,@Valid Integer offset, @Valid Integer limit, @Valid String sortOrder, RequestInfo requestInfo); + + List inactiveConsumerReport(String monthStartDate,String monthEndDate,String tenantId, @Valid Integer offset, @Valid Integer limit, 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 1ddaa5dda..2782ef0f1 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 @@ -108,6 +108,7 @@ public class WaterServiceImpl implements WaterService { private WaterConnectionProducer waterConnectionProducer; @Autowired + @Lazy private WaterRepository repository; @Autowired @@ -822,4 +823,16 @@ public List collectionReport(String paymentStartDate, Stri List collectionReportData = waterDaoImpl.getCollectionReportData(payStartDateTime,payEndDateTime,tenantId,offset,limit,sortOrder); return collectionReportData; } + + public List inactiveConsumerReport(String monthStartDate,String monthEndDate,String tenantId,@Valid Integer offset,@Valid Integer limit, RequestInfo requestInfo) + { + DateTimeFormatter formatter=DateTimeFormatter.ofPattern("dd/MM/yyyy"); + LocalDate startDate=LocalDate.parse(monthStartDate,formatter); + LocalDate endDate=LocalDate.parse(monthEndDate,formatter); + + Long monthStartDateTime=LocalDateTime.of(startDate.getYear(),startDate.getMonth(),startDate.getDayOfMonth(),0,0,0).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + Long mothEndDateTime=LocalDateTime.of(endDate,LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + List inactiveConsumerReport=waterDaoImpl.getInactiveConsumerReport(monthStartDateTime,mothEndDateTime,tenantId,offset,limit); + return inactiveConsumerReport; + } } \ 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 c28aa7adb..5a9e6be54 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 @@ -8,6 +8,7 @@ import org.egov.waterconnection.service.SchedulerService; import org.egov.waterconnection.service.WaterService; import org.egov.waterconnection.util.ResponseInfoFactory; +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; @@ -218,4 +219,15 @@ public ResponseEntity collectionReport(@Valid @Request .build(); return new ResponseEntity<>(response, HttpStatus.OK); } + @RequestMapping(value = "/_inactiveConsumerReport",method = RequestMethod.POST) + public ResponseEntity inactiveConsumerReport(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper, + @RequestParam(value="monthStartDate",required = true) String monthStartDate,@RequestParam(value="monthEndDate",required = true) String monthEndDate, + @RequestParam(value = "tenantId",required = true) String tenantId,@RequestParam(value="offset",required = true) Integer offset, @RequestParam(value="limit",required = true)Integer limit) + { + List inactiveConsumerReport=waterService.inactiveConsumerReport(monthStartDate,monthEndDate,tenantId,offset,limit,requestInfoWrapper.getRequestInfo()); + InactiveConsumerReportResponse response=InactiveConsumerReportResponse.builder().InactiveConsumerReportData(inactiveConsumerReport) + .responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(),true)).build(); + + return new ResponseEntity<>(response,HttpStatus.OK); + } } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/InactiveConsumerReportData.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/InactiveConsumerReportData.java new file mode 100644 index 000000000..4411214c7 --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/InactiveConsumerReportData.java @@ -0,0 +1,31 @@ +package org.egov.waterconnection.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class InactiveConsumerReportData { + + @JsonProperty("tenantName") + private String tenantName = null; + + @JsonProperty("connectionno") + private String connectionno=null; + + @JsonProperty("status") + private String status=null; + + @JsonProperty("inactiveDate") + private Long inactiveDate = null; + + @JsonProperty("inactivatedByUuid") + private String inactivatedByUuid=null; + + @JsonProperty("inactivatedByName") + private String inactivatedByName=null; + +} diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/InactiveConsumerReportResponse.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/InactiveConsumerReportResponse.java new file mode 100644 index 000000000..f5a6ed3cc --- /dev/null +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/InactiveConsumerReportResponse.java @@ -0,0 +1,17 @@ +package org.egov.waterconnection.web.models; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import org.egov.common.contract.response.ResponseInfo; + +import java.util.List; + +@Builder +public class InactiveConsumerReportResponse { + + @JsonProperty("InactiveConsumerReport") + private List InactiveConsumerReportData; + + @JsonProperty("responseInfo") + private ResponseInfo responseInfo = null; +}