Nabeel-DG-BS
Raja Nabeel 1 year ago
parent 444215580f
commit 63ff9d2999

@ -13,7 +13,7 @@ import java.math.BigDecimal;
@NoArgsConstructor @NoArgsConstructor
public class EvaluatedCurrencyReponse { public class EvaluatedCurrencyReponse {
private String pcrCurrcode; private String pcrCurrcode;
private double sgtGntramtfc; private BigDecimal sgtGntramtfc;
private double serviceCharges; private double serviceCharges;
private double targetPerEratrateact; private double targetPerEratrateact;

@ -0,0 +1,11 @@
package com.mfsys.uco.exception;
import com.mfsys.comm.exception.ApplicationException;
import com.mfsys.comm.exception.ERRCode;
public class CustomerAccountOpeningNotAllowedException extends ApplicationException {
public CustomerAccountOpeningNotAllowedException() {
super(null, ERRCode.CUSTOMER_ACCOUNT_PRODUCT_ALREADY_EXISTS, null);
}
}

@ -50,6 +50,7 @@ public class TransactionPinService {
public void updateTransactionPin(ChangeTransactionPinRequest request) { public void updateTransactionPin(ChangeTransactionPinRequest request) {
CustomerProfile profile = fetchCustomer(request.getPorOrgacode(), request.getCmpCustcode()); CustomerProfile profile = fetchCustomer(request.getPorOrgacode(), request.getCmpCustcode());
validateOldPin(profile, request.getOldTransPincode()); validateOldPin(profile, request.getOldTransPincode());
profile.setCmpUnverifiedTranpin(request.getNewTransPincode()); profile.setCmpUnverifiedTranpin(request.getNewTransPincode());
customerProfileRepository.save(profile); customerProfileRepository.save(profile);

@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -160,39 +161,38 @@ public class TransactionService {
} }
public EvaluatedCurrencyReponse getEvaluatedCurrency(String porOrgacode, String baseCurrencyCode, String targetCurrencyCode, double sgtGntramtfc) { public EvaluatedCurrencyReponse getEvaluatedCurrency(String porOrgacode, String baseCurrencyCode, String targetCurrencyCode, double sgtGntramtfc) {
List<Map> exchangeRateList = (List<Map>) ucoAccountService.fetchExchangeRate(porOrgacode); double pkrAmt = convertToPKR(baseCurrencyCode,sgtGntramtfc,porOrgacode);
Map<String, Double> exchangeRates = new HashMap<>(); double convertFromPkr = convertFromPKR(targetCurrencyCode,pkrAmt,porOrgacode);
for (Map rateEntry : exchangeRateList) { List<ExchangeRateModel> exchangeRateModelList = fetchExchangeRate(porOrgacode);
String currencyCode = (String) rateEntry.get("pcrCurrcode");
Double rate = (Double) rateEntry.get("perEratrateact"); Optional<Double> rate = exchangeRateModelList.stream()
exchangeRates.put(currencyCode, rate); .filter(x -> x.isPcrCurrbase() && x.getPcrCurrcode().equals(targetCurrencyCode))
.map(x -> {
BigDecimal bd = BigDecimal.valueOf(1 / x.getPerEratrateact());
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.doubleValue();
})
.findFirst();
if (!rate.isPresent()) {
rate = exchangeRateModelList.stream()
.filter(x -> !x.isPcrCurrbase() && x.getPcrCurrcode().equals(targetCurrencyCode))
.map(x -> {
BigDecimal bd = BigDecimal.valueOf(x.getPerEratrateact());
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.doubleValue();
})
.findFirst();
} }
double convertedAmount = convertCurrency(baseCurrencyCode, targetCurrencyCode, sgtGntramtfc, exchangeRates); double targetPerEratrateact = rate.orElse(0.0);
return EvaluatedCurrencyReponse.builder()
.pcrCurrcode(targetCurrencyCode)
.sgtGntramtfc(convertedAmount)
.serviceCharges(0.0)
.targetPerEratrateact(targetCurrencyCode.equals("default") ? (1 / exchangeRates.get(baseCurrencyCode)) : exchangeRates.get(targetCurrencyCode))
.build();
}
public double convertCurrency(String baseCurrencyCode, String targetCurrencyCode, double amount, Map<String, Double> exchangeRates) {
if (baseCurrencyCode.equals(targetCurrencyCode)) {
return amount;
}
if (baseCurrencyCode.equals("default")) {
return exchangeRates.get(targetCurrencyCode) * amount;
} else if (targetCurrencyCode.equals("default")) {
return exchangeRates.get(baseCurrencyCode) * amount;
}
if (!exchangeRates.containsKey(baseCurrencyCode) || !exchangeRates.containsKey(targetCurrencyCode)) {
throw new IllegalArgumentException("Unsupported currency code");
}
double amountInPKR = amount * exchangeRates.get(baseCurrencyCode); return EvaluatedCurrencyReponse.builder()
double amountInTargetCurrency = amountInPKR / exchangeRates.get(targetCurrencyCode); .targetPerEratrateact(targetPerEratrateact)
return amountInTargetCurrency; .serviceCharges(0.0)
.pcrCurrcode(targetCurrencyCode)
.sgtGntramtfc(BigDecimal.valueOf(convertFromPkr).setScale(2, RoundingMode.HALF_UP))
.build();
} }

@ -9,6 +9,7 @@ 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;
import com.mfsys.uco.exception.CustomerAccountOpeningNotAllowedException;
import com.mfsys.uco.exception.UserAlreadyRegisteredException; import com.mfsys.uco.exception.UserAlreadyRegisteredException;
import com.mfsys.uco.model.AccountId; import com.mfsys.uco.model.AccountId;
import com.mfsys.uco.model.CustomerProfile; import com.mfsys.uco.model.CustomerProfile;
@ -130,7 +131,16 @@ public class UcoAccountService {
public void addUcoAccount(AddAccountRequestModel addAccountRequestModel){ public void addUcoAccount(AddAccountRequestModel addAccountRequestModel){
String porOrgacode = addAccountRequestModel.getPorOrgacode(); String porOrgacode = addAccountRequestModel.getPorOrgacode();
CustomerProfile customerProfile = customerProfileRepository.findCustomerProfileByCmpEmailAndPorOrgacode(porOrgacode,addAccountRequestModel.getEmail()); CustomerProfile customerProfile = customerProfileRepository.findCustomerProfileByCmpEmailAndPorOrgacode(porOrgacode,addAccountRequestModel.getEmail());
if(Objects.nonNull(customerProfile)){
List<UcoAccount> ucoAccountList = ucoAccountRepository.findUcoAccountByCmpCustcode(customerProfile.getPorOrgacode(),customerProfile.getCmpCustcode());
ucoAccountList.stream().forEach(acc->{
if(acc.getDmpProdcode().equals(addAccountRequestModel.getDmpProdcode())){
throw new CustomerAccountOpeningNotAllowedException();
}
});
}
String accountNumber = webClientDeposit.createUcoAccount(JsonToString(Map.of("payload",preparePayloadForAccount(customerProfile,addAccountRequestModel.getTitle()), 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); "uniqueConstraints",List.of(List.of(String.valueOf(addAccountRequestModel.getDmpProdcode()))))),UCOURI.UCO_CUSTOMER_ACCOUNT,porOrgacode);
saveCustomerAccountDetails(porOrgacode,customerProfile.getCmpCustcode(),accountNumber); saveCustomerAccountDetails(porOrgacode,customerProfile.getCmpCustcode(),accountNumber);

Loading…
Cancel
Save