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 #837 from egovernments/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pradeepkumarcm-egov authored Jul 8, 2024
2 parents f8ade68 + 2719d6a commit a70472f
Show file tree
Hide file tree
Showing 101 changed files with 5,298 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ public class ApplicationProperties {
@Value("${kafka.topics.receipt.cancel.name}")
private String receiptCancellationTopic;

@Value("${kafka.topics.demand.index.name}")
private String demandIndexTopic;


@Value("${kafka.topics.create.demand.index.name}")
private String createDemandIndexTopic;

@Value("${kafka.topics.update.demand.index.name}")
private String updateDemandIndexTopic;

/*
* billing service v1.1
*/
Expand Down Expand Up @@ -207,4 +209,14 @@ public class ApplicationProperties {

@Value("${kafka.mgramseva.update.bill}")
private String updateBill;

@Value("${egov.demand.default.offset}")
private Integer demandDefaultOffset;

@Value("${egov.demand.default.limit}")
private Integer demandDefaultLimit;

@Value("${egov.demand.max.limit}")
private Integer demandMaxLimit;

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public class AggregatedDemandDetailResponse {
private BigDecimal netDueWithPenalty;

private BigDecimal totalApplicablePenalty;

private long latestDemandCreatedTime;

private long latestDemandPenaltyCreatedtime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public class DemandCriteria {
private Long periodFrom;

private Long periodTo;

private Long fromDate;

private Long toDate;

private Type type;

Expand All @@ -86,7 +90,11 @@ public class DemandCriteria {
private String status;

private Boolean isPaymentCompleted;


private Integer offset;

private Integer limit;

@Default
private Boolean receiptRequired=false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.kafka.common.protocol.types.Field;
import org.egov.demand.model.AuditDetails;
import org.egov.demand.model.Demand;
import org.egov.demand.model.DemandCriteria;
Expand All @@ -59,15 +60,18 @@
import org.egov.demand.repository.rowmapper.DemandRowMapper;
import org.egov.demand.util.Util;
import org.egov.demand.web.contract.DemandRequest;
import org.egov.tracer.model.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

@Repository
@Slf4j
Expand Down Expand Up @@ -409,4 +413,24 @@ public List<Demand> getDemandHistory(DemandCriteria demandCriteria) {
String searchDemandQuery = demandQueryBuilder.getDemandHistoryQuery(demandCriteria, preparedStatementValues);
return jdbcTemplate.query(searchDemandQuery, preparedStatementValues.toArray(), demandHistoryRowMapper);
}

public List<String> getDemandIds(DemandCriteria demandCriteria)
{
List<Object> preparedStmtList = new ArrayList<>();
String searchDemandQuery = demandQueryBuilder.getdemandIdSearchQuery(demandCriteria, preparedStmtList);
return jdbcTemplate.query(searchDemandQuery, new SingleColumnRowMapper<>(String.class), preparedStmtList.toArray());
}

public List<Demand> getDemandsPlainSearch(DemandCriteria demandCriteria) {

if (demandCriteria.getDemandId() == null || CollectionUtils.isEmpty(demandCriteria.getDemandId()))
throw new CustomException("PLAIN_SEARCH_ERROR", "Search only allowed by ids!");

List<Object> preparedStmtList = new ArrayList<>();
String query = demandQueryBuilder.getDemandPlainSearchQuery(demandCriteria, preparedStmtList);
log.info("Query: " + query);
log.info("PS: " + preparedStmtList);
return jdbcTemplate.query(query, preparedStmtList.toArray(), demandRowMapper);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@
*/
package org.egov.demand.repository.querybuilder;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.kafka.common.protocol.types.Field;
import org.egov.demand.model.DemandCriteria;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
Expand Down Expand Up @@ -136,7 +134,8 @@ public class DemandQueryBuilder {

public static final String DEMAND_UPDATE_CONSUMERCODE_QUERY="UPDATE egbs_demand_v1 SET consumercode=?, lastmodifiedby=?, lastmodifiedtime=? "
+ " WHERE tenantid=? AND id IN (";


public static final String FETCH_DEMAND_IDS_QUERY = "SELECT dmd.id AS did FROM egbs_demand_v1 dmd WHERE";

public String getDemandQueryForConsumerCodes(Map<String,Set<String>> businessConsumercodeMap,List<Object> preparedStmtList, String tenantId){

Expand Down Expand Up @@ -174,25 +173,59 @@ public String getDemandQuery(DemandCriteria demandCriteria, List<Object> prepare

StringBuilder demandQuery = new StringBuilder(BASE_DEMAND_QUERY);

addDemandCriteria(demandQuery, demandCriteria, preparedStatementValues);
addOrderByClause(demandQuery, DEMAND_QUERY_ORDER_BY_CLAUSE);
addPagingClause(demandQuery, preparedStatementValues);

log.info("the query String for demand : " + demandQuery.toString());
return demandQuery.toString();
}

public String getdemandIdSearchQuery(DemandCriteria demandCriteria, List<Object> preparedStatementValues)
{
StringBuilder demandIdSearchQuery = new StringBuilder(FETCH_DEMAND_IDS_QUERY);
addDemandCriteria(demandIdSearchQuery, demandCriteria, preparedStatementValues);
addOrderByClause(demandIdSearchQuery, DEMAND_QUERY_ORDER_BY_CLAUSE);
addPagingClauseForDemandIdSearch(demandIdSearchQuery, demandCriteria, preparedStatementValues);
log.info("Query for demand id search : " + demandIdSearchQuery.toString());
return demandIdSearchQuery.toString();

}

public String getDemandPlainSearchQuery(DemandCriteria demandCriteria, List<Object> preparedStmtList) {

StringBuilder demandQuery = new StringBuilder(BASE_DEMAND_QUERY);

Set<String> ids = demandCriteria.getDemandId();
if (!CollectionUtils.isEmpty(ids)) {
demandQuery.append(" dmd.id IN (").append(createQuery( new ArrayList<>(ids))).append(")");
addToPreparedStatement(preparedStmtList, ids);
}

return demandQuery.toString();
}

public void addDemandCriteria(StringBuilder demandQuery, DemandCriteria demandCriteria, List<Object> preparedStatementValues)
{
String tenantId = demandCriteria.getTenantId();
String[] tenantIdChunks = tenantId.split("\\.");

if(tenantIdChunks.length == 1){
demandQuery.append(" dmd.tenantid LIKE ? ");
preparedStatementValues.add(demandCriteria.getTenantId() + '%');
}else{
demandQuery.append(" dmd.tenantid = ? ");
preparedStatementValues.add(demandCriteria.getTenantId());
}


if (demandCriteria.getStatus() != null) {

addAndClause(demandQuery);
demandQuery.append("dmd.status=?");
preparedStatementValues.add(demandCriteria.getStatus());
}

if (demandCriteria.getDemandId() != null && !demandCriteria.getDemandId().isEmpty()) {
addAndClause(demandQuery);
demandQuery.append("dmd.id IN (" + getIdQueryForStrings(demandCriteria.getDemandId()) + ")");
Expand All @@ -208,39 +241,45 @@ public String getDemandQuery(DemandCriteria demandCriteria, List<Object> prepare
demandQuery.append("dmd.businessservice=?");
preparedStatementValues.add(demandCriteria.getBusinessService());
}

if(demandCriteria.getIsPaymentCompleted() != null){
addAndClause(demandQuery);
demandQuery.append("dmd.ispaymentcompleted = ?");
preparedStatementValues.add(demandCriteria.getIsPaymentCompleted());
}

if (demandCriteria.getPeriodFrom() != null) {
addAndClause(demandQuery);
demandQuery.append("dmd.taxPeriodFrom >= ?");
preparedStatementValues.add(demandCriteria.getPeriodFrom());
}

if(demandCriteria.getPeriodTo() != null){
addAndClause(demandQuery);
demandQuery.append("dmd.taxPeriodTo <= ?");
preparedStatementValues.add(demandCriteria.getPeriodTo());
}


if(demandCriteria.getFromDate() != null){
addAndClause(demandQuery);
demandQuery.append(" dmd.createdtime >= ? ");
preparedStatementValues.add(demandCriteria.getFromDate());
}

if(demandCriteria.getToDate() != null){
addAndClause(demandQuery);
demandQuery.append(" dmd.createdtime <= ? ");
preparedStatementValues.add(demandCriteria.getToDate());
}

if (demandCriteria.getConsumerCode() != null && !demandCriteria.getConsumerCode().isEmpty()) {
addAndClause(demandQuery);
demandQuery.append("dmd.consumercode IN ("
+ getIdQueryForStrings(demandCriteria.getConsumerCode()) + ")");
+ getIdQueryForStrings(demandCriteria.getConsumerCode()) + ")");
addToPreparedStatement(preparedStatementValues, demandCriteria.getConsumerCode());
}

addOrderByClause(demandQuery, DEMAND_QUERY_ORDER_BY_CLAUSE);
addPagingClause(demandQuery, preparedStatementValues);

log.info("the query String for demand : " + demandQuery.toString());
return demandQuery.toString();
}

private static void addOrderByClause(StringBuilder demandQueryBuilder,String columnName) {
demandQueryBuilder.append(" ORDER BY " + columnName);
}
Expand All @@ -256,7 +295,7 @@ private static boolean addAndClause(StringBuilder queryString) {
queryString.append(" AND ");
return true;
}

private static String getIdQueryForStrings(Set<String> idList) {

StringBuilder builder = new StringBuilder();
Expand All @@ -272,11 +311,11 @@ private void addToPreparedStatement(List<Object> preparedStmtList, Collection<St
{
ids.forEach(id ->{ preparedStmtList.add(id);});
}

public String getDemandHistoryQuery(DemandCriteria demandCriteria, List<Object> preparedStatementValues) {

StringBuilder demandQuery = new StringBuilder(BASE_DEMAND_HISTORY_QUERY);
StringBuilder demandQuery = new StringBuilder(BASE_DEMAND_HISTORY_QUERY);

if( demandCriteria.getTenantId() != null) {
demandQuery.append(" dmd.tenantid = ? ");
preparedStatementValues.add(demandCriteria.getTenantId());
Expand All @@ -286,11 +325,11 @@ public String getDemandHistoryQuery(DemandCriteria demandCriteria, List<Object>
demandQuery.append("dmd.businessservice=?");
preparedStatementValues.add(demandCriteria.getBusinessService());
}

if (demandCriteria.getConsumerCode() != null && !demandCriteria.getConsumerCode().isEmpty()) {
addAndClause(demandQuery);
demandQuery.append("dmd.consumercode IN ("
+ getIdQueryForStrings(demandCriteria.getConsumerCode()) + ")");
+ getIdQueryForStrings(demandCriteria.getConsumerCode()) + ")");
addToPreparedStatement(preparedStatementValues, demandCriteria.getConsumerCode());
}

Expand All @@ -299,4 +338,22 @@ public String getDemandHistoryQuery(DemandCriteria demandCriteria, List<Object>
log.info("the query String for demand : " + demandQuery.toString());
return demandQuery.toString();
}

private static void addPagingClauseForDemandIdSearch(StringBuilder demandQuery, DemandCriteria demandCriteria, List<Object> preparedStatementValues) {
demandQuery.append(" LIMIT ?");
preparedStatementValues.add(demandCriteria.getLimit());
demandQuery.append(" OFFSET ?");
preparedStatementValues.add(demandCriteria.getOffset());
}

private Object createQuery(List<String> ids) {
StringBuilder builder = new StringBuilder();
int length = ids.size();
for (int i = 0; i < length; i++) {
builder.append(" ?");
if (i != length - 1)
builder.append(",");
}
return builder.toString();
}
}
Loading

0 comments on commit a70472f

Please sign in to comment.