|
|
|
@ -1,9 +1,11 @@
|
|
|
|
package com.mfsys.uco.service;
|
|
|
|
package com.mfsys.uco.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.mfsys.uco.constants.UCOConstants;
|
|
|
|
import com.mfsys.uco.constants.UCOConstants;
|
|
|
|
import com.mfsys.uco.constants.UCOURI;
|
|
|
|
import com.mfsys.uco.constants.UCOURI;
|
|
|
|
import com.mfsys.uco.dto.AccountInquiryResponse;
|
|
|
|
import com.mfsys.uco.dto.AccountInquiryResponse;
|
|
|
|
|
|
|
|
import com.mfsys.uco.dto.AddAccountRequestModel;
|
|
|
|
import com.mfsys.uco.dto.SignupStep3RequestModel;
|
|
|
|
import com.mfsys.uco.dto.SignupStep3RequestModel;
|
|
|
|
import com.mfsys.uco.dto.webclientdto.AccountDetail;
|
|
|
|
import com.mfsys.uco.dto.webclientdto.AccountDetail;
|
|
|
|
import com.mfsys.uco.exception.AccountDoesntExistsException;
|
|
|
|
import com.mfsys.uco.exception.AccountDoesntExistsException;
|
|
|
|
@ -16,15 +18,11 @@ import com.mfsys.uco.repository.UCOAccountRepository;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class UcoAccountService {
|
|
|
|
public class UcoAccountService {
|
|
|
|
|
|
|
|
ObjectMapper objectMapper;
|
|
|
|
private final CustomerProfileRepository customerProfileRepository;
|
|
|
|
private final CustomerProfileRepository customerProfileRepository;
|
|
|
|
private final UCOAccountRepository ucoAccountRepository;
|
|
|
|
private final UCOAccountRepository ucoAccountRepository;
|
|
|
|
private final CustomerProfileService customerProfileService;
|
|
|
|
private final CustomerProfileService customerProfileService;
|
|
|
|
@ -32,12 +30,14 @@ public class UcoAccountService {
|
|
|
|
private final WebClientDepositService webClientDeposit;
|
|
|
|
private final WebClientDepositService webClientDeposit;
|
|
|
|
private final WebClientCrmService webClientCrmService;
|
|
|
|
private final WebClientCrmService webClientCrmService;
|
|
|
|
|
|
|
|
|
|
|
|
public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, CustomerProfileService customerProfileService, WebClientDepositService webClientDeposit, WebClientCrmService webClientCrmService) {
|
|
|
|
public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, CustomerProfileService customerProfileService, WebClientDepositService webClientDeposit, WebClientCrmService webClientCrmService
|
|
|
|
|
|
|
|
,ObjectMapper objectMapper) {
|
|
|
|
this.customerProfileRepository = customerProfileRepository;
|
|
|
|
this.customerProfileRepository = customerProfileRepository;
|
|
|
|
this.ucoAccountRepository = ucoAccountRepository;
|
|
|
|
this.ucoAccountRepository = ucoAccountRepository;
|
|
|
|
this.customerProfileService = customerProfileService;
|
|
|
|
this.customerProfileService = customerProfileService;
|
|
|
|
this.webClientDeposit = webClientDeposit;
|
|
|
|
this.webClientDeposit = webClientDeposit;
|
|
|
|
this.webClientCrmService = webClientCrmService;
|
|
|
|
this.webClientCrmService = webClientCrmService;
|
|
|
|
|
|
|
|
this.objectMapper = objectMapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AccountInquiryResponse fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue) {
|
|
|
|
public AccountInquiryResponse fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue) {
|
|
|
|
@ -70,7 +70,6 @@ public class UcoAccountService {
|
|
|
|
if (Objects.nonNull(customerProfileService.fetchCustcodeBasedOnEmail(signupStep3RequestModel.getPorOrgacode(), signupStep3RequestModel.getEmail()))) {
|
|
|
|
if (Objects.nonNull(customerProfileService.fetchCustcodeBasedOnEmail(signupStep3RequestModel.getPorOrgacode(), signupStep3RequestModel.getEmail()))) {
|
|
|
|
throw new UserAlreadyRegisteredException(null);
|
|
|
|
throw new UserAlreadyRegisteredException(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String porOrgacode = signupStep3RequestModel.getPorOrgacode();
|
|
|
|
String porOrgacode = signupStep3RequestModel.getPorOrgacode();
|
|
|
|
|
|
|
|
|
|
|
|
Map cmpCustcodeReturn = (Map) webClientCrmService.onboardCustomer(Map.of("CMP_FULLNAME", signupStep3RequestModel.getName()
|
|
|
|
Map cmpCustcodeReturn = (Map) webClientCrmService.onboardCustomer(Map.of("CMP_FULLNAME", signupStep3RequestModel.getName()
|
|
|
|
@ -80,7 +79,7 @@ public class UcoAccountService {
|
|
|
|
String cmpCustcode = String.valueOf(cmpCustcodeReturn.get("cmpCustcode"));
|
|
|
|
String cmpCustcode = String.valueOf(cmpCustcodeReturn.get("cmpCustcode"));
|
|
|
|
System.out.println(cmpCustcode);
|
|
|
|
System.out.println(cmpCustcode);
|
|
|
|
|
|
|
|
|
|
|
|
AccountDetail accountDetail = fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode);
|
|
|
|
AccountDetail accountDetail = fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode).get(0);
|
|
|
|
CustomerProfile customerProfile = CustomerProfile.builder().cmpCustcode(accountDetail.getCmpCustcode()).cmpEmail(signupStep3RequestModel.getEmail())
|
|
|
|
CustomerProfile customerProfile = CustomerProfile.builder().cmpCustcode(accountDetail.getCmpCustcode()).cmpEmail(signupStep3RequestModel.getEmail())
|
|
|
|
.cmpName(signupStep3RequestModel.getName()).cmpIsKycVerified(signupStep3RequestModel.isKycAdded())
|
|
|
|
.cmpName(signupStep3RequestModel.getName()).cmpIsKycVerified(signupStep3RequestModel.isKycAdded())
|
|
|
|
.pitIdencode(signupStep3RequestModel.getIdentificationType()).pitIdenvalue(signupStep3RequestModel.getIdentificationNumber())
|
|
|
|
.pitIdencode(signupStep3RequestModel.getIdentificationType()).pitIdenvalue(signupStep3RequestModel.getIdentificationNumber())
|
|
|
|
@ -104,12 +103,13 @@ public class UcoAccountService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AccountDetail fetchdepositAccountFromCiihive(String porOrgacode, String cmpCustcode) {
|
|
|
|
public List<AccountDetail> fetchdepositAccountFromCiihive(String porOrgacode, String cmpCustcode) {
|
|
|
|
String url = UCOURI.GET_CMP_UCOACCOUNTS + "?porOrgacode=" + porOrgacode + "&cmpCustcode=" + cmpCustcode;
|
|
|
|
String url = UCOURI.GET_CMP_UCOACCOUNTS + "?porOrgacode=" + porOrgacode + "&cmpCustcode=" + cmpCustcode;
|
|
|
|
List<Object> map = (List<Object>) webClientDeposit.getCmpUcoAccounts(url, porOrgacode);
|
|
|
|
List<Object> map = (List<Object>) webClientDeposit.getCmpUcoAccounts(url, porOrgacode);
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
|
|
return objectMapper.convertValue(map.get(0), AccountDetail.class);
|
|
|
|
return objectMapper.convertValue(map, objectMapper.getTypeFactory().constructCollectionType(List.class, AccountDetail.class));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -117,5 +117,75 @@ public class UcoAccountService {
|
|
|
|
String url = UCOURI.FETCH_EXCHANGE_RATE + "?porOrgacode=" + porOrgacode;
|
|
|
|
String url = UCOURI.FETCH_EXCHANGE_RATE + "?porOrgacode=" + porOrgacode;
|
|
|
|
return webClientDeposit.fetchExchangeRate(url, porOrgacode);
|
|
|
|
return webClientDeposit.fetchExchangeRate(url, porOrgacode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void addUcoAccount(AddAccountRequestModel addAccountRequestModel){
|
|
|
|
|
|
|
|
String porOrgacode = addAccountRequestModel.getPorOrgacode();
|
|
|
|
|
|
|
|
CustomerProfile customerProfile = customerProfileRepository.findCustomerProfileByCmpEmailAndPorOrgacode(porOrgacode,addAccountRequestModel.getEmail());
|
|
|
|
|
|
|
|
String accountNumber = webClientDeposit.createUcoAccount(JsonToString(Map.of("payload",preparePayloadForAccount(customerProfile,addAccountRequestModel.getTitle()),
|
|
|
|
|
|
|
|
"uniqueConstraints",List.of(List.of(String.valueOf(addAccountRequestModel.getDmpProdcode()))))),UCOURI.UCO_CUSTOMER_ACCOUNT,porOrgacode);
|
|
|
|
|
|
|
|
saveCustomerAccountDetails(porOrgacode,customerProfile.getCmpCustcode(),accountNumber);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void saveCustomerAccountDetails(String porOrgacode, String cmpCustcode,String accountNumber){
|
|
|
|
|
|
|
|
fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode).stream().forEach(k -> {
|
|
|
|
|
|
|
|
if(k.getMbmBkmsnumber().equals(accountNumber)){
|
|
|
|
|
|
|
|
UcoAccount ucoAccount = UcoAccount.builder()
|
|
|
|
|
|
|
|
.id(new AccountId(k.getPorOrgacode(), k.getMbmBkmsnumber())) // Set the AccountId, assuming a method exists to create or retrieve it
|
|
|
|
|
|
|
|
.dmpProdcode(k.getDmpProdcode())
|
|
|
|
|
|
|
|
.mbmBkmstitle(k.getMbmBkmstitle())
|
|
|
|
|
|
|
|
.pcrCurrdesc(k.getPcrCurrdesc())
|
|
|
|
|
|
|
|
.cmpCustcode(k.getCmpCustcode())
|
|
|
|
|
|
|
|
.pcrCurrcode(k.getPcrCurrcode())
|
|
|
|
|
|
|
|
.mbmBkmsclosed(k.isMbmBkmsclosed())
|
|
|
|
|
|
|
|
.mbmBkmsopendate(LocalDate.now())
|
|
|
|
|
|
|
|
.sgtLasttrandate(LocalDate.now())
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
ucoAccountRepository.save(ucoAccount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public String preparePayloadForAccount(CustomerProfile customerProfile,String title){
|
|
|
|
|
|
|
|
Map<String,Object> jsonMap = new HashMap<>();
|
|
|
|
|
|
|
|
jsonMap.put("SUS_USERCODE", "01");
|
|
|
|
|
|
|
|
jsonMap.put("CMP_CUSTCODE",customerProfile.getCmpCustcode());
|
|
|
|
|
|
|
|
jsonMap.put("CMP_FULLNAME", title);
|
|
|
|
|
|
|
|
jsonMap.put("PLC_LOCACODE", "2003");
|
|
|
|
|
|
|
|
jsonMap.put("workFlowStage", "BN_WF_CP_AUTHORIZATION");
|
|
|
|
|
|
|
|
jsonMap.put("PCT_CSTYCODE", "I");
|
|
|
|
|
|
|
|
jsonMap.put("POR_ORGACODE", customerProfile.getPorOrgacode());
|
|
|
|
|
|
|
|
List<Map<String, Object>> workFlowLog = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<String, Object> logEntry = new HashMap<>();
|
|
|
|
|
|
|
|
logEntry.put("susUsercode", "01");
|
|
|
|
|
|
|
|
logEntry.put("formId", "BN_WF_CP_AUTHORIZATION");
|
|
|
|
|
|
|
|
workFlowLog.add(logEntry);
|
|
|
|
|
|
|
|
jsonMap.put("workFlowLog", workFlowLog);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> bnCsItIdentifier = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<String, Object> identifierEntry = new HashMap<>();
|
|
|
|
|
|
|
|
identifierEntry.put("CIT_IDENVALUE", customerProfile.getPitIdenvalue());
|
|
|
|
|
|
|
|
identifierEntry.put("PIT_PRIMARYIDENCODE", true);
|
|
|
|
|
|
|
|
identifierEntry.put("PIT_IDENCODE", customerProfile.getPitIdencode());
|
|
|
|
|
|
|
|
bnCsItIdentifier.add(identifierEntry);
|
|
|
|
|
|
|
|
jsonMap.put("BN_CS_IT_IDENTIFIER", bnCsItIdentifier);
|
|
|
|
|
|
|
|
jsonMap.put("@_CREATEUSER", "01");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> bnCsAdAddress = new ArrayList<>();
|
|
|
|
|
|
|
|
Map<String, Object> addressEntry = new HashMap<>();
|
|
|
|
|
|
|
|
addressEntry.put("PAD_ADRSCORRESPONDENCE", true);
|
|
|
|
|
|
|
|
addressEntry.put("PAD_ADRSMOBPHONE", customerProfile.getPadAdrsmobphone());
|
|
|
|
|
|
|
|
bnCsAdAddress.add(addressEntry);
|
|
|
|
|
|
|
|
jsonMap.put("BN_CS_AD_ADDRESS", customerProfile.getCmpAddress());
|
|
|
|
|
|
|
|
Map<String, Object> createdDateMap = new HashMap<>();
|
|
|
|
|
|
|
|
createdDateMap.put("$date", new Date());
|
|
|
|
|
|
|
|
jsonMap.put("@_CREATEDATE", createdDateMap);
|
|
|
|
|
|
|
|
return JsonToString(jsonMap);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public String JsonToString(Object jsonMap){
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return this.objectMapper.writeValueAsString(jsonMap);
|
|
|
|
|
|
|
|
} catch (JsonProcessingException var3) {
|
|
|
|
|
|
|
|
throw new RuntimeException(var3);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|