Commit 091baf63 by zhangxingmin

Merge remote-tracking branch 'origin/test' into test

parents aef9677b a1cca7ee
...@@ -47,6 +47,8 @@ import java.io.IOException; ...@@ -47,6 +47,8 @@ import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -287,10 +289,6 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -287,10 +289,6 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
commissionExpected.setPaidRatio(BigDecimal.ZERO); commissionExpected.setPaidRatio(BigDecimal.ZERO);
// 校验参数 // 校验参数
validCommissionExpected(commissionExpected, true); validCommissionExpected(commissionExpected, true);
// 结算汇率初始值为 1
commissionExpected.setDefaultExchangeRate(BigDecimal.valueOf(1));
// 查询默认结算汇率
commissionExpected.setDefaultExchangeRate(queryDefaultExchangeRate(addDto.getCurrency()));
// 预计总金额 // 预计总金额
if ("R".equals(addDto.getCommissionBizType())) { if ("R".equals(addDto.getCommissionBizType())) {
...@@ -298,9 +296,17 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -298,9 +296,17 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
if (ObjectUtils.isEmpty(policy)) { if (ObjectUtils.isEmpty(policy)) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "保单号为" + addDto.getPolicyNo() + "的保单不存在"); 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() BigDecimal expectedAmount = policy.getPaymentPremium()
.multiply(commissionExpected.getCommissionRatio()) .multiply(commissionExpected.getCommissionRatio())
.multiply(commissionExpected.getDefaultExchangeRate()) .multiply(commissionExpected.getDefaultExchangeRate())
.multiply(exchangeRateHkd)
.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP); .divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP);
commissionExpected.setExpectedAmount(expectedAmount); commissionExpected.setExpectedAmount(expectedAmount);
...@@ -368,21 +374,6 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -368,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 @Override
public Boolean deleteCommissionExpected(String commissionExpectedBizId) { public Boolean deleteCommissionExpected(String commissionExpectedBizId) {
if (StringUtils.isBlank(commissionExpectedBizId)) { if (StringUtils.isBlank(commissionExpectedBizId)) {
...@@ -408,8 +399,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -408,8 +399,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
validCommissionExpected(commissionExpected, false); validCommissionExpected(commissionExpected, false);
// 转换为实体类 // 转换为实体类
BeanUtils.copyProperties(commissionExpectedUpdateRequest, commissionExpected, "id", "commissionBizId"); BeanUtils.copyProperties(commissionExpectedUpdateRequest, commissionExpected, "id", "commissionBizId");
// 更新默认结算汇率
commissionExpected.setDefaultExchangeRate(queryDefaultExchangeRate(commissionExpectedUpdateRequest.getCurrency()));
// 更新预计入账金额 // 更新预计入账金额
if ("R".equals(commissionExpectedUpdateRequest.getCommissionBizType())) { if ("R".equals(commissionExpectedUpdateRequest.getCommissionBizType())) {
// 查询保单 // 查询保单
...@@ -417,10 +407,16 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -417,10 +407,16 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
if (policy == null) { if (policy == null) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), "保单不存在"); throw new BusinessException(ResultCode.NULL_ERROR.getCode(), "保单不存在");
} }
// 更新默认结算汇率
commissionExpected.setDefaultExchangeRate(queryExchangeRateByFeign(policy.getCurrency(), commissionExpectedUpdateRequest.getCurrency()));
// 查询港币汇率
BigDecimal exchangeRateHkd = queryExchangeRateByFeign(commissionExpectedUpdateRequest.getCurrency(), "HKD");
// 转换为港币金额
commissionExpected.setExpectedAmount( commissionExpected.setExpectedAmount(
policy.getPaymentPremium() policy.getPaymentPremium()
.multiply(commissionExpectedUpdateRequest.getCommissionRatio()) .multiply(commissionExpectedUpdateRequest.getCommissionRatio())
.multiply(commissionExpected.getDefaultExchangeRate()) .multiply(commissionExpected.getDefaultExchangeRate())
.multiply(exchangeRateHkd)
.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP) .divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP)
); );
commissionExpected.setPremium(policy.getPaymentPremium()); commissionExpected.setPremium(policy.getPaymentPremium());
...@@ -514,7 +510,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -514,7 +510,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
// 匹配规格并获取不匹配的条件 // 匹配规格并获取不匹配的条件
MatchResult matchResult = matchExpectedSpecies( MatchResult matchResult = matchExpectedSpecies(
expectedSpeciesList, paymentTerm, reconciliationCompanyBizId, expectedSpeciesList, paymentTerm, reconciliationCompanyBizId,
policyHolderAge, paymentPremium); policyHolderAge, paymentPremium, effectiveDate);
if (matchResult.getMatchedList().isEmpty()) { if (matchResult.getMatchedList().isEmpty()) {
String errorMsg = matchResult.getUnmatchedConditions().isEmpty() String errorMsg = matchResult.getUnmatchedConditions().isEmpty()
...@@ -611,7 +607,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -611,7 +607,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
*/ */
private MatchResult matchExpectedSpecies(List<ApiExpectedSpeciesListResponse> expectedSpeciesList, private MatchResult matchExpectedSpecies(List<ApiExpectedSpeciesListResponse> expectedSpeciesList,
String paymentTerm, String reconciliationCompanyId, String paymentTerm, String reconciliationCompanyId,
Integer policyHolderAge, BigDecimal paymentPremium) { Integer policyHolderAge, BigDecimal paymentPremium, Date effectiveDate) {
List<String> unmatchedConditions = new ArrayList<>(); List<String> unmatchedConditions = new ArrayList<>();
List<ApiExpectedSpeciesListResponse> currentList = expectedSpeciesList; List<ApiExpectedSpeciesListResponse> currentList = expectedSpeciesList;
...@@ -644,9 +640,22 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -644,9 +640,22 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
i -> containsValue(i.getSpeciesJson(), "PREMIUM", Convert.toStr(paymentPremium)), i -> containsValue(i.getSpeciesJson(), "PREMIUM", Convert.toStr(paymentPremium)),
unmatchedConditions, "保费[" + paymentPremium + "]"); unmatchedConditions, "保费[" + paymentPremium + "]");
// 检查生效日期
currentList = filterAndCheck(currentList,
i -> isEffective(i.getEffectiveStart(), i.getEffectiveEnd(), effectiveDate),
unmatchedConditions, "生效日期[" + effectiveDate + "]");
if (unmatchedConditions.size() > 0) {
return new MatchResult(Collections.emptyList(), unmatchedConditions);
}
return new MatchResult(currentList, unmatchedConditions); return new MatchResult(currentList, unmatchedConditions);
} }
private boolean isEffective(LocalDateTime effectiveStart, LocalDateTime effectiveEnd, Date effectiveDate) {
LocalDateTime effectiveDateLocal = effectiveDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
return effectiveDateLocal.isAfter(effectiveStart) && effectiveDateLocal.isBefore(effectiveEnd);
}
/** /**
* 过滤列表并检查是否为空 * 过滤列表并检查是否为空
* *
...@@ -751,7 +760,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -751,7 +760,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
if ("R".equals(commissionBizType)) { if ("R".equals(commissionBizType)) {
// 关联保单应收单:保费 × 佣金比例 × 默认结算汇率 ÷ 100 // 关联保单应收单:保费 × 佣金比例 × 默认结算汇率 ÷ 100
BigDecimal exchangeRate = defaultExchangeRate; BigDecimal exchangeRate = defaultExchangeRate;
BigDecimal exchangeRateHkd = queryDefaultExchangeRate(currency); BigDecimal exchangeRateHkd = queryExchangeRateByFeign(currency, "HKD");
if (exchangeRate == null) { if (exchangeRate == null) {
// 这里获取保单币种对预计来佣的结算币种的默认汇率 // 这里获取保单币种对预计来佣的结算币种的默认汇率
exchangeRate = queryExchangeRateByFeign(policyCurrency, currency); exchangeRate = queryExchangeRateByFeign(policyCurrency, currency);
...@@ -765,7 +774,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -765,7 +774,7 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
// 非关联保单应收单:金额 × 默认结算汇率 // 非关联保单应收单:金额 × 默认结算汇率
BigDecimal exchangeRate = defaultExchangeRate; BigDecimal exchangeRate = defaultExchangeRate;
if (exchangeRate == null) { if (exchangeRate == null) {
exchangeRate = queryDefaultExchangeRate(currency); exchangeRate = queryExchangeRateByFeign(policyCurrency, currency);
} }
return amount.multiply(exchangeRate); return amount.multiply(exchangeRate);
} }
...@@ -778,6 +787,9 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte ...@@ -778,6 +787,9 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
* @return 汇率 * @return 汇率
*/ */
private BigDecimal queryExchangeRateByFeign(String policyCurrency, String currency) { private BigDecimal queryExchangeRateByFeign(String policyCurrency, String currency) {
if (policyCurrency.equalsIgnoreCase(currency)) {
return BigDecimal.valueOf(1);
}
// 调用Feign客户端查询汇率 // 调用Feign客户端查询汇率
Result<BigDecimal> result = apiExchangeRateFeignClient.getExchangeRate(policyCurrency, currency, ""); Result<BigDecimal> result = apiExchangeRateFeignClient.getExchangeRate(policyCurrency, currency, "");
if (result != null && result.getData() != null) { if (result != null && result.getData() != null) {
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
then round((ifnull(sum(ce.expected_amount), 0) - ifnull(sum(ce.paid_amount), 0)) / ifnull(sum(ce.expected_amount), 0) * 100, 2) then round((ifnull(sum(ce.expected_amount), 0) - ifnull(sum(ce.paid_amount), 0)) / ifnull(sum(ce.expected_amount), 0) * 100, 2)
else 0 else 0
end as unpaidRatio, 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.insurance_company) as insuranceCompany,
MAX(p.product_name) as productName, MAX(p.product_name) as productName,
ifnull(avg(ce.premium), 0) as premium, 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