Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #544 from egovernments/PFM-4080-Pagination
Browse files Browse the repository at this point in the history
Added pagination for billReport and collectionReport
  • Loading branch information
rahuldevgarg authored Sep 7, 2023
2 parents c397cf5 + c0569ee commit 2173e79
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,36 +522,81 @@ public BigDecimal getPenaltyCollectionAmount(@Valid SearchCriteria criteria) {
return jdbcTemplate.queryForObject(query.toString(), BigDecimal.class);
}

public List<BillReportData> getBillReportData(@Valid Long demandStartDate,@Valid Long demandEndDate, @Valid String tenantId) {
public List<BillReportData> getBillReportData(@Valid Long demandStartDate,@Valid Long demandEndDate, @Valid String tenantId, @Valid Integer offset, @Valid Integer limit, @Valid String sortOrder) {
StringBuilder query = new StringBuilder(wsQueryBuilder.BILL_REPORT_QUERY);
query.append("where dem.taxperiodfrom =" + demandStartDate);
query.append(" and dem.taxperiodto =" + demandEndDate);
query.append("where dem.taxperiodfrom >=" + demandStartDate);
query.append(" and dem.taxperiodto <=" + demandEndDate);

List<Object> preparedStatement = new ArrayList<>();

if(!tenantId.isEmpty()){
query.append(" and conn.tenantId ='"+tenantId+"'");
}
query.append(" group by conn.connectionno,conn.tenantId,dd.taxheadcode,conn.oldConnectionno,conn.createdTime,dd.taxamount,connectionholder.userid order by conn.connectionno,dd.taxheadcode");

query.append(" group by conn.connectionno,conn.tenantId,dd.taxheadcode,conn.oldConnectionno,conn.createdTime,dd.taxamount,connectionholder.userid order by conn.connectionno,dd.taxheadcode ");
if(sortOrder.equals(SearchCriteria.SortOrder.DESC.name()))
query.append(" DESC ");
else
query.append(" ASC ");

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) {
query.append(" offset ? limit ? ");
preparedStatement.add(newoffset);
preparedStatement.add(newlimit);
}
List<BillReportData> billReportList = new ArrayList<>();
List<Object> preparedStatement = new ArrayList<>();

billReportList = jdbcTemplate.query(query.toString(), preparedStatement.toArray(), reportRowMapper);
return billReportList;

}

public List<CollectionReportData> getCollectionReportData(Long payStartDateTime, Long payEndDateTime,
String tenantId) {
String tenantId,@Valid Integer offset, @Valid Integer limit, @Valid String sortOrder) {
StringBuilder query = new StringBuilder(wsQueryBuilder.COLLECTION_REPORT_QUERY);
query.append(" and pay.transactiondate between "+ payStartDateTime +"and " + payEndDateTime);
query.append(" and pay.transactiondate between "+ payStartDateTime +" and " + payEndDateTime);

List<Object> preparedStatement = new ArrayList<>();

if(!tenantId.isEmpty()){
query.append(" and conn.tenantId ='"+tenantId+"'");
}
query.append(" group by conn.connectionno,conn.tenantId,conn.oldConnectionno,connectionholder.userid,pd.amountpaid,pay.paymentmode");
if(sortOrder.equals(SearchCriteria.SortOrder.DESC.name()))
query.append(" DESC ");
else
query.append(" ASC ");

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){
query.append(" offset ? limit ? ");
preparedStatement.add(newoffset);
preparedStatement.add(newlimit);
}

List<CollectionReportData> collectionReportList = new ArrayList<>();
List<Object> preparedStatement = new ArrayList<>();

collectionReportList = jdbcTemplate.query(query.toString(), preparedStatement.toArray(), collectionReportRowMapper);
return collectionReportList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public interface WaterService {

List<RevenueCollectionData> getRevenueCollectionData(@Valid SearchCriteria criteria, RequestInfo requestInfo);

List<BillReportData> billReport(@Valid String demandStartDate,@Valid String demandEndDate, @Valid String tenantId, RequestInfo requestInfo);
List<BillReportData> billReport(@Valid String demandStartDate, @Valid String demandEndDate, @Valid String tenantId, @Valid Integer offset, @Valid Integer limit, @Valid String sortOrder, RequestInfo requestInfo);

List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,
List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,@Valid Integer offset, @Valid Integer limit, @Valid String sortOrder,
RequestInfo requestInfo);

}
Original file line number Diff line number Diff line change
Expand Up @@ -797,20 +797,20 @@ public void postForMeterReading(WaterConnectionRequest waterConnectionrequest, i
}

@Override
public List<BillReportData> billReport(@Valid String demandStartDate, @Valid String demandEndDate, String tenantId, RequestInfo requestInfo) {
public List<BillReportData> billReport(@Valid String demandStartDate, @Valid String demandEndDate, String tenantId, @Valid Integer offset, @Valid Integer limit, @Valid String sortOrder, RequestInfo requestInfo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate demStartDate = LocalDate.parse(demandStartDate, formatter);
LocalDate demEndDate = LocalDate.parse(demandEndDate, formatter);

Long demStartDateTime = LocalDateTime.of(demStartDate.getYear(), demStartDate.getMonth(), demStartDate.getDayOfMonth(), 0, 0, 0)
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
Long demEndDateTime = LocalDateTime.of(demEndDate, LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
List<BillReportData> billReportData = waterDaoImpl.getBillReportData(demStartDateTime,demEndDateTime,tenantId);
List<BillReportData> billReportData = waterDaoImpl.getBillReportData(demStartDateTime,demEndDateTime,tenantId,offset,limit,sortOrder);
return billReportData;
}

@Override
public List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,
public List<CollectionReportData> collectionReport(String paymentStartDate, String paymentEndDate, String tenantId,@Valid Integer offset, @Valid Integer limit, @Valid String sortOrder,
RequestInfo requestInfo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate payStartDate = LocalDate.parse(paymentStartDate, formatter);
Expand All @@ -819,7 +819,7 @@ public List<CollectionReportData> collectionReport(String paymentStartDate, Stri
Long payStartDateTime = LocalDateTime.of(payStartDate.getYear(), payStartDate.getMonth(), payStartDate.getDayOfMonth(), 0, 0, 0)
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
Long payEndDateTime = LocalDateTime.of(payEndDate,LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
List<CollectionReportData> collectionReportData = waterDaoImpl.getCollectionReportData(payStartDateTime,payEndDateTime,tenantId);
List<CollectionReportData> collectionReportData = waterDaoImpl.getCollectionReportData(payStartDateTime,payEndDateTime,tenantId,offset,limit,sortOrder);
return collectionReportData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ public ResponseEntity<RevenueCollectionDataResponse> _revenueCollectionData(

@RequestMapping(value = "/_billReport", method = RequestMethod.POST)
public ResponseEntity<BillReportResponse> billReport(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper,
@RequestParam(value = "demandStartDate", required = true) String demandStartDate,@RequestParam(value = "demandEndDate", required = true) String demandEndDate,@RequestParam(value = "tenantId",required = true) String tenantId) {
List<BillReportData> billReport = waterService.billReport(demandStartDate,demandEndDate,tenantId,
requestInfoWrapper.getRequestInfo());
@RequestParam(value = "demandStartDate", required = true) String demandStartDate,@RequestParam(value = "demandEndDate", required = true) String demandEndDate,@RequestParam(value = "tenantId",required = true) String tenantId,@RequestParam(value="offset",required = true) Integer offset,@RequestParam(value="limit",required = true)Integer limit,@RequestParam(value="sortOrder") String sortOrder) {
List<BillReportData> billReport = waterService.billReport(demandStartDate,demandEndDate,tenantId,offset,limit,sortOrder,requestInfoWrapper.getRequestInfo());

BillReportResponse response = BillReportResponse.builder().BillReportData(billReport)
.responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(),
Expand All @@ -210,9 +209,8 @@ public ResponseEntity<BillReportResponse> billReport(@Valid @RequestBody Request

@RequestMapping(value = "/_collectionReport", method = RequestMethod.POST)
public ResponseEntity<CollectionReportResponse> collectionReport(@Valid @RequestBody RequestInfoWrapper requestInfoWrapper,
@RequestParam(value = "paymentStartDate", required = true) String paymentStartDate,@RequestParam(value = "paymentEndDate", required = true) String paymentEndDate,@RequestParam(value = "tenantId",required = true) String tenantId) {
List<CollectionReportData> collectionReport = waterService.collectionReport(paymentStartDate,paymentEndDate,tenantId,
requestInfoWrapper.getRequestInfo());
@RequestParam(value = "paymentStartDate", required = true) String paymentStartDate,@RequestParam(value = "paymentEndDate", required = true) String paymentEndDate,@RequestParam(value = "tenantId",required = true) String tenantId, @RequestParam(value="offset",required = true) Integer offset, @RequestParam(value="limit",required = true)Integer limit, @RequestParam(value="sortOrder") String sortOrder) {
List<CollectionReportData> collectionReport = waterService.collectionReport(paymentStartDate,paymentEndDate,tenantId,offset,limit,sortOrder,requestInfoWrapper.getRequestInfo());

CollectionReportResponse response = CollectionReportResponse.builder().CollectionReportData(collectionReport)
.responseInfo(responseInfoFactory.createResponseInfoFromRequestInfo(requestInfoWrapper.getRequestInfo(),
Expand Down

0 comments on commit 2173e79

Please sign in to comment.