Commit 29d4f5ce by jianan

新单跟进同步预约信息4

parent 8c4ee699
......@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yd.base.feign.client.exchangerate.ApiExchangeRateFeignClient;
import com.yd.common.constant.CommonConstant;
import com.yd.common.constant.RedisConstants;
......@@ -41,6 +43,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
......@@ -77,6 +80,9 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
@Resource
private ApiExchangeRateFeignClient apiExchangeRateFeignClient;
// 用于对象转换的ObjectMapper
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
public Page<CommissionExpectedVO> getCommissionExpectedVOPage(Page<CommissionExpected> commissionExpectedPage) {
......@@ -481,6 +487,10 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
if (paymentPremium == null) {
throw new BusinessException("保费不能为空");
}
Integer policyHolderAge = policy.getPolicyHolderAge();
if (policyHolderAge == null) {
throw new BusinessException("保單持有人年齡不能为空");
}
Date effectiveDate = policy.getEffectiveDate();
if (effectiveDate == null) {
throw new BusinessException("保单生效日期不能为空");
......@@ -501,22 +511,25 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
List<CommissionExpected> commissionExpectedList = new ArrayList<>();
if (CollUtil.isNotEmpty(expectedSpeciesList)) {
// 根据供款年期匹配规格
List<ApiExpectedSpeciesListResponse> collect = expectedSpeciesList.stream()
.filter(i -> paymentTerm.equals(i.getPaymentTerm()))
.collect(Collectors.toList());
if (ObjectUtils.isEmpty(collect)) {
throw new BusinessException(ResultCode.FAIL.getCode(), "未查询到对应供款年期的佣金规格");
// 匹配规格并获取不匹配的条件
MatchResult matchResult = matchExpectedSpecies(
expectedSpeciesList, paymentTerm, reconciliationCompanyBizId,
policyHolderAge, paymentPremium);
if (matchResult.getMatchedList().isEmpty()) {
String errorMsg = matchResult.getUnmatchedConditions().isEmpty()
? "未查询到对应供款年期的佣金规格"
: "未查询到对应供款年期的佣金规格,不匹配条件:" + String.join("、", matchResult.getUnmatchedConditions());
throw new BusinessException(ResultCode.FAIL.getCode(), errorMsg);
}
// 计算佣金总期数 list 中 endPeriod最大值
Integer maxEndPeriod = collect.stream()
Integer maxEndPeriod = matchResult.getMatchedList().stream()
.map(item -> Convert.toInt(item.getEndPeriod()))
.max(Integer::compareTo)
.orElse(0);
for (ApiExpectedSpeciesListResponse item : collect) {
for (ApiExpectedSpeciesListResponse item : matchResult.getMatchedList()) {
CommissionExpected commissionExpected = new CommissionExpected();
commissionExpected.setCommissionExpectedBizId(RandomStringGenerator.generateBizId16("commission_expected"));
commissionExpected.setReceivableNo(receivableService.generateReceivableNo("R", reconciliationCompanyCode, reconciliationCompany));
......@@ -565,6 +578,140 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
}
}
/**
* 匹配规格结果内部类
*/
private static class MatchResult {
private List<ApiExpectedSpeciesListResponse> matchedList;
private List<String> unmatchedConditions;
public MatchResult(List<ApiExpectedSpeciesListResponse> matchedList, List<String> unmatchedConditions) {
this.matchedList = matchedList;
this.unmatchedConditions = unmatchedConditions;
}
public List<ApiExpectedSpeciesListResponse> getMatchedList() {
return matchedList;
}
public List<String> getUnmatchedConditions() {
return unmatchedConditions;
}
}
/**
* 匹配预计规格并返回不匹配的条件
*
* @param expectedSpeciesList 预计规格列表
* @param paymentTerm 供款年期
* @param reconciliationCompanyId 对账公司ID
* @param policyHolderAge 保单持有人年龄
* @param paymentPremium 年缴保费
* @return 匹配结果
*/
private MatchResult matchExpectedSpecies(List<ApiExpectedSpeciesListResponse> expectedSpeciesList,
String paymentTerm, String reconciliationCompanyId,
Integer policyHolderAge, BigDecimal paymentPremium) {
List<String> unmatchedConditions = new ArrayList<>();
List<ApiExpectedSpeciesListResponse> currentList = expectedSpeciesList;
// 检查供款年期
currentList = filterAndCheck(currentList,
i -> paymentTerm.equals(i.getPaymentTerm()),
unmatchedConditions, "供款年期[" + paymentTerm + "]");
if (unmatchedConditions.size() > 0) {
return new MatchResult(Collections.emptyList(), unmatchedConditions);
}
// 检查对账公司
currentList = filterAndCheck(currentList,
i -> reconciliationCompanyId.equals(i.getReconciliationCompany()),
unmatchedConditions, "对账公司[" + reconciliationCompanyId + "]");
if (unmatchedConditions.size() > 0) {
return new MatchResult(Collections.emptyList(), unmatchedConditions);
}
// 检查年龄
currentList = filterAndCheck(currentList,
i -> containsValue(i.getSpeciesJson(), "AGE", Convert.toStr(policyHolderAge)),
unmatchedConditions, "年龄[" + policyHolderAge + "]");
if (unmatchedConditions.size() > 0) {
return new MatchResult(Collections.emptyList(), unmatchedConditions);
}
// 检查保费
currentList = filterAndCheck(currentList,
i -> containsValue(i.getSpeciesJson(), "PREMIUM", Convert.toStr(paymentPremium)),
unmatchedConditions, "保费[" + paymentPremium + "]");
return new MatchResult(currentList, unmatchedConditions);
}
/**
* 过滤列表并检查是否为空
*
* @param list 待过滤的列表
* @param predicate 过滤条件
* @param unmatchedConditions 不匹配条件列表
* @param conditionDesc 条件描述
* @return 过滤后的列表
*/
private List<ApiExpectedSpeciesListResponse> filterAndCheck(
List<ApiExpectedSpeciesListResponse> list,
java.util.function.Predicate<ApiExpectedSpeciesListResponse> predicate,
List<String> unmatchedConditions, String conditionDesc) {
List<ApiExpectedSpeciesListResponse> filtered = list.stream()
.filter(predicate)
.collect(Collectors.toList());
if (filtered.isEmpty()) {
unmatchedConditions.add(conditionDesc);
}
return filtered;
}
private static boolean containsValue(String json, String targetKey, String targetValue) {
if (json == null || json.trim().isEmpty()) return false;
try {
List<Map<String, Object>> params = objectMapper.readValue(json, new TypeReference<List<Map<String, Object>>>() {});
// AGE 和 PREMIUM 使用最小值匹配(targetValue >= value)
if (targetKey.equals("AGE") || targetKey.equals("PREMIUM")) {
return params.stream().anyMatch(p -> {
Object value = p.get("value");
if (value == null) {
return false;
}
// 转换为 BigDecimal
BigDecimal threshold;
if (value instanceof BigDecimal) {
threshold = (BigDecimal) value;
} else if (value instanceof Number) {
threshold = BigDecimal.valueOf(((Number) value).doubleValue());
} else if (value instanceof String) {
try {
threshold = new BigDecimal((String) value);
} catch (NumberFormatException e) {
return false;
}
} else {
return false;
}
// 判断是否大于等于最小值
return new BigDecimal(targetValue).compareTo(threshold) >= 0;
});
}
// 其他字段使用等于匹配
else {
return params.stream().anyMatch(p -> targetValue.equals(p.get("value")));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
@Override
public List<ApiExpectedSpeciesListResponse> queryExpectedSpeciesByFeign(String productLaunchBizId) {
ApiExpectedSpeciesListRequest apiExpectedSpeciesListRequest = new ApiExpectedSpeciesListRequest();
......
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