added seprate auditable in entity
This commit is contained in:
@@ -214,7 +214,6 @@ public class BillerMapperHelper {
|
||||
biller.setPlanMDMRequirement(dto.getPlanMDMRequirement());
|
||||
biller.setAdhocBiller(dto.getAdhocBiller());
|
||||
biller.setPaymentAmountExactness(dto.getPaymentAmountExactness());
|
||||
biller.setCreateDateTime(new Date());
|
||||
biller.setRequestId(requestId);
|
||||
biller.setTxnId(txnId);
|
||||
biller.setUserId(userId);
|
||||
@@ -279,7 +278,6 @@ public class BillerMapperHelper {
|
||||
groupEntity.setRequestId(requestId);
|
||||
groupEntity.setTxnId(txnId);
|
||||
groupEntity.setUserId(userId);
|
||||
groupEntity.setCreateDateTime(new Date());
|
||||
// Save group parameters (if any)
|
||||
if (groupDTO.getParams() != null && !groupDTO.getParams().isEmpty()) {
|
||||
List<GroupParam> groupParams = new ArrayList<>();
|
||||
@@ -367,7 +365,6 @@ public class BillerMapperHelper {
|
||||
List<AmountOptionDetails> amountOptionDetailsList = mapAmountOptionDTOToEntity(
|
||||
responseWrapper.getAmountOptionDAOS(), requestId, txnId, userId);
|
||||
entity.setAmountOptionDetails(amountOptionDetailsList);
|
||||
entity.setCreateDateTime(new Date());
|
||||
|
||||
amountOptionByBillerIdRepository.save(entity); // Saves the entity and cascades to AmountOptionDetails
|
||||
|
||||
@@ -416,7 +413,6 @@ public class BillerMapperHelper {
|
||||
response.setTotalPages(planResponse.getTotalPages());
|
||||
response.setTxnId(txnId);
|
||||
response.setUserId(userId);
|
||||
response.setCreateDateTime(new Date());
|
||||
|
||||
PlansList plansList = new PlansList();
|
||||
List<Plan> planEntities = new ArrayList<>();
|
||||
@@ -489,7 +485,6 @@ public class BillerMapperHelper {
|
||||
category.setCategoryRespList(item);
|
||||
category.setRequestId(txnId);
|
||||
category.setRequestId(requestId);
|
||||
category.setCreateDateTime(new Date());
|
||||
category.setUserId(userId);
|
||||
categoryResponseListRepository.save(category);
|
||||
savedCount++;
|
||||
@@ -536,7 +531,6 @@ public class BillerMapperHelper {
|
||||
entity.setNpciTicketType(dto.getNpciTicketType());
|
||||
entity.setNpciTicketStatus(dto.getNpciTicketStatus());
|
||||
entity.setCreatedTime(dto.getCreatedTime());
|
||||
entity.setCreateDateTime(new Date());
|
||||
entity.setUserId(userId);
|
||||
|
||||
try {
|
||||
@@ -567,7 +561,6 @@ public class BillerMapperHelper {
|
||||
entity.setHistoryStatus(dto.getHistoryStatus());
|
||||
entity.setReqId(reqId);
|
||||
entity.setTxnId(txnId);
|
||||
entity.setCreateDateTime(new Date());
|
||||
entity.setUserId(userId);
|
||||
|
||||
complaintHistoryRepository.save(entity);
|
||||
@@ -683,7 +676,6 @@ public class BillerMapperHelper {
|
||||
entity.setTotalElements(String.valueOf(responseWrapper.getTotalElements()));
|
||||
entity.setPage(String.valueOf(responseWrapper.getPage()));
|
||||
entity.setPageSize(String.valueOf(responseWrapper.getPageSize()));
|
||||
entity.setCreateDateTime(new Date());
|
||||
entity.setUserId(userId);
|
||||
|
||||
}
|
||||
@@ -726,8 +718,11 @@ public class BillerMapperHelper {
|
||||
parent.setStatus(responseWrapper.getStatus());
|
||||
parent.setActionType(responseWrapper.getActionType());
|
||||
parent.setUserId(responseWrapper.getUserId());
|
||||
parent.setCreationDate(responseWrapper.getCreationDate());
|
||||
parent.setModifiedDate(responseWrapper.getModifiedDate());
|
||||
// Map incoming DTO date strings into Auditable LocalDateTime fields
|
||||
LocalDateTime parentCreatedOn = parseToLocalDateTime(responseWrapper.getCreationDate());
|
||||
if (parentCreatedOn != null) parent.setCreatedOn(parentCreatedOn);
|
||||
LocalDateTime parentUpdatedOn = parseToLocalDateTime(responseWrapper.getModifiedDate());
|
||||
if (parentUpdatedOn != null) parent.setUpdatedOn(parentUpdatedOn);
|
||||
parent.setCreatedEpochDate(responseWrapper.getCreatedEpochDate());
|
||||
parent.setModifiedEpochDate(responseWrapper.getModifiedEpochDate());
|
||||
parent.setReqId(reqId);
|
||||
@@ -828,7 +823,6 @@ public class BillerMapperHelper {
|
||||
entity.setDispositionCode(dto.getDispositionCode());
|
||||
|
||||
// Set current datetime
|
||||
entity.setCreateDateTime(new Date());
|
||||
entity.setTxnId(txnId);
|
||||
entity.setReqId(requestId);
|
||||
entity.setUserId(userId);
|
||||
@@ -862,7 +856,6 @@ public class BillerMapperHelper {
|
||||
entity.setPageSize(String.valueOf(responseWrapper.getPageSize()));
|
||||
entity.setTotalPages(String.valueOf(responseWrapper.getTotalPages()));
|
||||
entity.setTotalElements(String.valueOf(responseWrapper.getTotalElements()));
|
||||
entity.setCreateDateTime(new Date());
|
||||
entity.setUserId(userId);
|
||||
|
||||
}
|
||||
@@ -887,7 +880,6 @@ public class BillerMapperHelper {
|
||||
entity.setReqId(requestId);
|
||||
entity.setTxnId(txnID);
|
||||
entity.setUserId(userId);
|
||||
entity.setCreateDateTime(new Date());
|
||||
return entity;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
@@ -926,7 +918,7 @@ public class BillerMapperHelper {
|
||||
billMaster.setUserId(userId);
|
||||
billMaster.setClientUserId(billFetchByBillIdRequest.getClientUserId());
|
||||
|
||||
// BILLER RESPONSE
|
||||
// BILLER RESPONSE
|
||||
BillerResponse billerResponse = new BillerResponse();
|
||||
if (responseWrapper.getBillerResponse() != null) {
|
||||
billerResponse.setBillId(responseWrapper.getBillerResponse().getBillId());
|
||||
@@ -943,7 +935,7 @@ public class BillerMapperHelper {
|
||||
}
|
||||
billMaster.setBillerResponse(billerResponse);
|
||||
|
||||
// ADDITIONAL INFO
|
||||
// ADDITIONAL INFO
|
||||
List<AdditionalInfoBill> additionalInfos = new ArrayList<>();
|
||||
if (responseWrapper.getAdditionalInfo() != null) {
|
||||
for (AdditionalInfoBillDTO info : responseWrapper.getAdditionalInfo()) {
|
||||
@@ -956,7 +948,7 @@ public class BillerMapperHelper {
|
||||
}
|
||||
billMaster.setAdditionalInfo(additionalInfos);
|
||||
|
||||
// CUSTOMER PARAMS
|
||||
// CUSTOMER PARAMS
|
||||
List<CustomerParamBill> customerParams = new ArrayList<>();
|
||||
if (responseWrapper.getCustomerParams() != null) {
|
||||
for (CustomerParamDAO param : responseWrapper.getCustomerParams()) {
|
||||
@@ -970,170 +962,45 @@ public class BillerMapperHelper {
|
||||
}
|
||||
billMaster.setCustomerParams(customerParams);
|
||||
|
||||
// DATES
|
||||
billMaster.setCreationDate(responseWrapper.getCreationDate());
|
||||
billMaster.setModifiedDate(responseWrapper.getModifiedDate());
|
||||
// DATES
|
||||
// Map incoming DTO date strings into Auditable LocalDateTime fields
|
||||
LocalDateTime bmCreatedOn = parseToLocalDateTime(responseWrapper.getCreationDate());
|
||||
if (bmCreatedOn != null) {
|
||||
billMaster.setCreatedOn(bmCreatedOn);
|
||||
}
|
||||
LocalDateTime bmUpdatedOn = parseToLocalDateTime(responseWrapper.getModifiedDate());
|
||||
if (bmUpdatedOn != null) {
|
||||
billMaster.setUpdatedOn(bmUpdatedOn);
|
||||
}
|
||||
billMaster.setCreatedEpochDate(responseWrapper.getCreatedEpochDate());
|
||||
billMaster.setModifiedEpochDate(responseWrapper.getModifiedEpochDate());
|
||||
|
||||
billMasterRepository.save(billMaster);
|
||||
}
|
||||
|
||||
public void saveBillValidation(FetchBillValidateResponse responseWrapper, BillFetchByBillIdRequest billRequest,
|
||||
String txnId) {
|
||||
System.out.println("responseWrapper");
|
||||
ModelMapper modelMapper = new ModelMapper();
|
||||
|
||||
try {
|
||||
LOGGER.info("Saving bill validation data for billId={}", responseWrapper.getBillId());
|
||||
|
||||
// ✅ Map the main object
|
||||
BillValidation billEntity = modelMapper.map(responseWrapper, BillValidation.class);
|
||||
// ✅ Manually handle only the nested relationship part
|
||||
if (responseWrapper.getCustomerParams() != null) {
|
||||
List<CustomerParamBillValidation> customerParams = responseWrapper.getCustomerParams().stream()
|
||||
.map(param -> {
|
||||
CustomerParamBillValidation cp = modelMapper.map(param, CustomerParamBillValidation.class);
|
||||
cp.setBill(billEntity); // maintain relation
|
||||
return cp;
|
||||
}).collect(Collectors.toList());
|
||||
billEntity.setCustomerParams(customerParams);
|
||||
}
|
||||
if (responseWrapper.getAdditionalInfo() != null) {
|
||||
List<AdditionalInfoBillValidate> additionalInfos = responseWrapper.getAdditionalInfo().stream()
|
||||
.map(info -> {
|
||||
AdditionalInfoBillValidate ai = modelMapper.map(info, AdditionalInfoBillValidate.class);
|
||||
ai.setBill(billEntity); // maintain relation
|
||||
return ai;
|
||||
}).collect(Collectors.toList());
|
||||
billEntity.setAdditionalInfo(additionalInfos);
|
||||
billEntity.setClientUserId(billRequest.getClientUserId());
|
||||
billEntity.setTxnId(txnId);
|
||||
billEntity.setRefId(billRequest.getReqId());
|
||||
|
||||
}
|
||||
// ✅ Save everything (cascade handles child)
|
||||
|
||||
billValidationRepository.save(billEntity);
|
||||
|
||||
LOGGER.info("Bill validation saved successfully for billId={}", billEntity.getBillId());
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Error saving BillValidation data: {}", ex.getMessage(), ex);
|
||||
throw new RuntimeException("Failed to save bill validation data", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public FetchBillForwardRequest fetchBillForwardRequestMap(FetchBillRequest req) {
|
||||
|
||||
FetchBillForwardRequest forward = new FetchBillForwardRequest();
|
||||
|
||||
forward.setBillerId(req.getBillerId());
|
||||
forward.setBillerName(req.getBillerName());
|
||||
forward.setBillerCategory(req.getBillerCategory());
|
||||
forward.setClientReqId(req.getClientReqId());
|
||||
forward.setMacAdress(req.getMacAdress());
|
||||
forward.setCustomerMobNo(req.getCustomerMobNo());
|
||||
forward.setRemitterName(req.getRemitterName());
|
||||
forward.setPaymentChannel(req.getPaymentChannel());
|
||||
forward.setDeviceBlockTags(req.getDeviceBlockTags());
|
||||
forward.setCustomerParamsRequest(req.getCustomerParamsRequest());
|
||||
forward.setRemitterIdentity(req.getRemitterIdentity());
|
||||
|
||||
return forward;
|
||||
}
|
||||
|
||||
public FetchBillValidatestForwardRequest fetchBillValidatestForwardRequest(FetchBillValidatestRequest req) {
|
||||
|
||||
FetchBillValidatestForwardRequest forward = new FetchBillValidatestForwardRequest();
|
||||
|
||||
forward.setBillerId(req.getBillerId());
|
||||
forward.setBillerName(req.getBillerName());
|
||||
forward.setBillerCategory(req.getBillerCategory());
|
||||
forward.setCustomerMobNo(req.getCustomerMobNo());
|
||||
forward.setClientReqId(req.getClientReqId());
|
||||
forward.setMacAddress(req.getMacAddress());
|
||||
forward.setCustomerParamsRequest(req.getCustomerParamsRequest());
|
||||
|
||||
return forward;
|
||||
}
|
||||
|
||||
public BillPaymentForwardRequest billPaymentForwardRequest(BillPaymentRequest req) {
|
||||
|
||||
BillPaymentForwardRequest forward = new BillPaymentForwardRequest();
|
||||
|
||||
// forward.setTenantId(req.getTenantId());
|
||||
forward.setRefId(req.getRefId());
|
||||
forward.setBillId(req.getBillId());
|
||||
forward.setAmountOptions(req.isAmountOptions());
|
||||
forward.setPaymentMode(req.getPaymentMode());
|
||||
forward.setPaymentInformation(req.getPaymentInformation());
|
||||
forward.setBillerId(req.getBillerId());
|
||||
forward.setBillerName(req.getBillerName());
|
||||
forward.setBillerCategory(req.getBillerCategory());
|
||||
forward.setMacAdress(req.getMacAdress());
|
||||
forward.setCustomerMobNo(req.getCustomerMobNo());
|
||||
forward.setTxnAmount(req.getTxnAmount());
|
||||
forward.setPaymentRefId(req.getPaymentRefId());
|
||||
forward.setClientReqId(req.getClientReqId());
|
||||
forward.setPaymentChannel(req.getPaymentChannel());
|
||||
|
||||
forward.setDeviceBlockTags(req.getDeviceBlockTags());
|
||||
forward.setCustomerParamsRequest(req.getCustomerParams());
|
||||
forward.setRemitterIdentity(req.getRemitterIdentity());
|
||||
forward.setAmountBreakSet(req.getAmountBreakSet());
|
||||
|
||||
return forward;
|
||||
}
|
||||
|
||||
public FetchComplaintForwardRequest fetchComplaintForwardRequestMap(ComplaintRequestDTO complainRequestDTO) {
|
||||
FetchComplaintForwardRequest forward = new FetchComplaintForwardRequest();
|
||||
forward.setTicketDescription(complainRequestDTO.getTicketDescription());
|
||||
forward.setTicketDisposition(complainRequestDTO.getTicketDisposition());
|
||||
forward.setTicketDispositionCode(complainRequestDTO.getTicketDispositionCode());
|
||||
forward.setTxnId(complainRequestDTO.getTxnId());
|
||||
return forward;
|
||||
}
|
||||
|
||||
public FetchTicketLatestStatusRequest fetchTicketLatestStatusRequestMap(GetTicketLatestStausRequest request) {
|
||||
FetchTicketLatestStatusRequest forward = new FetchTicketLatestStatusRequest();
|
||||
forward.setTicketId(request.getTicketId());
|
||||
forward.setTxnNpciId(request.getTxnNpciId());
|
||||
return forward;
|
||||
}
|
||||
|
||||
public void savePaymentStartRecord(PaymentStartUserRequest request, PaymentStartApiResponse apiResponse,
|
||||
String txnId, String orderNo, String requestJson, String rawResponse, String responseType) {
|
||||
PaymentStartRecord record = new PaymentStartRecord();
|
||||
record.setOrderNo(orderNo);
|
||||
record.setRequestId(request.getReqId());
|
||||
record.setClientMid(request.getMid());
|
||||
record.setClientUserId(request.getClientUserId());
|
||||
record.setInternalTxnId(txnId);
|
||||
|
||||
|
||||
record.setAmount(Optional.ofNullable(apiResponse.getResponseData().getAmount()).orElse("0.00"));
|
||||
record.setMid(Optional.ofNullable(apiResponse.getResponseData().getMid()).orElse("DUMMY_MID"));
|
||||
record.setTxnId(Optional.ofNullable(apiResponse.getResponseData().getTxnId()).orElse("DUMMY_TXN"));
|
||||
record.setQrString(Optional.ofNullable(apiResponse.getResponseData().getQrString()).orElse("NO_QR"));
|
||||
record.setCreatedOn(Optional.ofNullable(apiResponse.getResponseData().getCreatedOn()).orElse(LocalDateTime.now().toString()));
|
||||
record.setTxnStatus("PENDING");
|
||||
|
||||
|
||||
// store the original request body and raw response
|
||||
record.setRequestBody(requestJson);
|
||||
record.setResponseBody(rawResponse);
|
||||
record.setResponseType(responseType);
|
||||
|
||||
paymentStartRecordRepository.save(record);
|
||||
}
|
||||
|
||||
public TransactionHistoryMasterDTO toDTO(TransactionMaster transactionMaster) {
|
||||
if (transactionMaster == null) {
|
||||
// Helper to parse incoming ISO date/time strings (with optional offset) into LocalDateTime
|
||||
private LocalDateTime parseToLocalDateTime(String dateStr) {
|
||||
if (dateStr == null || dateStr.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// Try parsing with offset first (e.g., 2023-04-19T17:28:05.508679Z or with +05:30)
|
||||
OffsetDateTime odt = OffsetDateTime.parse(dateStr);
|
||||
return odt.toLocalDateTime();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
// Fallback to LocalDateTime without offset
|
||||
return LocalDateTime.parse(dateStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.warn("Unable to parse date string to LocalDateTime: {}", dateStr);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new DTO and set the values from the entity
|
||||
// Convert TransactionMaster to master DTO
|
||||
public TransactionHistoryMasterDTO toDTO(TransactionMaster transactionMaster) {
|
||||
if (transactionMaster == null) return null;
|
||||
TransactionHistoryMasterDTO dto = new TransactionHistoryMasterDTO();
|
||||
dto.setBankTxnId(transactionMaster.getBankTxnId());
|
||||
dto.setTxnId(transactionMaster.getTxnId());
|
||||
@@ -1174,16 +1041,12 @@ record.setTxnStatus("PENDING");
|
||||
dto.setModifiedDate(transactionMaster.getModifiedDate());
|
||||
dto.setCreatedEpochDate(transactionMaster.getCreatedEpochDate());
|
||||
dto.setModifiedEpochDate(transactionMaster.getModifiedEpochDate());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
// Convert TransactionMaster to particular details DTO (used with method references)
|
||||
public TransactionHistoryParticularDetailsDTO billerRemainingDetails(TransactionMaster transactionMaster) {
|
||||
if (transactionMaster == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create a new DTO and set the values from the entity
|
||||
if (transactionMaster == null) return null;
|
||||
TransactionHistoryParticularDetailsDTO dto = new TransactionHistoryParticularDetailsDTO();
|
||||
dto.setBankTxnId(transactionMaster.getBankTxnId());
|
||||
dto.setTxnId(transactionMaster.getTxnId());
|
||||
@@ -1192,45 +1055,110 @@ record.setTxnStatus("PENDING");
|
||||
dto.setBillerName(transactionMaster.getBillerName());
|
||||
dto.setStatus(transactionMaster.getStatus());
|
||||
dto.setTotalTxnAmount(transactionMaster.getTotalTxnAmount());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
// Map BillPaymentRequest to forward request used by external BBPS API
|
||||
public BillPaymentForwardRequest billPaymentForwardRequest(BillPaymentRequest req) {
|
||||
BillPaymentForwardRequest forward = new BillPaymentForwardRequest();
|
||||
forward.setRefId(req.getRefId());
|
||||
forward.setBillId(req.getBillId());
|
||||
forward.setAmountOptions(req.isAmountOptions());
|
||||
forward.setPaymentMode(req.getPaymentMode());
|
||||
forward.setPaymentInformation(req.getPaymentInformation());
|
||||
forward.setBillerId(req.getBillerId());
|
||||
forward.setBillerName(req.getBillerName());
|
||||
forward.setBillerCategory(req.getBillerCategory());
|
||||
forward.setMacAdress(req.getMacAdress());
|
||||
forward.setCustomerMobNo(req.getCustomerMobNo());
|
||||
forward.setTxnAmount(req.getTxnAmount());
|
||||
forward.setPaymentRefId(req.getPaymentRefId());
|
||||
forward.setClientReqId(req.getClientReqId());
|
||||
forward.setPaymentChannel(req.getPaymentChannel());
|
||||
forward.setDeviceBlockTags(req.getDeviceBlockTags());
|
||||
forward.setCustomerParamsRequest(req.getCustomerParams());
|
||||
forward.setRemitterIdentity(req.getRemitterIdentity());
|
||||
forward.setAmountBreakSet(req.getAmountBreakSet());
|
||||
return forward;
|
||||
}
|
||||
|
||||
// Map PaymentStartUserRequest + API response into PaymentStartRecord and persist
|
||||
public void savePaymentStartRecord(PaymentStartUserRequest request, PaymentStartApiResponse apiResponse,
|
||||
String txnId, String orderNo, String requestJson, String rawResponse, String responseType) {
|
||||
PaymentStartRecord record = new PaymentStartRecord();
|
||||
record.setOrderNo(orderNo);
|
||||
record.setRequestId(request.getReqId());
|
||||
record.setClientMid(request.getMid());
|
||||
record.setClientUserId(request.getClientUserId());
|
||||
record.setInternalTxnId(txnId);
|
||||
|
||||
if (apiResponse != null && apiResponse.getResponseData() != null) {
|
||||
record.setAmount(Optional.ofNullable(apiResponse.getResponseData().getAmount()).orElse("0.00"));
|
||||
record.setMid(Optional.ofNullable(apiResponse.getResponseData().getMid()).orElse("DUMMY_MID"));
|
||||
record.setTxnId(Optional.ofNullable(apiResponse.getResponseData().getTxnId()).orElse("DUMMY_TXN"));
|
||||
record.setQrString(Optional.ofNullable(apiResponse.getResponseData().getQrString()).orElse("NO_QR"));
|
||||
// parse createdOn string into LocalDateTime and set on Auditable
|
||||
LocalDateTime createdOn = parseToLocalDateTime(apiResponse.getResponseData().getCreatedOn());
|
||||
if (createdOn == null) createdOn = LocalDateTime.now();
|
||||
record.setCreatedOn(createdOn);
|
||||
// default status pending
|
||||
record.setTxnStatus("PENDING");
|
||||
} else {
|
||||
record.setAmount("0.00");
|
||||
record.setMid(request.getMid());
|
||||
record.setTxnStatus("PENDING");
|
||||
record.setCreatedOn(LocalDateTime.now());
|
||||
}
|
||||
|
||||
// store the original request body and raw response
|
||||
record.setRequestBody(requestJson);
|
||||
record.setResponseBody(rawResponse);
|
||||
record.setResponseType(responseType);
|
||||
|
||||
paymentStartRecordRepository.save(record);
|
||||
}
|
||||
|
||||
// Map ComplaintRequestDTO to forward request for complaint API
|
||||
public FetchComplaintForwardRequest fetchComplaintForwardRequestMap(ComplaintRequestDTO complainRequestDTO) {
|
||||
FetchComplaintForwardRequest forward = new FetchComplaintForwardRequest();
|
||||
forward.setTicketDescription(complainRequestDTO.getTicketDescription());
|
||||
forward.setTicketDisposition(complainRequestDTO.getTicketDisposition());
|
||||
forward.setTicketDispositionCode(complainRequestDTO.getTicketDispositionCode());
|
||||
forward.setTxnId(complainRequestDTO.getTxnId());
|
||||
return forward;
|
||||
}
|
||||
|
||||
// Map GetTicketLatestStausRequest to forward request
|
||||
public FetchTicketLatestStatusRequest fetchTicketLatestStatusRequestMap(GetTicketLatestStausRequest request) {
|
||||
FetchTicketLatestStatusRequest forward = new FetchTicketLatestStatusRequest();
|
||||
forward.setTicketId(request.getTicketId());
|
||||
forward.setTxnNpciId(request.getTxnNpciId());
|
||||
return forward;
|
||||
}
|
||||
|
||||
// Check if complaint can be raised (true if within 24 hours of transactionCreatedDateString)
|
||||
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");
|
||||
|
||||
if (transactionCreatedDateString == null || transactionCreatedDateString.isBlank()) return false;
|
||||
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 transactionCreatedDate = OffsetDateTime.parse(transactionCreatedDateString);
|
||||
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;
|
||||
|
||||
// complaint allowed if 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());
|
||||
LOGGER.warn("isComplaintAllowed - invalid date string: {}", transactionCreatedDateString);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Persist complaint response entity
|
||||
public String saveComplaintResponseEntity(ComplaintResponse responseWrapper, String requestId, String txnId,
|
||||
String userId) {
|
||||
|
||||
// 1. Convert ComplaintResponse DTO to ComplaintResponseEntity
|
||||
if (responseWrapper == null || responseWrapper.getTicketDetails() == null) {
|
||||
return "No data";
|
||||
}
|
||||
ComplaintResponseEntity complaintResponseEntity = new ComplaintResponseEntity();
|
||||
|
||||
// Map fields from DTO to entity
|
||||
complaintResponseEntity.setRefId(responseWrapper.getTicketDetails().getRefId()); // For example, generate a
|
||||
// unique ID
|
||||
complaintResponseEntity.setRefId(responseWrapper.getTicketDetails().getRefId());
|
||||
complaintResponseEntity.setTxnNpciId(responseWrapper.getTicketDetails().getTxnNpciId());
|
||||
complaintResponseEntity.setTicketId(responseWrapper.getTicketDetails().getTicketId());
|
||||
complaintResponseEntity.setTicketType(responseWrapper.getTicketDetails().getTicketType());
|
||||
@@ -1238,36 +1166,107 @@ record.setTxnStatus("PENDING");
|
||||
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.setUserId(userId);
|
||||
complaintResponseEntity.setCreateDateTime(new Date());
|
||||
// If you need a separate complaintTicketId, you can set it here
|
||||
complaintResponseEntity.setComplaintTicketId(generateComplaintTicketId()); // Generate or set manually
|
||||
complaintResponseEntity.setComplaintTicketId(generateComplaintTicketId());
|
||||
|
||||
// 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.";
|
||||
ComplaintResponseEntity saved = complaintResponseRepository.save(complaintResponseEntity);
|
||||
if (saved != null) {
|
||||
return "1 record saved with id=" + saved.getId();
|
||||
}
|
||||
|
||||
return "Failed to save";
|
||||
}
|
||||
|
||||
// Save Complain Response From DB
|
||||
private String generateComplaintTicketId() {
|
||||
// Logic for generating complaint ticket ID
|
||||
return "CMP-" + UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
// Minimal mapping helpers used by AgentServiceImpl
|
||||
public com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest fetchBillForwardRequestMap(
|
||||
com.billpaymentservice.bbps.dto.request.FetchBillRequest req) {
|
||||
if (req == null) return null;
|
||||
com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest f = new com.billpaymentservice.bbps.dto.sentRequest.FetchBillForwardRequest();
|
||||
f.setBillerId(req.getBillerId());
|
||||
f.setBillerName(req.getBillerName());
|
||||
f.setBillerCategory(req.getBillerCategory());
|
||||
f.setClientReqId(req.getClientReqId());
|
||||
f.setMacAdress(req.getMacAdress());
|
||||
f.setCustomerMobNo(req.getCustomerMobNo());
|
||||
f.setRemitterName(req.getRemitterName());
|
||||
f.setPaymentChannel(req.getPaymentChannel());
|
||||
f.setDeviceBlockTags(req.getDeviceBlockTags());
|
||||
f.setCustomerParamsRequest(req.getCustomerParamsRequest());
|
||||
f.setRemitterIdentity(req.getRemitterIdentity());
|
||||
return f;
|
||||
}
|
||||
|
||||
public com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest fetchBillValidatestForwardRequest(
|
||||
com.billpaymentservice.bbps.dto.request.FetchBillValidatestRequest req) {
|
||||
if (req == null) return null;
|
||||
com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest f = new com.billpaymentservice.bbps.dto.sentRequest.FetchBillValidatestForwardRequest();
|
||||
f.setBillerId(req.getBillerId());
|
||||
f.setBillerName(req.getBillerName());
|
||||
f.setBillerCategory(req.getBillerCategory());
|
||||
f.setCustomerMobNo(req.getCustomerMobNo());
|
||||
f.setClientReqId(req.getClientReqId());
|
||||
f.setMacAddress(req.getMacAddress());
|
||||
f.setCustomerParamsRequest(req.getCustomerParamsRequest());
|
||||
return f;
|
||||
}
|
||||
|
||||
public void saveBillValidation(com.billpaymentservice.bbps.dto.response.FetchBillValidateResponse responseWrapper,
|
||||
com.billpaymentservice.bbps.dto.request.BillFetchByBillIdRequest billRequest, String txnId) {
|
||||
if (responseWrapper == null || billRequest == null) return;
|
||||
BillValidation entity = new BillValidation();
|
||||
entity.setBillId(responseWrapper.getBillId());
|
||||
entity.setRefId(responseWrapper.getRefId());
|
||||
entity.setBillerId(responseWrapper.getBillerId());
|
||||
entity.setStatus(responseWrapper.getStatus());
|
||||
entity.setActionType(responseWrapper.getActionType());
|
||||
entity.setUserId(responseWrapper.getUserId());
|
||||
entity.setBillerResponse(responseWrapper.getBillerResponse());
|
||||
entity.setTxnId(txnId);
|
||||
entity.setReqId(billRequest.getReqId());
|
||||
|
||||
// Map additionalInfo if present (minimal mapping)
|
||||
if (responseWrapper.getAdditionalInfo() != null) {
|
||||
List<AdditionalInfoBillValidate> addList = new ArrayList<>();
|
||||
for (com.billpaymentservice.bbps.dto.AdditionalInfoBillValidateDTO ai : responseWrapper.getAdditionalInfo()) {
|
||||
AdditionalInfoBillValidate info = new AdditionalInfoBillValidate();
|
||||
// DTO only has name & value
|
||||
info.setName(ai.getName());
|
||||
info.setValue(ai.getValue());
|
||||
info.setBill(entity);
|
||||
addList.add(info);
|
||||
}
|
||||
entity.setAdditionalInfo(addList);
|
||||
}
|
||||
|
||||
// Map customerParams if present (minimal mapping)
|
||||
if (responseWrapper.getCustomerParams() != null) {
|
||||
List<CustomerParamBillValidation> cpList = new ArrayList<>();
|
||||
for (com.billpaymentservice.bbps.dto.CustomerParamDAO cp : responseWrapper.getCustomerParams()) {
|
||||
CustomerParamBillValidation param = new CustomerParamBillValidation();
|
||||
param.setName(cp.getName());
|
||||
param.setValue(cp.getValue());
|
||||
param.setType(cp.getType());
|
||||
param.setBill(entity);
|
||||
cpList.add(param);
|
||||
}
|
||||
entity.setCustomerParams(cpList);
|
||||
}
|
||||
|
||||
// Persist
|
||||
try {
|
||||
billValidationRepository.save(entity);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error saving BillValidation: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user