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 #815 from egovernments/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pradeepkumarcm-egov authored Jun 17, 2024
2 parents a408b26 + 1d8c2ae commit 417460b
Show file tree
Hide file tree
Showing 37 changed files with 674 additions and 478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class BillV2 {
@Size(max = 256)
private String id;

@JsonProperty("userId")
private String userId;

@JsonProperty("mobileNumber")
@Pattern(regexp = "^[0-9]{10}$", message = "MobileNumber should be 10 digit number")
private String mobileNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public void setValues(PreparedStatement ps, int index) throws SQLException {
AuditDetails auditDetails = bill.getAuditDetails();

ps.setString(1, bill.getId());
ps.setString(15, bill.getUserId());
ps.setString(16, bill.getConsumerCode());
ps.setString(2, bill.getTenantId());
ps.setString(3, bill.getPayerName());
ps.setString(4, bill.getPayerAddress());
Expand All @@ -82,8 +84,8 @@ public void setValues(PreparedStatement ps, int index) throws SQLException {
ps.setString(12, bill.getMobileNumber());
ps.setString(13, bill.getStatus().toString());
ps.setObject(14, util.getPGObject(bill.getAdditionalDetails()));
ps.setString(15, bill.getConsumerCode());
ps.setString(16, bill.getTenantId());
// ps.setString(15, bill.getConsumerCode());
// ps.setString(16, bill.getTenantId());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public class BillQueryBuilder {
public static final String BILL_STATUS_UPDATE_BASE_QUERY = "UPDATE egbs_bill_v1 SET status=?, lastmodifieddate=? {replace} WHERE status='ACTIVE' AND tenantId = ? ";

public static final String INSERT_BILL_QUERY = "INSERT into egbs_bill_v1 "
+ " (id, tenantid, payername, payeraddress, payeremail, isactive, iscancelled, createdby, createddate, lastmodifiedby, lastmodifieddate, mobilenumber, status, additionaldetails)"
+ " SELECT ?,?,?,?,?,?,?,?,?,?,?,?,?,? "
+ " WHERE NOT EXISTS (SELECT distinct(consumercode) FROM egbs_bill_v1 bill INNER JOIN egbs_billdetail_v1 billd ON bill.id=billd.billid "
+ " WHERE status = 'ACTIVE' AND consumerCode = ? AND bill.tenantid = ?)";
+"(id, tenantid, payername, payeraddress, payeremail, isactive, iscancelled, createdby, createddate, lastmodifiedby, lastmodifieddate,"
+" mobilenumber, status, additionaldetails, payerid, consumercode)"
+"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";


public static final String INSERT_BILLDETAILS_QUERY = "INSERT into egbs_billdetail_v1 "
Expand All @@ -49,7 +48,7 @@ public class BillQueryBuilder {
+ " INNER JOIN (SELECT bd_consumercode, min(b_createddate) as mindate FROM billresult GROUP BY bd_consumercode) as uniqbill"
+ " ON uniqbill.bd_consumercode=billresult.bd_consumercode AND uniqbill.mindate=billresult.b_createddate ";

public static final String BILL_BASE_QUERY = "SELECT b.id AS b_id,b.mobilenumber, b.tenantid AS b_tenantid,"
public static final String BILL_BASE_QUERY = "SELECT b.id AS b_id,b.mobilenumber, b.tenantid AS b_tenantid,b.payerid AS b_payerid,"
+ " b.payername AS b_payername, b.payeraddress AS b_payeraddress, b.payeremail AS b_payeremail,b.filestoreid AS b_fileStoreId,"
+ " b.isactive AS b_isactive, b.iscancelled AS b_iscancelled, b.createdby AS b_createdby, b.status as b_status,"
+ " b.createddate AS b_createddate, b.lastmodifiedby AS b_lastmodifiedby, b.lastmodifieddate AS b_lastmodifieddate,"
Expand Down Expand Up @@ -82,9 +81,9 @@ public String getBillQuery(BillSearchCriteria billSearchCriteria, List<Object> p
}
addWhereClause(billQuery, preparedStatementValues, billSearchCriteria);

if(billSearchCriteria!=null && billSearchCriteria.getReturnAllBills()) {
return billQuery.toString();
}
// if(billSearchCriteria!=null && billSearchCriteria.getReturnAllBills()) {
// return billQuery.toString();
// }
StringBuilder maxQuery = addPagingClause(billQuery, preparedStatementValues, billSearchCriteria);

return maxQuery.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public List<BillV2> extractData(ResultSet rs) throws SQLException {
.id(billId)
.totalAmount(BigDecimal.ZERO)
.tenantId(rs.getString("b_tenantid"))
.userId(rs.getString("b_payerid"))
.payerName(rs.getString("b_payername"))
.payerAddress(rs.getString("b_payeraddress"))
.payerEmail(rs.getString("b_payeremail"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.egov.common.contract.request.RequestInfo;
import org.egov.demand.config.ApplicationProperties;
Expand Down Expand Up @@ -99,6 +100,10 @@
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.egov.demand.producer.Producer;
import org.egov.demand.web.contract.UserResponse;
import org.egov.demand.web.contract.UserSearchRequest;
import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -138,9 +143,20 @@ public class BillServicev2 {

@Autowired
private BillValidator billValidator;

@Autowired
private Producer producer;

@Autowired
private ObjectMapper mapper;

@Value("${kafka.topics.cancel.bill.topic.name}")
private String billCancelTopic;

@Value("${kafka.topics.billgen.topic.name}")
private String notifTopicName;

private static List<String> ownerPlainRequestFieldsList;

/**
* Cancell bill operation can be carried by this method, based on consumerCodes
Expand All @@ -154,6 +170,7 @@ public class BillServicev2 {
public Integer cancelBill(UpdateBillRequest updateBillRequest) {

UpdateBillCriteria cancelBillCriteria = updateBillRequest.getUpdateBillCriteria();
billValidator.validateBillSearchRequest(cancelBillCriteria);
Set<String> consumerCodes = cancelBillCriteria.getConsumerCodes();
cancelBillCriteria.setStatusToBeUpdated(BillStatus.CANCELLED);

Expand All @@ -162,10 +179,31 @@ public Integer cancelBill(UpdateBillRequest updateBillRequest) {
throw new CustomException("EG_BS_CANCEL_BILL_ERROR", "Only one consumer code can be provided in the Cancel request");
} else {

return billRepository.updateBillStatus(cancelBillCriteria);
int result = billRepository.updateBillStatus(cancelBillCriteria);
sendNotificationForBillCancellation(updateBillRequest.getRequestInfo(), cancelBillCriteria);
return result;
}
}

private void sendNotificationForBillCancellation(RequestInfo requestInfo, UpdateBillCriteria cancelBillCriteria) {
Set<String> consumerCodes = cancelBillCriteria.getConsumerCodes();
if(CollectionUtils.isEmpty(consumerCodes))
return;

List<BillV2> bills = billRepository.findBill(BillSearchCriteria.builder()
.service(cancelBillCriteria.getBusinessService())
.tenantId(cancelBillCriteria.getTenantId())
.consumerCode(consumerCodes)
.build());

if (CollectionUtils.isEmpty(bills))
return;

BillRequestV2 req = BillRequestV2.builder().bills(bills).requestInfo(requestInfo).build();
producer.push(billCancelTopic, req);

}

/**
* Fetches the bill for given parameters
*
Expand Down Expand Up @@ -428,6 +466,7 @@ private List<BillV2> prepareBill(List<Demand> demands, RequestInfo requestInfo)
.status(BillStatus.ACTIVE)
.billDetails(billDetails)
.totalAmount(billAmount)
.userId(payer.getUuid())
.billNumber(billNumber)
.tenantId(tenantId)
.id(billId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public AggregatedDemandDetailResponse getAllDemands(DemandCriteria demandCriteri
Integer rate = (Integer) paymentMasterData.get("rate");
String penaltyType = String.valueOf(paymentMasterData.get("type"));
totalApplicablePenalty = currentmonthBill.multiply(new BigDecimal(rate).divide(new BigDecimal(100)));
totalApplicablePenalty = totalApplicablePenalty.setScale(0, RoundingMode.CEILING);
totalApplicablePenalty = totalApplicablePenalty.setScale(0, RoundingMode.HALF_UP);
} else {
log.info("MDMS data is Null Penalty not connfigured");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,21 @@ private Constants() {}

public static final String COUNT_REPLACE_CANCEL_BILL_MSG = "{count}";


// Bill cancel

public static final String CANCELLATION_REASON_MSG= "reasonMessage";

public static final String CANCELLATION_REASON_CODE= "reason";

public static final String CANCELL_REASON_MSG_NOT_FOUND = "EG_BS_CANCELL_REASON_MSG_NOT";
public static final String CANCELL_REASON_MSG_NOT_FOUND_MSG = "Cancell Reason message with key " + "'" + CANCELLATION_REASON_MSG + "'" + " is madnatory Text field in additionalDetails of Bill cancell Request";
public static final String CANCELL_REASON_MSG_EMPTY_MSG = "Cancell Reason message cannot be empty";

public static final String CANCELL_REASON_CODE_NOT_FOUND = "EG_BS_CANCELL_REASON_CODE_NOT";
public static final String CANCELL_REASON_CODE_NOT_FOUND_MSG = "Cancellation Reason with key " + "'" + CANCELLATION_REASON_CODE + "'" + " is a madnatory Text field in additionalDetails of Bill cancell Request";
public static final String CANCELL_REASON_CODE_EMPTY_MSG = "Cancell Reason code cannot be empty";

public static final String PENALTY_PATH_CODE = "$.MdmsRes.ws-services-calculation.Penalty";

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package org.egov.demand.web.validator;

import java.util.HashMap;
import java.util.Map;
import static org.egov.demand.util.Constants.BILL_GEN_MANDATORY_FIELDS_MISSING_KEY;
import static org.egov.demand.util.Constants.BILL_GEN_MANDATORY_FIELDS_MISSING_MSG;

import org.egov.common.contract.request.RequestInfo;
import org.egov.demand.model.BillSearchCriteria;
import org.egov.demand.model.BillV2.BillStatus;
import org.egov.demand.model.GenerateBillCriteria;
import org.egov.demand.util.Util;
import org.egov.tracer.model.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.Errors;
import org.egov.demand.model.UpdateBillCriteria;
import org.egov.demand.util.Constants;
import org.springframework.util.StringUtils;

import com.fasterxml.jackson.databind.JsonNode;

@Component
public class BillValidator {
Expand Down Expand Up @@ -57,4 +65,28 @@ public void validateBillSearchCriteria(BillSearchCriteria billCriteria, RequestI
}
}

public void validateBillSearchRequest(UpdateBillCriteria cancelBillCriteria) {
cancelBillCriteria.setStatusToBeUpdated(BillStatus.CANCELLED);
JsonNode additionalDetails = cancelBillCriteria.getAdditionalDetails();
Map<String, String> errorMap = new HashMap<>();
JsonNode reasonMsg = additionalDetails.get(Constants.CANCELLATION_REASON_MSG);
JsonNode reasonCode = additionalDetails.get(Constants.CANCELLATION_REASON_CODE);
if (null != reasonCode && reasonCode.isTextual()) {
if (StringUtils.isEmpty(reasonCode.textValue()))
errorMap.put(Constants.CANCELL_REASON_CODE_NOT_FOUND, Constants.CANCELL_REASON_CODE_EMPTY_MSG);
} else {
errorMap.put(Constants.CANCELL_REASON_CODE_NOT_FOUND, Constants.CANCELL_REASON_CODE_NOT_FOUND_MSG);
}

if (null != reasonMsg && reasonMsg.isTextual()) {
if (StringUtils.isEmpty(reasonMsg.textValue()))
errorMap.put(Constants.CANCELL_REASON_MSG_NOT_FOUND, Constants.CANCELL_REASON_MSG_EMPTY_MSG);
} else {
errorMap.put(Constants.CANCELL_REASON_MSG_NOT_FOUND, Constants.CANCELL_REASON_MSG_NOT_FOUND_MSG);
}
if (!CollectionUtils.isEmpty(errorMap)) {
throw new CustomException(errorMap);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ egov.apportion.endpoint=/apportion-service/v2/demand/_apportion
# billgen notif topic
kafka.topics.billgen.topic.name=billing-billgen-topic-name
bill.notification.fallback.locale=en_IN
kafka.topics.cancel.bill.topic.name=bill-cancel-topic-name

# notif topic
kafka.topics.notification.sms=egov.core.notification.sms
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE egbs_bill_v1 add column payerid character varying (128);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE egbs_bill_v1 ADD COLUMN IF NOT EXISTS consumercode CHARACTER VARYING(256);

UPDATE egbs_bill_v1 b SET consumerCode = bd.consumercode FROM egbs_billdetail_v1 bd WHERE bd.billid = b.id;

ALTER TABLE egbs_bill_v1 ALTER COLUMN consumercode SET NOT NULL;

CREATE UNIQUE INDEX IF NOT EXISTS index_egbs_UNIQUE_ACTIVE_BILL ON egbs_bill_v1 (consumercode, tenantid, status) where status='ACTIVE';
Loading

0 comments on commit 417460b

Please sign in to comment.