Commit a1cca7ee by jianan

Merge branch 'refs/heads/test_policy_follow' into test

parents 13dbdee7 4680d228
......@@ -289,10 +289,6 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
commissionExpected.setPaidRatio(BigDecimal.ZERO);
// 校验参数
validCommissionExpected(commissionExpected, true);
// 结算汇率初始值为 1
commissionExpected.setDefaultExchangeRate(BigDecimal.valueOf(1));
// 查询默认结算汇率
commissionExpected.setDefaultExchangeRate(queryDefaultExchangeRate(addDto.getCurrency()));
// 预计总金额
if ("R".equals(addDto.getCommissionBizType())) {
......@@ -300,9 +296,17 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
if (ObjectUtils.isEmpty(policy)) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "保单号为" + addDto.getPolicyNo() + "的保单不存在");
}
// 结算汇率初始值为 1
commissionExpected.setDefaultExchangeRate(BigDecimal.valueOf(1));
// 查询默认结算汇率
commissionExpected.setDefaultExchangeRate(queryExchangeRateByFeign(policy.getCurrency(), addDto.getCurrency()));
// 查询港币汇率
BigDecimal exchangeRateHkd = queryExchangeRateByFeign(addDto.getCurrency(), "HKD");
// 转换为港币金额
BigDecimal expectedAmount = policy.getPaymentPremium()
.multiply(commissionExpected.getCommissionRatio())
.multiply(commissionExpected.getDefaultExchangeRate())
.multiply(exchangeRateHkd)
.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP);
commissionExpected.setExpectedAmount(expectedAmount);
......@@ -370,21 +374,6 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
}
}
private BigDecimal queryDefaultExchangeRate(String currency) {
if ("HKD".equalsIgnoreCase(currency)) {
return BigDecimal.valueOf(1);
}
Result<List<GetDictItemListByDictTypeResponse>> result = apiSysDictFeignClient.getDictItemListByDictType("csf_exchange_rate_hkd");
if (CollectionUtils.isNotEmpty(result.getData())) {
for (GetDictItemListByDictTypeResponse dictItem : result.getData()) {
if (StringUtils.equalsIgnoreCase(dictItem.getItemLabel(), currency)) {
return new BigDecimal(dictItem.getItemValue());
}
}
}
return BigDecimal.ONE;
}
@Override
public Boolean deleteCommissionExpected(String commissionExpectedBizId) {
if (StringUtils.isBlank(commissionExpectedBizId)) {
......@@ -410,8 +399,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
validCommissionExpected(commissionExpected, false);
// 转换为实体类
BeanUtils.copyProperties(commissionExpectedUpdateRequest, commissionExpected, "id", "commissionBizId");
// 更新默认结算汇率
commissionExpected.setDefaultExchangeRate(queryDefaultExchangeRate(commissionExpectedUpdateRequest.getCurrency()));
// 更新预计入账金额
if ("R".equals(commissionExpectedUpdateRequest.getCommissionBizType())) {
// 查询保单
......@@ -419,10 +407,16 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
if (policy == null) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), "保单不存在");
}
// 更新默认结算汇率
commissionExpected.setDefaultExchangeRate(queryExchangeRateByFeign(policy.getCurrency(), commissionExpectedUpdateRequest.getCurrency()));
// 查询港币汇率
BigDecimal exchangeRateHkd = queryExchangeRateByFeign(commissionExpectedUpdateRequest.getCurrency(), "HKD");
// 转换为港币金额
commissionExpected.setExpectedAmount(
policy.getPaymentPremium()
.multiply(commissionExpectedUpdateRequest.getCommissionRatio())
.multiply(commissionExpected.getDefaultExchangeRate())
.multiply(exchangeRateHkd)
.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP)
);
commissionExpected.setPremium(policy.getPaymentPremium());
......@@ -766,7 +760,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
if ("R".equals(commissionBizType)) {
// 关联保单应收单:保费 × 佣金比例 × 默认结算汇率 ÷ 100
BigDecimal exchangeRate = defaultExchangeRate;
BigDecimal exchangeRateHkd = queryDefaultExchangeRate(currency);
BigDecimal exchangeRateHkd = queryExchangeRateByFeign(currency, "HKD");
if (exchangeRate == null) {
// 这里获取保单币种对预计来佣的结算币种的默认汇率
exchangeRate = queryExchangeRateByFeign(policyCurrency, currency);
......@@ -780,7 +774,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
// 非关联保单应收单:金额 × 默认结算汇率
BigDecimal exchangeRate = defaultExchangeRate;
if (exchangeRate == null) {
exchangeRate = queryDefaultExchangeRate(currency);
exchangeRate = queryExchangeRateByFeign(policyCurrency, currency);
}
return amount.multiply(exchangeRate);
}
......@@ -793,6 +787,9 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
* @return 汇率
*/
private BigDecimal queryExchangeRateByFeign(String policyCurrency, String currency) {
if (policyCurrency.equalsIgnoreCase(currency)) {
return BigDecimal.valueOf(1);
}
// 调用Feign客户端查询汇率
Result<BigDecimal> result = apiExchangeRateFeignClient.getExchangeRate(policyCurrency, currency, "");
if (result != null && result.getData() != null) {
......
......@@ -87,7 +87,7 @@
then round((ifnull(sum(ce.expected_amount), 0) - ifnull(sum(ce.paid_amount), 0)) / ifnull(sum(ce.expected_amount), 0) * 100, 2)
else 0
end as unpaidRatio,
ifnull(avg(ce.default_exchange_rate), 0) as exchangeRate,
MAX(ce.default_exchange_rate) as exchangeRate,
MAX(p.insurance_company) as insuranceCompany,
MAX(p.product_name) as productName,
ifnull(avg(ce.premium), 0) as premium,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment