diff --git a/src/main/java/com/mfsys/uco/constants/UCOURI.java b/src/main/java/com/mfsys/uco/constants/UCOURI.java new file mode 100644 index 0000000..4571fdd --- /dev/null +++ b/src/main/java/com/mfsys/uco/constants/UCOURI.java @@ -0,0 +1,5 @@ +package com.mfsys.uco.constants; + +public interface UCOURI { + String GET_UCOACC_BALANCE = "/deposit/getUcoAccountBalance"; +} diff --git a/src/main/java/com/mfsys/uco/dto/TransactionPinResponseModel.java b/src/main/java/com/mfsys/uco/dto/TransactionPinResponseModel.java index 1bc7b5d..c59efa1 100644 --- a/src/main/java/com/mfsys/uco/dto/TransactionPinResponseModel.java +++ b/src/main/java/com/mfsys/uco/dto/TransactionPinResponseModel.java @@ -11,5 +11,4 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class TransactionPinResponseModel { private double otdTranrequestid; - private String pinCode; } diff --git a/src/main/java/com/mfsys/uco/repository/CustomerProfileRepository.java b/src/main/java/com/mfsys/uco/repository/CustomerProfileRepository.java index e3ff526..b94f4dc 100644 --- a/src/main/java/com/mfsys/uco/repository/CustomerProfileRepository.java +++ b/src/main/java/com/mfsys/uco/repository/CustomerProfileRepository.java @@ -3,8 +3,11 @@ package com.mfsys.uco.repository; import com.mfsys.uco.model.CustomerProfile; import com.mfsys.uco.model.CustomerProfileId; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @Repository public interface CustomerProfileRepository extends JpaRepository { + @Query("SELECT c FROM BN_CS_MP_CUSTOMERPROFILE c WHERE c.porOrgacode =:porOrgacode and c.padAdrsmobphone = :phone") + CustomerProfile findProfilesByMobilePhone(String porOrgacode,String phone); } diff --git a/src/main/java/com/mfsys/uco/repository/UCOAccountRepository.java b/src/main/java/com/mfsys/uco/repository/UCOAccountRepository.java new file mode 100644 index 0000000..0d15c34 --- /dev/null +++ b/src/main/java/com/mfsys/uco/repository/UCOAccountRepository.java @@ -0,0 +1,16 @@ +package com.mfsys.uco.repository; + +import com.mfsys.uco.model.AccountId; +import com.mfsys.uco.model.CustomerProfile; +import com.mfsys.uco.model.CustomerProfileId; +import com.mfsys.uco.model.UcoAccount; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +@Repository +public interface UCOAccountRepository extends JpaRepository { + + @Query("SELECT c FROM BN_MS_UC_UCOACCOUNT c WHERE c.id.porOrgacode =:porOrgacode and c.cmpCustcode = :cmpCustcode") + UcoAccount findUcoAccountByCmpCustcode(String porOrgacode,String cmpCustcode); +} diff --git a/src/main/java/com/mfsys/uco/service/TransactionService.java b/src/main/java/com/mfsys/uco/service/TransactionService.java new file mode 100644 index 0000000..ffdc18e --- /dev/null +++ b/src/main/java/com/mfsys/uco/service/TransactionService.java @@ -0,0 +1,9 @@ +package com.mfsys.uco.service; + +import org.springframework.stereotype.Service; + +@Service +public class TransactionService { + + +} diff --git a/src/main/java/com/mfsys/uco/service/UcoAccountService.java b/src/main/java/com/mfsys/uco/service/UcoAccountService.java new file mode 100644 index 0000000..87aabac --- /dev/null +++ b/src/main/java/com/mfsys/uco/service/UcoAccountService.java @@ -0,0 +1,44 @@ +package com.mfsys.uco.service; + +import com.mfsys.uco.constants.UCOURI; +import com.mfsys.uco.model.CustomerProfile; +import com.mfsys.uco.repository.CustomerProfileRepository; +import com.mfsys.uco.repository.UCOAccountRepository; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; + +import java.math.BigDecimal; +import java.util.Map; + +@Service +public class UcoAccountService { + + private final CustomerProfileRepository customerProfileRepository; + private final UCOAccountRepository ucoAccountRepository; + + private final WebClientDepositService webClientDeposit; + + public UcoAccountService(CustomerProfileRepository customerProfileRepository, UCOAccountRepository ucoAccountRepository, WebClientDepositService webClientDeposit) { + this.customerProfileRepository = customerProfileRepository; + this.ucoAccountRepository = ucoAccountRepository; + this.webClientDeposit = webClientDeposit; + } + + public String fetchAccountTitile(String porOrgacode, String acntTypeCode, String acntTypeValue){ + if(acntTypeCode.equals("01")){ + CustomerProfile customerProfile = customerProfileRepository.findProfilesByMobilePhone(porOrgacode,acntTypeValue); + return ucoAccountRepository.findUcoAccountByCmpCustcode(porOrgacode,customerProfile.getCmpCustcode()).getMbmBkmstitle(); + } + return null; + } + + + public Double fetchAccountBalance(String porOrgacode, String mbmBkmsNumber) { + return (Double) getIndvAccountDetails(porOrgacode,mbmBkmsNumber); + } + + public Object getIndvAccountDetails(String porOrgacode, String mbmBkmsnumber) { + String url= UCOURI.GET_UCOACC_BALANCE+"?porOrgacode="+porOrgacode+"&mbmBkmsnumber="+mbmBkmsnumber; + return webClientDeposit.getUcoAccountBalance(url,porOrgacode); + } +} diff --git a/src/main/java/com/mfsys/uco/service/WebClientDepositService.java b/src/main/java/com/mfsys/uco/service/WebClientDepositService.java new file mode 100644 index 0000000..319a4c8 --- /dev/null +++ b/src/main/java/com/mfsys/uco/service/WebClientDepositService.java @@ -0,0 +1,64 @@ +package com.mfsys.uco.service; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mfsys.comm.exception.ApplicationException; +import com.mfsys.comm.exception.ApplicationExceptionMapper; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; +import reactor.core.publisher.Mono; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@Service +public class WebClientDepositService { + private final WebClient webClientDeposit; + + + public WebClientDepositService(WebClient webClientDeposit) { + this.webClientDeposit = webClientDeposit; + } + public Object getUcoAccountBalance(String url,String porOrgacode) { + return handleResponse(webClientDeposit.get().uri(url).accept(MediaType.APPLICATION_JSON) + .header("SUS_USERCODE", porOrgacode) + .header("POR_ORGACODE", porOrgacode).retrieve().toEntity(Object.class), + null); + } + + private T handleResponse(Mono> responseMono, String porgaCode) { + try { + ResponseEntity response = responseMono.block(); + return response.getBody(); + } catch (WebClientResponseException e) { + ApplicationExceptionMapper.APIError errorDetails = parseErrorDetails(e); + throw new ApplicationException(porgaCode,errorDetails.getErrorCode(),errorDetails.getArguments()); + } + } + + private ApplicationExceptionMapper.APIError parseErrorDetails(WebClientResponseException e) { + String errorCode = null; + List arguments = null; + if (e.getResponseBodyAsString() != null) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode errorNode = objectMapper.readTree(e.getResponseBodyAsString()); + errorCode = errorNode.get("errorCode").asText(); + arguments = Arrays.asList(objectMapper.convertValue(errorNode.get("arguments"), String[].class)); + } catch (IOException ex) { + } + } + return new ApplicationExceptionMapper.APIError(errorCode, arguments.toArray()); + } +} + + + + + +