This commit is contained in:
Mohd-Arham
2025-12-02 18:43:59 +05:30
parent af15334937
commit 5f09755d2c
8 changed files with 103 additions and 11 deletions
@@ -29,6 +29,7 @@ import com.billpaymentservice.bbps.dto.response.ViewComplainByIdResponse;
import com.billpaymentservice.bbps.dto.sentRequest.FetchComplaintForwardRequest;
import com.billpaymentservice.bbps.dto.sentRequest.FetchTicketLatestStatusRequest;
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
import com.billpaymentservice.bbps.entites.ComplaintResponseEntity;
import com.billpaymentservice.bbps.entites.ComplaintStatusOptionsMaster;
import com.billpaymentservice.bbps.entites.InboundTraceLog;
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
@@ -37,6 +38,7 @@ import com.billpaymentservice.bbps.exception.CustomException;
import com.billpaymentservice.bbps.repository.BharatConnectMasterRepository;
import com.billpaymentservice.bbps.repository.ComplainRepository;
import com.billpaymentservice.bbps.repository.ComplaintOptionsStatusMasterRepository;
import com.billpaymentservice.bbps.repository.ComplaintResponseRepository;
import com.billpaymentservice.bbps.repository.TransactionMasterRepository;
import com.billpaymentservice.bbps.service.ComplainService;
import com.billpaymentservice.bbps.util.BBPSConstant;
@@ -65,6 +67,7 @@ public class ComplainServiceImpl implements ComplainService {
private final ComplainRepository complainRepository;
private final ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository;
private final TransactionMasterRepository transactionMasterRepository;
private final ComplaintResponseRepository complaintResponseRepository;
// moved to class-level
private final ObjectMapper objectMapper;
@@ -74,7 +77,8 @@ public class ComplainServiceImpl implements ComplainService {
BharatConnectMasterRepository beneficiaryDetailsRepository, BillerMapperHelper mapperHelper,
ComplainRepository complainRepository,
ComplaintOptionsStatusMasterRepository complaintStatusMasterRepository,
TransactionMasterRepository transactionMasterRepository) {
TransactionMasterRepository transactionMasterRepository,
ComplaintResponseRepository complaintResponseRepository) {
this.restClient = restClient;
this.httpService = httpService;
this.helper = helper;
@@ -86,6 +90,7 @@ public class ComplainServiceImpl implements ComplainService {
// initialize shared ObjectMapper once
this.objectMapper = new ObjectMapper();
this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
this.complaintResponseRepository = complaintResponseRepository;
}
@Override
@@ -94,7 +99,8 @@ public class ComplainServiceImpl implements ComplainService {
String apiName = BBPSConstant.API_ADD_COMPLAIN;
String requestId = complainRequestDTO.getReqId();
String mid = complainRequestDTO.getMid();
LOGGER.info("[{}] START | reqId={} | mid={}", apiName, requestId, mid);
String userId = complainRequestDTO.getClientUserId();
LOGGER.info("[{}] START | reqId={} | mid={} | clientUserId={}", apiName, requestId, mid, userId);
String txnId = helper.generateTxnId(15);
String fullUrl = complainDataUrl + BBPSConstant.ADD_COMPLAIN_ENDPOINT;
@@ -186,7 +192,7 @@ public class ComplainServiceImpl implements ComplainService {
ComplaintResponse responseWrapper = objectMapper.convertValue(dataMap, ComplaintResponse.class);
String saveComplaintResponseEntity = mapperHelper.saveComplaintResponseEntity(responseWrapper, requestId,
txnId);
txnId, userId);
LOGGER.info("Save Complaint Response Count" + saveComplaintResponseEntity);
ResponseModel responseModel = new ResponseModel(responseWrapper.getMessage(), responseWrapper.getStatus(),
Integer.parseInt(responseWrapper.getStatusCode()), responseWrapper);
@@ -543,7 +549,7 @@ public class ComplainServiceImpl implements ComplainService {
String requestJson = helper.convertObjectToJson(request);
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, request.getMid(),
BBPSConstant.HTTP_POST, requestJson);
BBPSConstant.HTTP_GET, requestJson);
helper.validateMerchant(request.getMid());
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
HttpHeaders headers = helper.buildHeaders(headersData);
@@ -592,4 +598,69 @@ public class ComplainServiceImpl implements ComplainService {
}
}
@Override
public ResponseModel viewAllComplaintsByUserId(AllMasterOptionsRequest request) {
String apiName = BBPSConstant.API_VIEW_ALL_COMPLAINTS_BY_USER_ID;
String reqId = request.getReqId();
String mid = request.getMid();
String userId = request.getClientUserId();
LOGGER.info("[{}] START | reqId={} | mid={} | userId={}", apiName, reqId, mid, userId);
String txnId = helper.generateTxnId(15);
String requestJson = helper.convertObjectToJson(request);
InboundTraceLog inboundLog = helper.createInboundLog(reqId, txnId, apiName, mid, BBPSConstant.HTTP_GET,
requestJson);
helper.validateMerchant(mid); // Validate merchant before continuing
BharatConnectMaster headersData = beneficiaryDetailsRepository.findByOrgId(BBPSConstant.ORG_ID);
HttpHeaders headers = helper.buildHeaders(headersData);
OutboundTraceLog outboundLog = helper.createOutboundLog(txnId, reqId, apiName, apiName, BBPSConstant.HTTP_GET,
requestJson);
LOGGER.debug("Outbound log created successfully for Complaint: {}", apiName);
try {
// Validate userId
if (userId.isEmpty() || userId == null) {
helper.updateOutboundLogResponse(outboundLog, BBPSConstant.USER_ID_IS_EMPTY);
return new ResponseModel(BBPSConstant.USER_ID_IS_EMPTY, "User ID cannot be null or empty", // Provide a
BBPSConstant.BADREQUEST, null, 0 // Return 0 as the size when no complaints
);
}
// Log the call to external API
LOGGER.info("[{}] Calling external API | URL={}", apiName, apiName);
List<ComplaintResponseEntity> complaintUserData = complaintResponseRepository.findByUserIdCustom(userId);
// Check if complaints were found
if (complaintUserData == null || complaintUserData.isEmpty()) {
LOGGER.info("[{}] No complaints found for userId={}", apiName, userId);
throw new CustomException("No complaints found for this User ID", "FAILED", BBPSConstant.BADREQUEST,
null);
}
// Log the number of complaints fetched
LOGGER.info("[{}] Complaints found for userId={} | count={}", apiName, userId, complaintUserData.size());
// Update outbound log with the count
String count = String.valueOf(complaintUserData.size());
helper.updateOutboundLogResponse(outboundLog, count);
// Return successful response with complaints data
return new ResponseModel(BBPSConstant.ALL_COMPLAINT_FIELDS_FETCH, BBPSConstant.SUCCESS_RESPONSE,
BBPSConstant.HTTP_OK_INT, complaintUserData, complaintUserData.size());
} catch (CustomException e) {
// Rethrow custom exception for handling at the controller level
throw e;
} catch (Exception e) {
// Log generic exception and create inbound log failure
LOGGER.error("[{}] Error: {}", apiName, e.getMessage(), e);
helper.updateInboundLogFailure(inboundLog, e.getMessage(), BBPSConstant.JSON_ERROR);
throw new CustomException("An error occurred while processing the request");
}
}
}