Commit 7e01dcb6 by jianan

新单跟进v2

parent 55eb1a25
......@@ -45,6 +45,7 @@ import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
......@@ -509,21 +510,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
@Override
public Boolean addFortune(FortuneAddRequest fortuneAddRequest) {
if (ObjectUtils.isEmpty(fortuneAddRequest.getFortuneBizType())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账类型不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getAmount())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账金额不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getCurrency())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账币种不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getFortuneType())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账项目不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getBrokerBizId())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "转介人不能为空");
}
valiAddFortune(fortuneAddRequest);
// 创建Fortune实体
Fortune fortune = new Fortune();
......@@ -571,6 +558,32 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
return this.save(fortune);
}
private static void valiAddFortune(FortuneAddRequest fortuneAddRequest) {
if (ObjectUtils.isEmpty(fortuneAddRequest.getFortuneBizType())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账类型不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getAmount())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账金额不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getCurrency())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账币种不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getFortuneType())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "出账项目不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getBrokerBizId())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "转介人不能为空");
}
if ("R".equals(fortuneAddRequest.getFortuneBizType())) {
if (ObjectUtils.isEmpty(fortuneAddRequest.getPolicyNo())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "关联保单应付款,保单号不能为空");
}
if (ObjectUtils.isEmpty(fortuneAddRequest.getFortunePeriod())) {
throw new BusinessException(ResultCode.FAIL.getCode(), "关联保单应付款,佣金期数不能为空");
}
}
}
private String queryByDict(String fortuneType) {
//查询redis缓存的字典列表信息
List<GetDictItemListByDictTypeResponse> dictTypeResponses = redisUtil.getCacheObject(RedisConstants.DICT_LIST);
......@@ -644,12 +657,56 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
return false;
}
Set<String> policyNoSet = fortuneAddRequestList.stream()
.map(FortuneAddRequest::getPolicyNo)
.filter(StringUtils::isNotBlank).collect(Collectors.toSet());
// 查询预计出账
Map<String, ExpectedFortune> expectedFortuneMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(policyNoSet)) {
expectedFortuneMap = expectedFortuneService.lambdaQuery()
.in(ExpectedFortune::getPolicyNo, policyNoSet)
.list()
.stream()
.collect(Collectors.toMap(
i -> i.getPolicyNo() + "_" + i.getFortuneType() + "_" + i.getFortuneType(),
Function.identity(),
(oldValue, newValue) -> newValue)
);
}
List<Fortune> fortuneList = new ArrayList<>();
for (FortuneAddRequest fortuneAddRequest : fortuneAddRequestList) {
// 校验参数
valiAddFortune(fortuneAddRequest);
Fortune fortune = new Fortune();
BeanUtil.copyProperties(fortuneAddRequest, fortune);
if ("R".equals(fortuneAddRequest.getFortuneBizType())) {
ExpectedFortune expectedFortune = expectedFortuneMap.get(fortuneAddRequest.getPolicyNo() + "_" + fortuneAddRequest.getFortuneType() + "_" + fortuneAddRequest.getFortuneType());
if (expectedFortune == null) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), fortuneAddRequest.getFortuneName() + " 预计出账不存在");
}
fortune.setExpectedFortuneBizId(expectedFortune.getExpectedFortuneBizId());
fortune.setCommissionExpectedBizId(expectedFortune.getExpectedFortuneBizId());
fortune.setPolicyCurrency(expectedFortune.getPolicyCurrency());
fortune.setExchangeRate(expectedFortune.getDefaultExchangeRate());
fortune.setHkdAmount(fortuneAddRequest.getAmount().multiply(expectedFortune.getDefaultExchangeRate()));
fortune.setCurrentPaymentHkdAmount(fortune.getHkdAmount());
fortune.setPayoutDate(expectedFortune.getPayoutDate());
} else {
fortune.setExchangeRate(queryDefaultExchangeRate(fortuneAddRequest.getCurrency()));
fortune.setHkdAmount(fortuneAddRequest.getAmount().multiply(fortune.getExchangeRate()));
fortune.setCurrentPaymentHkdAmount(fortune.getHkdAmount());
}
// 生成发佣业务ID
fortune.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode()));
fortune.setCurrentPaymentAmount(fortuneAddRequest.getAmount());
fortune.setFortuneName(queryByDict(fortuneAddRequest.getFortuneType()));
fortune.setActualPayoutDate(fortuneAddRequest.getPayoutDate());
fortune.setIsPart(0);
fortune.setStatus(FortuneStatusEnum.WAIT.getItemValue());
fortuneList.add(fortune);
}
......
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