diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java index ebf7d78cc..ba15e73ef 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java @@ -4,26 +4,19 @@ import java.math.BigInteger; import java.math.RoundingMode; import java.sql.Timestamp; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.Month; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.time.format.TextStyle; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; import java.util.Collections; import java.util.Comparator; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; @@ -31,14 +24,13 @@ import java.util.stream.Collectors; import javax.validation.Valid; -import io.swagger.models.auth.In; + import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.egov.common.contract.request.RequestInfo; import org.egov.common.contract.request.User; import org.egov.mdms.model.MasterDetail; import org.egov.mdms.model.MdmsCriteria; -import org.egov.mdms.model.MdmsCriteriaReq; import org.egov.mdms.model.ModuleDetail; import org.egov.tracer.model.CustomException; import org.egov.wscalculation.config.WSCalculationConfiguration; @@ -296,21 +288,22 @@ private List createDemand(RequestInfo requestInfo, List cal if (!isWSUpdateSMS) { - List billNumbers = fetchBill(demands, waterConnectionRequest.getRequestInfo()); - Long billDate = fetchBillDate(demands,waterConnectionRequest.getRequestInfo()); - billDate =billDate + 1296000000l; - LocalDate billDateLocal = Instant.ofEpochMilli(billDate).atZone(ZoneId.systemDefault()).toLocalDate(); - String paymentDueDate = billDateLocal.format(dateTimeFormatter); - if(isOnlinePaymentAllowed(requestInfo,tenantId)) { - if(fetchTotalBillAmount(demands,requestInfo).signum()> 0) { - sendPaymentSMSNotification(requestInfo,tenantId,owner,waterConnectionRequest,property,demandDetails,consumerCode,demands,isForConnectionNO,businessService,billCycle,billNumbers,paymentDueDate); - //sendPaymentAndBillSMSNotification(requestInfo,tenantId,owner,waterConnectionRequest,property,demandDetails,consumerCode,demands,isForConnectionNO,businessService,billCycle,billNumbers,paymentDueDate); + List bills = fetchBill(demands, waterConnectionRequest.getRequestInfo()); + if (!CollectionUtils.isEmpty(bills)) { + String billNumber = bills.get(0).getBillNumber(); + Long billDate = bills.get(0).getBillDate(); + billDate = billDate + 1296000000l; + LocalDate billDateLocal = Instant.ofEpochMilli(billDate).atZone(ZoneId.systemDefault()).toLocalDate(); + String paymentDueDate = billDateLocal.format(dateTimeFormatter); + BigDecimal totalAmount=bills.get(0).getTotalAmount(); + if (ObjectUtils.isEmpty(totalAmount) && totalAmount.signum() > 0) { + if (isOnlinePaymentAllowed(requestInfo, tenantId)) { + sendPaymentSMSNotification(requestInfo, tenantId, owner, waterConnectionRequest, property, demandDetails, consumerCode, demands, isForConnectionNO, businessService, billCycle, billNumber, paymentDueDate,totalAmount); + //sendPaymentAndBillSMSNotification(requestInfo,tenantId,owner,waterConnectionRequest,property,demandDetails,consumerCode,demands,isForConnectionNO,businessService,billCycle,billNumbers,paymentDueDate,totalAmount); + } + sendDownloadBillSMSNotification(requestInfo, tenantId, owner, waterConnectionRequest, property, demandDetails, consumerCode, demands, isForConnectionNO, businessService, billCycle, billNumber, paymentDueDate, totalAmount); } } - BigDecimal totalAmount=fetchTotalBillAmount(demands,requestInfo); - //log.info("Total Amount from fetch Bill"+String.valueOf(totalAmount)); - if(totalAmount!=null && totalAmount.signum()> 0) - sendDownloadBillSMSNotification(requestInfo,tenantId,owner,waterConnectionRequest,property,demandDetails,consumerCode,demands,isForConnectionNO,businessService,billCycle,billNumbers,paymentDueDate,totalAmount); } } @@ -318,7 +311,9 @@ private List createDemand(RequestInfo requestInfo, List cal return finalDemandRes; } - private void sendPaymentSMSNotification(RequestInfo requestInfo, String tenantId, User owner, WaterConnectionRequest waterConnectionRequest, Property property, List demandDetails, String consumerCode, List demands, Boolean isForConnectionNO, String businessService, String billCycle, List billNumbers, String paymentDueDate ) { + private void sendPaymentSMSNotification(RequestInfo requestInfo, String tenantId, User owner, WaterConnectionRequest waterConnectionRequest, + Property property, List demandDetails, String consumerCode, List demands, Boolean isForConnectionNO, + String businessService, String billCycle, String billNumber, String paymentDueDate,BigDecimal totalAmount ) { HashMap localizationMessage = util.getLocalizationMessage(requestInfo, WSCalculationConstant.mGram_Consumer_Payment, tenantId); String connectionType = null; @@ -335,7 +330,6 @@ private void sendPaymentSMSNotification(RequestInfo requestInfo, String tenantId String messageString = localizationMessage.get(WSCalculationConstant.MSG_KEY); - BigDecimal totalAmount = fetchTotalBillAmount(demands,requestInfo); if (!StringUtils.isEmpty(messageString) && isForConnectionNO) { messageString = messageString.replace("{ownername}", owner.getName()); @@ -352,7 +346,7 @@ private void sendPaymentSMSNotification(RequestInfo requestInfo, String tenantId } } } - private void sendDownloadBillSMSNotification(RequestInfo requestInfo, String tenantId, User owner, WaterConnectionRequest waterConnectionRequest, Property property, List demandDetails, String consumerCode, List demands, Boolean isForConnectionNO, String businessService, String billCycle,List billNumbers, String paymentDueDate,BigDecimal totalamount) { + private void sendDownloadBillSMSNotification(RequestInfo requestInfo, String tenantId, User owner, WaterConnectionRequest waterConnectionRequest, Property property, List demandDetails, String consumerCode, List demands, Boolean isForConnectionNO, String businessService, String billCycle,String billNumber, String paymentDueDate,BigDecimal totalamount) { HashMap localizationMessage = util.getLocalizationMessage(requestInfo, WSCalculationConstant.mGram_Consumer_NewBill, tenantId); String actionLink = config.getNotificationUrl() @@ -371,8 +365,8 @@ private void sendDownloadBillSMSNotification(RequestInfo requestInfo, String ten //System.out.println("Localization message get bill::" + messageString); //System.out.println("isForConnectionNO:" + isForConnectionNO); if (!StringUtils.isEmpty(messageString) && isForConnectionNO) { - if (totalamount!=null && billNumbers.size() > 0 && totalamount.signum()>0) { - actionLink = actionLink.replace("$billNumber", billNumbers.get(0)); + if (totalamount!=null && totalamount.signum()>0) { + actionLink = actionLink.replace("$billNumber", billNumber); messageString = messageString.replace("{ownername}", owner.getName()); messageString = messageString.replace("{Period}", billCycle); messageString = messageString.replace("{consumerno}", consumerCode); @@ -970,7 +964,7 @@ private List updateDemandForCalculation(RequestInfo requestInfo, List billNumbers = fetchBill(demands, waterConnectionRequest.getRequestInfo()); + List bills = fetchBill(demands, waterConnectionRequest.getRequestInfo()); // Long billDate = fetchBillDate(demands,waterConnectionRequest.getRequestInfo()); // billDate =billDate + 1296000000l; // LocalDate billDateLocal = Instant.ofEpochMilli(billDate).atZone(ZoneId.systemDefault()).toLocalDate(); @@ -1290,26 +1284,31 @@ private boolean isCurrentDateIsMatching(String billingFrequency, long dayOfMonth return true; } - public List fetchBill(List demandResponse, RequestInfo requestInfo) { - boolean notificationSent = false; - List billNumber = new ArrayList<>(); + public List fetchBill(List demandResponse, RequestInfo requestInfo) { + boolean notificationSent = false; new ArrayList<>(); + List bills =null; for (Demand demand : demandResponse) { try { Object result = serviceRequestRepository.fetchResult( calculatorUtils.getFetchBillURL(demand.getTenantId(), demand.getConsumerCode()), RequestInfoWrapper.builder().requestInfo(requestInfo).build()); - billNumber = JsonPath.read(result, "$.Bill.*.billNumber"); + //billNumber = JsonPath.read(result, "$.Bill.*.billNumber"); HashMap billResponse = new HashMap<>(); billResponse.put("requestInfo", requestInfo); billResponse.put("billResponse", result); + try { + bills = mapper.convertValue(result, BillResponseV2.class).getBill(); + } catch (IllegalArgumentException e) { + throw new CustomException("PARSING_ERROR", "Failed to parse response from Demand Search"); + } wsCalculationProducer.push(configs.getPayTriggers(), billResponse); notificationSent = true; } catch (Exception ex) { log.error("Fetch Bill Error", ex); } } - return billNumber; + return bills; } public Long fetchBillDate(List demandResponse, RequestInfo requestInfo) { diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillDetailV2.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillDetailV2.java new file mode 100644 index 000000000..db5e6e44f --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillDetailV2.java @@ -0,0 +1,4 @@ +package org.egov.wscalculation.web.models; + +public class BillDetailV2 { +} diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillResponseV2.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillResponseV2.java new file mode 100644 index 000000000..5cdc5df17 --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillResponseV2.java @@ -0,0 +1,30 @@ +package org.egov.wscalculation.web.models; + +import java.util.ArrayList; +import java.util.List; +import org.egov.common.contract.response.ResponseInfo; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * BillResponse + */ + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BillResponseV2 { + + @JsonProperty("ResposneInfo") + private ResponseInfo resposneInfo = null; + + @JsonProperty("Bill") + private List bill = new ArrayList<>(); + +} diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillV2.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillV2.java new file mode 100644 index 000000000..e24fc7ca8 --- /dev/null +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/BillV2.java @@ -0,0 +1,136 @@ +package org.egov.wscalculation.web.models; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import javax.validation.Valid; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.databind.JsonNode; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BillV2 { + + @JsonProperty("id") + @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; + + @JsonProperty("payerName") + @Size(max = 256) + private String payerName; + + @JsonProperty("payerAddress") + @Size(max = 1024) + private String payerAddress; + + @JsonProperty("payerEmail") + @Size(max = 256) + private String payerEmail; + + @JsonProperty("status") + private BillStatus status; + + @JsonProperty("totalAmount") + private BigDecimal totalAmount; + + @JsonProperty("businessService") + @Size(max = 256) + private String businessService; + + @JsonProperty("billNumber") + @Size(max = 256) + private String billNumber; + + @JsonProperty("billDate") + private Long billDate; + + @JsonProperty("consumerCode") + @Size(max = 256) + private String consumerCode; + + @JsonProperty("additionalDetails") + private JsonNode additionalDetails; + + @JsonProperty("billDetails") + @Valid + private List billDetails; + + @JsonProperty("tenantId") + @Size(max = 256) + private String tenantId; + + @JsonProperty("fileStoreId") + private String fileStoreId; + + @JsonProperty("auditDetails") + private AuditDetails auditDetails; + + /** + * status of the bill . + */ + public enum BillStatus { + + ACTIVE("ACTIVE"), + + CANCELLED("CANCELLED"), + + PAID("PAID"), + + PARTIALLY_PAID("PARTIALLY_PAID"), + + PAYMENT_CANCELLED("PAYMENT_CANCELLED"), + + EXPIRED("EXPIRED"); + + private String value; + + BillStatus(String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static BillStatus fromValue(String text) { + for (BillStatus b : BillStatus.values()) { + if (String.valueOf(b.value).equalsIgnoreCase(text)) { + return b; + } + } + return null; + } + } + + public BillV2 addBillDetailsItem(BillDetailV2 billDetailsItem) { + if (this.billDetails == null) { + this.billDetails = new ArrayList<>(); + } + this.billDetails.add(billDetailsItem); + return this; + } +} +