This commit is contained in:
Mohd-Arham
2025-11-12 17:03:07 +05:30
parent 1102a58aee
commit 7e8a7fdd6b
16 changed files with 620 additions and 65 deletions
@@ -6,17 +6,20 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.billpaymentservice.bbps.dto.AmountOptionDTO;
import com.billpaymentservice.bbps.dto.BillerIconDTO;
import com.billpaymentservice.bbps.dto.ComplainDetailsDto;
import com.billpaymentservice.bbps.dto.ComplaintHistoryDTO;
import com.billpaymentservice.bbps.dto.CustomerParamGroupsDTO;
import com.billpaymentservice.bbps.dto.GroupDTO;
import com.billpaymentservice.bbps.dto.MasterCategoryBillerResponse;
import com.billpaymentservice.bbps.dto.PlanDTO;
import com.billpaymentservice.bbps.dto.PlanTag;
import com.billpaymentservice.bbps.dto.response.AmountOptionsResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintHistoryStatusResponse;
import com.billpaymentservice.bbps.dto.response.ComplaintStatusResponse;
import com.billpaymentservice.bbps.dto.response.PlanResponse;
import com.billpaymentservice.bbps.entites.AdditionalInfoPlans;
@@ -26,6 +29,7 @@ import com.billpaymentservice.bbps.entites.BillerCategoryIcon;
import com.billpaymentservice.bbps.entites.BillerCategoryWise;
import com.billpaymentservice.bbps.entites.CategoryResponseList;
import com.billpaymentservice.bbps.entites.ComplainStatus;
import com.billpaymentservice.bbps.entites.ComplaintHistory;
import com.billpaymentservice.bbps.entites.CustomerParamGroupById;
import com.billpaymentservice.bbps.entites.GroupParam;
import com.billpaymentservice.bbps.entites.Plan;
@@ -36,15 +40,19 @@ import com.billpaymentservice.bbps.entites.ReOpenComplain;
import com.billpaymentservice.bbps.repository.AmountOptionByBillerIdRepository;
import com.billpaymentservice.bbps.repository.BillerCategoryWiseRepository;
import com.billpaymentservice.bbps.repository.CategoryResponseListRepository;
import com.billpaymentservice.bbps.repository.ComplaintHistoryRepository;
import com.billpaymentservice.bbps.repository.ComplaintStatusRepository;
import com.billpaymentservice.bbps.repository.CustomerParamGroupByBillerIdRepository;
import com.billpaymentservice.bbps.repository.FetchBillValidateRepository;
import com.billpaymentservice.bbps.repository.PlanResponseRepository;
import com.billpaymentservice.bbps.repository.ReOpenComplaintRepository;
import com.billpaymentservice.bbps.serviceImpl.AgentServiceImpl;
@Component
public class BillerMapperHelper {
private static final Logger LOGGER = LoggerFactory.getLogger(BillerMapperHelper.class);
private final BillerCategoryWiseRepository billerRepo;
private final CustomerParamGroupByBillerIdRepository customerParamGroupByBillerIdRepo;
private final AmountOptionByBillerIdRepository amountOptionByBillerIdRepository;
@@ -53,6 +61,7 @@ public class BillerMapperHelper {
private final FetchBillValidateRepository fetchBillValidateRepository;
private final ComplaintStatusRepository complaintStatusRepository;
private final ReOpenComplaintRepository reOpenComplaintRepository;
private final ComplaintHistoryRepository complaintHistoryRepository;
public BillerMapperHelper(BillerCategoryWiseRepository billerRepo,
CustomerParamGroupByBillerIdRepository customerParamGroupByBillerIdRepo,
@@ -60,7 +69,8 @@ public class BillerMapperHelper {
PlanResponseRepository planResponseRepository,
CategoryResponseListRepository categoryResponseListRepository,
FetchBillValidateRepository fetchBillValidateRepository,
ComplaintStatusRepository complaintStatusRepository, ReOpenComplaintRepository reOpenComplaintRepository) {
ComplaintStatusRepository complaintStatusRepository, ReOpenComplaintRepository reOpenComplaintRepository,
ComplaintHistoryRepository complaintHistoryRepository) {
this.billerRepo = billerRepo;
this.customerParamGroupByBillerIdRepo = customerParamGroupByBillerIdRepo;
this.amountOptionByBillerIdRepository = amountOptionByBillerIdRepository;
@@ -69,6 +79,7 @@ public class BillerMapperHelper {
this.fetchBillValidateRepository = fetchBillValidateRepository;
this.complaintStatusRepository = complaintStatusRepository;
this.reOpenComplaintRepository = reOpenComplaintRepository;
this.complaintHistoryRepository = complaintHistoryRepository;
}
/**
@@ -288,72 +299,72 @@ public class BillerMapperHelper {
}
public PlanResponses savePlanResponse(PlanResponse planResponse, String reqId, String txnId) {
PlanResponses response = new PlanResponses();
response.setRequestId(reqId);
response.setPageNo(planResponse.getPageNo());
response.setPageSize(planResponse.getPageSize());
response.setTotalElements(planResponse.getTotalElements());
response.setTotalPages(planResponse.getTotalPages());
response.setTxnId(txnId);
response.setCreateDateTime(new Date());
PlanResponses response = new PlanResponses();
response.setRequestId(reqId);
response.setPageNo(planResponse.getPageNo());
response.setPageSize(planResponse.getPageSize());
response.setTotalElements(planResponse.getTotalElements());
response.setTotalPages(planResponse.getTotalPages());
response.setTxnId(txnId);
response.setCreateDateTime(new Date());
PlansList plansList = new PlansList();
List<Plan> planEntities = new ArrayList<>();
PlansList plansList = new PlansList();
List<Plan> planEntities = new ArrayList<>();
for (PlanDTO dto : planResponse.getPlansList().getPlans()) {
Plan plan = new Plan();
plan.setPlanId(dto.getPlanId());
plan.setDescription(dto.getDescription());
plan.setBillerId(dto.getBillerId());
plan.setCategoryType(dto.getCategoryType());
plan.setAmountInRupees(dto.getAmountInRupees());
plan.setEffctvFrom(dto.getEffctvFrom());
plan.setEffctvTo(dto.getEffctvTo());
plan.setStatus(dto.getStatus());
plan.setPlansList(plansList);
for (PlanDTO dto : planResponse.getPlansList().getPlans()) {
Plan plan = new Plan();
plan.setPlanId(dto.getPlanId());
plan.setDescription(dto.getDescription());
plan.setBillerId(dto.getBillerId());
plan.setCategoryType(dto.getCategoryType());
plan.setAmountInRupees(dto.getAmountInRupees());
plan.setEffctvFrom(dto.getEffctvFrom());
plan.setEffctvTo(dto.getEffctvTo());
plan.setStatus(dto.getStatus());
plan.setPlansList(plansList);
// categorySubType
List<PlanCategorySubType> subs = new ArrayList<>();
if (dto.getCategorySubType() != null) {
for (String s : dto.getCategorySubType()) {
PlanCategorySubType sub = new PlanCategorySubType();
sub.setCategorySubType(s);
sub.setPlan(plan);
subs.add(sub);
}
}
plan.setCategorySubTypes(subs);
// categorySubType
List<PlanCategorySubType> subs = new ArrayList<>();
if (dto.getCategorySubType() != null) {
for (String s : dto.getCategorySubType()) {
PlanCategorySubType sub = new PlanCategorySubType();
sub.setCategorySubType(s);
sub.setPlan(plan);
subs.add(sub);
}
}
plan.setCategorySubTypes(subs);
// additionalInfo + tags
// ✅ additionalInfo + tags
if (dto.getAdditionalInfo() != null) {
AdditionalInfoPlans info = new AdditionalInfoPlans();
info.setPlanAdditionalInfoId(dto.getAdditionalInfo().getPlanAdditionalInfoId().toString());
// additionalInfo + tags
// ✅ additionalInfo + tags
if (dto.getAdditionalInfo() != null) {
AdditionalInfoPlans info = new AdditionalInfoPlans();
info.setPlanAdditionalInfoId(dto.getAdditionalInfo().getPlanAdditionalInfoId().toString());
List<com.billpaymentservice.bbps.entites.PlanTag> tagEntities = new ArrayList<>();
if (dto.getAdditionalInfo().getTags() != null && !dto.getAdditionalInfo().getTags().isEmpty()) {
for (com.billpaymentservice.bbps.dto.PlanTag tagDto : dto.getAdditionalInfo().getTags()) {
com.billpaymentservice.bbps.entites.PlanTag tagEntity = new com.billpaymentservice.bbps.entites.PlanTag();
tagEntity.setTagId(tagDto.getTagId().toString());
tagEntity.setName(tagDto.getName());
tagEntity.setValue(tagDto.getValue());
tagEntity.setAdditionalInfo(info); // ✅ maintain relationship
tagEntities.add(tagEntity);
}
}
List<com.billpaymentservice.bbps.entites.PlanTag> tagEntities = new ArrayList<>();
if (dto.getAdditionalInfo().getTags() != null && !dto.getAdditionalInfo().getTags().isEmpty()) {
for (com.billpaymentservice.bbps.dto.PlanTag tagDto : dto.getAdditionalInfo().getTags()) {
com.billpaymentservice.bbps.entites.PlanTag tagEntity = new com.billpaymentservice.bbps.entites.PlanTag();
tagEntity.setTagId(tagDto.getTagId().toString());
tagEntity.setName(tagDto.getName());
tagEntity.setValue(tagDto.getValue());
tagEntity.setAdditionalInfo(info); // ✅ maintain relationship
tagEntities.add(tagEntity);
}
}
// ✅ Now set the entity list
info.setTags(tagEntities);
plan.setAdditionalInfo(info);
}
// ✅ Now set the entity list
info.setTags(tagEntities);
plan.setAdditionalInfo(info);
}
planEntities.add(plan);
}
planEntities.add(plan);
}
plansList.setPlans(planEntities);
response.setPlansList(plansList);
plansList.setPlans(planEntities);
response.setPlansList(plansList);
return planResponseRepository.save(response);
return planResponseRepository.save(response);
}
public String saveCategoryItems(List<String> categoryRespList, String requestId, String txnId) {
@@ -375,7 +386,7 @@ public class BillerMapperHelper {
return savedCount + " items were successfully saved.";
}
public String saveComplaintStatus(ComplaintStatusResponse response, String reqId) {
public String saveComplaintStatus(ComplaintStatusResponse response, String reqId, String txnId) {
if (response == null || response.getComplaints() == null) {
throw new IllegalArgumentException("Invalid complaint response received!");
@@ -411,6 +422,7 @@ public class BillerMapperHelper {
entity.setCreatedEpochDate(dto.getCreatedEpochDate());
entity.setModifiedEpochDate(dto.getModifiedEpochDate());
entity.setRefId(reqId);
entity.setSystemTxnId(txnId);
try {
ComplainStatus savedEntity = complaintStatusRepository.save(entity);
@@ -425,7 +437,7 @@ public class BillerMapperHelper {
}
}
public String saveReOpenComplaint(ComplaintStatusResponse response, String reqId) {
public String saveReOpenComplaint(ComplaintStatusResponse response, String reqId, String txnId) {
if (response == null || response.getComplaints() == null) {
throw new IllegalArgumentException("Invalid complaint response received!");
@@ -461,6 +473,7 @@ public class BillerMapperHelper {
entity.setCreatedEpochDate(dto.getCreatedEpochDate());
entity.setModifiedEpochDate(dto.getModifiedEpochDate());
entity.setRefId(reqId);
entity.setSystemTxnId(txnId);
try {
ReOpenComplain savedEntity = reOpenComplaintRepository.save(entity);
@@ -475,4 +488,50 @@ public class BillerMapperHelper {
}
}
public String saveComplaintHistory(ComplaintHistoryStatusResponse responseWrapper, String reqId, String txnId) {
if (responseWrapper == null || responseWrapper.getComplaintsHistories() == null
|| responseWrapper.getComplaintsHistories().isEmpty()) {
return "No complaint history data found to save.";
}
try {
int savedCount = 0;
for (ComplaintHistoryDTO dto : responseWrapper.getComplaintsHistories()) {
ComplaintHistory entity = new ComplaintHistory();
entity.setComplaintHistoryId(dto.getComplaintHistoryId());
entity.setComplaintId(dto.getComplaintId());
entity.setComplaintDescr(dto.getComplaintDescr());
entity.setComplaintDispos(dto.getComplaintDispos());
entity.setTxnId(dto.getTxnId());
entity.setAssignedTo(dto.getAssignedTo());
entity.setComplaintNpciId(dto.getComplaintNpciId());
entity.setComplaintType(dto.getComplaintType());
entity.setComplaintRaisedFrom(dto.getComplaintRaisedFrom());
entity.setUserId(dto.getUserId());
entity.setStatus(dto.getStatus());
entity.setModifiedDate(dto.getModifiedDate());
entity.setModifiedEpochDate(dto.getModifiedEpochDate());
entity.setReqId(reqId);
entity.setSystemTxnId(txnId);
entity.setCreateDateTime(new Date());
entity.setPageNo(responseWrapper.getPageNo());
entity.setPageSize(responseWrapper.getPageSize());
entity.setTotalElements(responseWrapper.getTotalElements());
entity.setTotalPages(responseWrapper.getTotalPages());
complaintHistoryRepository.save(entity);
savedCount++;
}
return "✅ " + savedCount + " Complaint history record(s) saved successfully.";
} catch (Exception e) {
// Log the error for debugging
LOGGER.error("❌ Error saving complaint history data: {}", e.getMessage(), e);
return "❌ Failed to save complaint history data due to: " + e.getMessage();
}
}
}