This commit is contained in:
Mohd-Arham
2025-12-01 18:45:31 +05:30
parent ff97877997
commit 3e0a04e390
19 changed files with 463 additions and 106 deletions
@@ -1,5 +1,8 @@
package com.billpaymentservice.bbps.util;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -7,6 +10,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import org.modelmapper.ModelMapper;
@@ -32,6 +36,7 @@ import com.billpaymentservice.bbps.dto.PlanDTO;
import com.billpaymentservice.bbps.dto.TicketDetailsDTO;
import com.billpaymentservice.bbps.dto.TicketDispositionsDTO;
import com.billpaymentservice.bbps.dto.TransactionHistoryMasterDTO;
import com.billpaymentservice.bbps.dto.TransactionHistoryParticularDetailsDTO;
import com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest;
import com.billpaymentservice.bbps.dto.request.BillPaymentRequest;
import com.billpaymentservice.bbps.dto.request.ComplaintRequestDTO;
@@ -42,6 +47,7 @@ import com.billpaymentservice.bbps.dto.response.AmountOptionsResponse;
import com.billpaymentservice.bbps.dto.response.BillDataResponse;
import com.billpaymentservice.bbps.dto.response.ClientReqIdResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintResponse;
import com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse;
import com.billpaymentservice.bbps.dto.response.PlanResponse;
import com.billpaymentservice.bbps.dto.response.TicketCheckStatusResponse;
@@ -72,6 +78,7 @@ import com.billpaymentservice.bbps.entites.CheckClientBillerData;
import com.billpaymentservice.bbps.entites.CheckClientStatusReqId;
import com.billpaymentservice.bbps.entites.ComplainStatus;
import com.billpaymentservice.bbps.entites.ComplaintHistory;
import com.billpaymentservice.bbps.entites.ComplaintResponseEntity;
import com.billpaymentservice.bbps.entites.ComplaintStatusDetails;
import com.billpaymentservice.bbps.entites.ContactMasterData;
import com.billpaymentservice.bbps.entites.CustomerParamBill;
@@ -97,6 +104,7 @@ import com.billpaymentservice.bbps.repository.CheckClientBillerDataRepository;
import com.billpaymentservice.bbps.repository.ClientReqIdRepository;
import com.billpaymentservice.bbps.repository.ComplainDetailRepository;
import com.billpaymentservice.bbps.repository.ComplaintHistoryRepository;
import com.billpaymentservice.bbps.repository.ComplaintResponseRepository;
import com.billpaymentservice.bbps.repository.ComplaintStatusRepository;
import com.billpaymentservice.bbps.repository.ContactMasterDataRepository;
import com.billpaymentservice.bbps.repository.CustomerParamGroupByBillerIdRepository;
@@ -130,6 +138,7 @@ public class BillerMapperHelper {
private final BillerDataRepository billerDataRespository;
private final BillMasterRepository billMasterRepository;
private final BillValidationRepository billValidationRepository;
private final ComplaintResponseRepository complaintResponseRepository;
public BillerMapperHelper(BillerCategoryWiseRepository billerRepo,
CustomerParamGroupByBillerIdRepository customerParamGroupByBillerIdRepo,
@@ -145,7 +154,8 @@ public class BillerMapperHelper {
ViewAllComplainTicketDetailRepository viewAllComplainTicketDetailRepository,
ContactMasterDataRepository contactMasterDataRepository, BBPSMasterDataRepo bbpsMasterDataRepo,
BillerDataRepository billerDataRespository, BillMasterRepository billMasterRepository,
BillValidationRepository billValidationRepository) {
BillValidationRepository billValidationRepository,
ComplaintResponseRepository complaintResponseRepository) {
this.billerRepo = billerRepo;
this.customerParamGroupByBillerIdRepo = customerParamGroupByBillerIdRepo;
this.amountOptionByBillerIdRepository = amountOptionByBillerIdRepository;
@@ -165,6 +175,7 @@ public class BillerMapperHelper {
this.billerDataRespository = billerDataRespository;
this.billMasterRepository = billMasterRepository;
this.billValidationRepository = billValidationRepository;
this.complaintResponseRepository = complaintResponseRepository;
}
/**
@@ -1109,4 +1120,95 @@ public class BillerMapperHelper {
return dto;
}
public TransactionHistoryParticularDetailsDTO billerRemainingDetails(TransactionMaster transactionMaster) {
if (transactionMaster == null) {
return null;
}
// Create a new DTO and set the values from the entity
TransactionHistoryParticularDetailsDTO dto = new TransactionHistoryParticularDetailsDTO();
dto.setBankTxnId(transactionMaster.getBankTxnId());
dto.setTxnId(transactionMaster.getTxnId());
dto.setCreationDate(transactionMaster.getCreationDate());
dto.setBillerCategory(transactionMaster.getBillerCategory());
dto.setBillerName(transactionMaster.getBillerName());
dto.setStatus(transactionMaster.getStatus());
dto.setTotalTxnAmount(transactionMaster.getTotalTxnAmount());
return dto;
}
public static boolean isComplaintAllowed(String transactionCreatedDateString) {
// Define the format of the transaction creation date including the time zone
// offset
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
try {
// Parse the transaction creation date string to OffsetDateTime (handles time
// zone)
OffsetDateTime transactionCreatedDate = OffsetDateTime.parse(transactionCreatedDateString, formatter);
// Get the current time (with offset)
OffsetDateTime currentTime = OffsetDateTime.now();
// Calculate the difference in hours
long hoursDifference = ChronoUnit.HOURS.between(transactionCreatedDate, currentTime);
// Return true if complaint can be raised (i.e., within 24 hours)
return hoursDifference >= 24;
} catch (Exception e) {
// Handle invalid date format or other parsing issues
System.err.println("Invalid date format: " + e.getMessage());
return false;
}
}
public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId) {
// 1. Convert ComplaintResponse DTO to ComplaintResponseEntity
ComplaintResponseEntity complaintResponseEntity = new ComplaintResponseEntity();
// Map fields from DTO to entity
complaintResponseEntity.setRefId(responseWrapper.getTicketDetails().getRefId()); // For example, generate a
// unique ID
complaintResponseEntity.setTxnNpciId(responseWrapper.getTicketDetails().getTxnNpciId());
complaintResponseEntity.setTicketId(responseWrapper.getTicketDetails().getTicketId());
complaintResponseEntity.setTicketType(responseWrapper.getTicketDetails().getTicketType());
complaintResponseEntity.setTicketNpciId(responseWrapper.getTicketDetails().getTicketNpciId());
complaintResponseEntity.setTicketDesp(responseWrapper.getTicketDetails().getTicketDesp());
complaintResponseEntity.setTicketDesr(responseWrapper.getTicketDetails().getTicketDesr());
// Additional fields from ComplaintResponse DTO
complaintResponseEntity.setMessage(responseWrapper.getMessage());
complaintResponseEntity.setRemarks(responseWrapper.getRemarks());
complaintResponseEntity.setStatus(responseWrapper.getStatus());
complaintResponseEntity.setStatusCode(responseWrapper.getStatusCode());
// Set requestId and txnId from parameters
complaintResponseEntity.setReqId(requestId);
complaintResponseEntity.setTxnId(txnId);
complaintResponseEntity.setCreateDateTime(new Date());
// If you need a separate complaintTicketId, you can set it here
complaintResponseEntity.setComplaintTicketId(generateComplaintTicketId()); // Generate or set manually
// Save the entity
complaintResponseRepository.save(complaintResponseEntity);
ComplaintResponseEntity savedEntity = complaintResponseRepository.save(complaintResponseEntity);
// Check if the entity is saved successfully and return count (1 for success)
if (savedEntity != null) {
return "1 record saved with RefId: " + savedEntity.toString();
} else {
return "Failed to save complaint response.";
}
}
// Save Complain Response From DB
private String generateComplaintTicketId() {
// Logic for generating complaint ticket ID
return "CMP-" + UUID.randomUUID().toString();
}
}