Commit 55eb1a25 by jianan

新单跟进v2

parent 35783e97
package com.yd.csf.api.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
......@@ -29,6 +30,7 @@ import com.yd.csf.service.dto.QueryPolicyBrokerDto;
import com.yd.csf.service.enums.FortuneStatusEnum;
import com.yd.csf.service.model.CommissionRuleBinding;
import com.yd.csf.service.model.ExpectedFortune;
import com.yd.csf.service.model.Policy;
import com.yd.csf.service.model.PolicyBroker;
import com.yd.csf.service.service.ICommissionRuleBindingService;
import com.yd.csf.service.service.IExpectedFortuneService;
......@@ -59,6 +61,7 @@ import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
......@@ -670,6 +673,18 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
}
validateAdd(fortuneAddRequestList);
// 查询保单信息
Set<String> policyNoSet = fortuneAddRequestList.stream()
.map(ExpectedFortuneAddRequest::getPolicyNo)
.filter(StringUtils::isNotBlank).collect(Collectors.toSet());
Map<String, Policy> policyMap = new HashMap<>();
if (CollUtil.isNotEmpty(policyNoSet)) {
List<Policy> policyList = policyService.lambdaQuery().in(Policy::getPolicyNo, policyNoSet).list();
// 保单映射
policyMap = policyList.stream().collect(Collectors.toMap(Policy::getPolicyNo, Function.identity()));
}
// 查询最新一条有 payableNo 记录
ExpectedFortune latest = iExpectedFortuneService.getOne(
new QueryWrapper<ExpectedFortune>().isNotNull("payable_no").orderByDesc("id").last("LIMIT 1"),
......@@ -686,8 +701,23 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
ExpectedFortune expectedFortune = new ExpectedFortune();
BeanUtil.copyProperties(expectedFortuneDto, expectedFortune);
if ("R".equals(expectedFortuneDto.getFortuneBizType())) {
Policy policy = policyMap.get(expectedFortuneDto.getPolicyNo());
if (ObjectUtils.isEmpty(policy)) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "保单号为" + expectedFortuneDto.getPolicyNo() + "的保单不存在");
}
// 设置关联字段
expectedFortune.setInsuranceCompanyBizId(policy.getInsuranceCompanyBizId());
expectedFortune.setProductLaunchBizId(policy.getProductLaunchBizId());
expectedFortune.setPremium(policy.getPaymentPremium());
expectedFortune.setPolicyCurrency(policy.getCurrency());
}
// 预计发佣业务id
expectedFortune.setExpectedFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_EXPECTED_FORTUNE.getCode()));
// 预计发佣类型名称
expectedFortune.setFortuneName(queryByDict(expectedFortuneDto.getFortuneType()));
// 应付款编号(序号递增)
expectedFortune.setPayableNo(this.createPayableNo(expectedFortune.getFortuneBizType(), ++currentSeq));
// 默认结算汇率
......@@ -696,6 +726,8 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
expectedFortune.setHkdAmount(expectedFortune.getAmount().multiply(expectedFortune.getDefaultExchangeRate()));
// 已出帐金额、待出帐金额、已出帐比例、待出帐比例
expectedFortune.setPaidAmount(BigDecimal.ZERO);
// 转介人比例默认100%
expectedFortune.setBrokerRatio("100");
expectedFortune.setUnpaidAmount(expectedFortune.getAmount());
expectedFortune.setPaidRatio(BigDecimal.ZERO);
expectedFortune.setUnpaidRatio(BigDecimal.valueOf(100));
......@@ -705,6 +737,25 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
return true;
}
private String queryByDict(String fortuneType) {
//查询redis缓存的字典列表信息
List<GetDictItemListByDictTypeResponse> dictTypeResponses = redisUtil.getCacheObject(RedisConstants.DICT_LIST);
String fortuneName = GetDictItemListByDictTypeResponse.getItemLabel(dictTypeResponses,
"csf_fortune_type", fortuneType);
if (ObjectUtils.isNotEmpty(fortuneName)) {
return fortuneName;
}
Result<List<GetDictItemListByDictTypeResponse>> result = apiSysDictFeignClient.getDictItemListByDictType("csf_fortune_type");
if (ObjectUtils.isNotEmpty(result.getData())) {
for (GetDictItemListByDictTypeResponse dictItem : result.getData()) {
if (StringUtils.equalsIgnoreCase(dictItem.getItemValue(), fortuneType)) {
return dictItem.getItemLabel();
}
}
}
return null;
}
private BigDecimal queryDefaultExchangeRate(String currency) {
if ("HKD".equalsIgnoreCase(currency)) {
return BigDecimal.valueOf(1);
......
......@@ -255,22 +255,16 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
}
validateAddCommissionExpected(addDtoList);
// 查询保单信息、保单产品信息
// 查询保单信息
Set<String> policyNoSet = addDtoList.stream()
.map(CommissionExpectedAddDto::getPolicyNo)
.filter(StringUtils::isNotBlank).collect(Collectors.toSet());
Map<String, Policy> policyMap = new HashMap<>();
Map<String, PolicyProductInfo> policyProductInfoMap = new HashMap<>();
if (CollUtil.isNotEmpty(policyNoSet)) {
List<Policy> policyList = policyService.lambdaQuery().in(Policy::getPolicyNo, policyNoSet).list();
// 保单映射
policyMap = policyList.stream().collect(Collectors.toMap(Policy::getPolicyNo, Function.identity()));
// 关联查询保单产品信息
Set<String> productLaunchBizIdSet = policyList.stream()
.map(Policy::getProductLaunchBizId)
.collect(Collectors.toSet());
// policyProductInfoMap = policyService.getPolicyProductInfoMap(productLaunchBizIdSet);
}
List<CommissionExpected> addList = new ArrayList<>();
......
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