Commit a139ccd6 by zhangxingmin

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

parents a3f1ed10 e6856d4f
......@@ -33,6 +33,7 @@ import com.yd.csf.service.dto.QueryPolicyBrokerDto;
import com.yd.csf.service.dto.UserGradeDto;
import com.yd.csf.service.enums.CurrencyEnum;
import com.yd.csf.service.enums.FortuneStatusEnum;
import com.yd.csf.service.enums.FortuneTypeEnum;
import com.yd.csf.service.helper.FeignResultHelper;
import com.yd.csf.service.model.*;
import com.yd.csf.service.service.*;
......@@ -685,7 +686,7 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
ExpectedFortune updateObj = new ExpectedFortune();
updateObj.setId(expectedFortune.getId());
updateObj.setPayableNo(this.createPayableNo("R", expectedFortune.getPayoutDate(), policyNo, expectedFortune.getFortunePeriod()));
updateObj.setPayableNo(iExpectedFortuneService.getPayableNo(expectedFortune.getFortuneType(), policyNo, expectedFortune.getId()));
updateObj.setFortuneType(GetDictItemListByDictTypeResponse.getItemValue(dictTypeResponses,
"csf_fortune_type", expectedFortune.getFortuneName()));
......@@ -1021,14 +1022,10 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
// 查询保单信息
Set<String> policyNoSet = fortuneAddRequestList.stream()
.map(ExpectedFortuneAddRequest::getPolicyNo)
.filter(StringUtils::isNotBlank).collect(Collectors.toSet());
.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()));
}
Map<String, Policy> policyMap = policyService.queryPolicyMap(policyNoSet);
// 查询最新一条有 payableNo 记录
// int currentSeq = iExpectedFortuneService.getPayableNoCurrentSeq();
......@@ -1036,7 +1033,7 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
List<ExpectedFortune> fortuneList = new ArrayList<>();
for (ExpectedFortuneAddRequest expectedFortuneDto : fortuneAddRequestList) {
ExpectedFortune expectedFortune = new ExpectedFortune();
BeanUtil.copyProperties(expectedFortuneDto, expectedFortune);
BeanUtil.copyProperties(expectedFortuneDto, expectedFortune, "payoutDate", "actualPayoutDate");
if ("R".equals(expectedFortuneDto.getFortuneBizType())) {
Policy policy = policyMap.get(expectedFortuneDto.getPolicyNo());
......@@ -1055,9 +1052,10 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
expectedFortune.setExpectedFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_EXPECTED_FORTUNE.getCode()));
// 预计发佣类型名称
expectedFortune.setFortuneName(queryByDict(expectedFortuneDto.getFortuneType()));
// 应付款编号(序号递增)
expectedFortune.setPayableNo(this.createPayableNo(expectedFortune.getFortuneBizType(), expectedFortuneDto.getPayoutDate(), expectedFortuneDto.getPolicyNo(), expectedFortuneDto.getFortunePeriod()));
// 预计出账年月
expectedFortune.setPayoutDate(LocalDate.parse(expectedFortuneDto.getPayoutDate() + "-01"));
// 实际出账年月
expectedFortune.setActualPayoutDate(LocalDate.parse(expectedFortuneDto.getActualPayoutDate() + "-01"));
// 已出帐金额、待出帐金额、已出帐比例、待出帐比例
expectedFortune.setPaidAmount(BigDecimal.ZERO);
......@@ -1069,17 +1067,24 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
fortuneList.add(expectedFortune);
}
iExpectedFortuneService.saveOrUpdateBatch(fortuneList);
// 更新应付款编号
List<ExpectedFortune> updateList = new ArrayList<>();
for (ExpectedFortune expected : fortuneList) {
// 生成应付款编号
String payableNo = iExpectedFortuneService.getPayableNo(expected.getFortuneType(), expected.getPolicyNo(), expected.getId());
ExpectedFortune updateExpected = new ExpectedFortune();
updateExpected.setId(expected.getId());
updateExpected.setPayableNo(payableNo);
updateList.add(updateExpected);
}
iExpectedFortuneService.updateBatchById(updateList);
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()) {
......@@ -1115,15 +1120,29 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
private void validateAdd(List<ExpectedFortuneAddRequest> fortuneAddRequestList) {
for (ExpectedFortuneAddRequest expectedFortuneDto : fortuneAddRequestList) {
if (Objects.isNull(expectedFortuneDto.getHkdAmount())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "预计出账金额不能为空");
if (Objects.isNull(expectedFortuneDto.getOriginalAmount())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "原币种金额不能为空");
}
if (Objects.isNull(expectedFortuneDto.getCurrency())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "预计出账币种不能为空");
if (Objects.isNull(expectedFortuneDto.getOriginalCurrency())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "币种不能为空");
}
if (Objects.isNull(expectedFortuneDto.getExchangeRate())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "结算汇率不能为空");
if (Objects.isNull(expectedFortuneDto.getOriginalToHkdRate())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "原币种→港币汇率不能为空");
}
if (Objects.isNull(expectedFortuneDto.getRuleAmount())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "保单币种金额不能为空");
}
if (Objects.isNull(expectedFortuneDto.getRuleCurrency())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "保单币种不能为空");
}
if (Objects.isNull(expectedFortuneDto.getDefaultExchangeRate())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "预计出账汇率不能为空");
}
if (Objects.isNull(expectedFortuneDto.getHkdAmount())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "预计出账金额不能为空");
}
}
}
......@@ -1212,37 +1231,6 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
}
/**
* 创建应付款编号 应付单类型(R/U)+预计年月+保单号后4位(如不够用0补齐)+出账期数(3位)
*
* @param fortuneBizType 预计发佣业务类型
* @param payoutDate 预计出账日期
* @param policyNo 保单号
* @param fortunePeriod 预计出账期数
* @return
*/
public String createPayableNo(String fortuneBizType, LocalDate payoutDate, String policyNo, int fortunePeriod) {
// 1. 安全获取保单号后4位
String last4Chars = "";
if (policyNo != null && !policyNo.isEmpty()) {
int startIdx = Math.max(0, policyNo.length() - 4);
last4Chars = policyNo.substring(startIdx);
}
// 2. 字符串左补0至4位
// %4s 表示最小宽度为4,不足部分默认用空格填充在左侧
// replace(' ', '0') 将填充的空格替换为0,实现左补0效果
String formattedPolicySuffix = String.format("%4s", last4Chars).replace(' ', '0');
// 3. 组装最终字符串
return String.format("%s%04d%02d%s%03d",
fortuneBizType,
payoutDate.getYear(),
payoutDate.getMonthValue(),
formattedPolicySuffix,
fortunePeriod);
}
/**
* 分页查询 - 预计发佣
*
* @param request
......
......@@ -5,118 +5,84 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
@Data
public class ExpectedFortuneAddRequest {
/**
* 应付款类型 R-关联保单应付款 U-非关联保单应付款
*/
@Schema(description = "应付款类型 R-关联保单应付款 U-非关联保单应付款")
@Schema(description = "应付款类型 R-关联保单应付款 U-非关联保单应付款", requiredMode = Schema.RequiredMode.REQUIRED)
private String fortuneBizType;
/**
* 关联保单号
*/
@Schema(description = "出账年月 (估)", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonFormat(pattern = "yyyy-MM", timezone = "GMT+8")
private String payoutDate;
@Schema(description = "出账年月 (实)", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonFormat(pattern = "yyyy-MM", timezone = "GMT+8")
private String actualPayoutDate;
@Schema(description = "关联保单号")
private String policyNo;
/**
* 产品计划 ID
*/
@Schema(description = "产品计划 ID")
private String productLaunchBizId;
@Schema(description = "出账状态 0=待出账 1=可出帐,待检核 2=完成出账 3=部分出账 4=保留 5=已失效 6=可出帐,检核完成 7=未找到当前预计发佣对应的来佣, 字典值: csf_expected_fortune_status")
private String status;
@Schema(description = "出账状态-修改理由")
private String statusDesc;
/**
* 佣金期数
*/
@Schema(description = "佣金期数")
@Schema(description = "出账项目", requiredMode = Schema.RequiredMode.REQUIRED)
private String fortuneName;
@Schema(description = "出账项目类型 字典值:csf_fortune_type", requiredMode = Schema.RequiredMode.REQUIRED)
private String fortuneType;
@Schema(description = "出账期数", requiredMode = Schema.RequiredMode.REQUIRED)
private Integer fortunePeriod;
/**
* 总期数
*/
@Schema(description = "总期数")
@Schema(description = "出账总期数", requiredMode = Schema.RequiredMode.REQUIRED)
private Integer fortuneTotalPeriod;
/**
* 转介人名称
*/
@Schema(description = "转介人名称")
@Schema(description = "转介人名称", requiredMode = Schema.RequiredMode.REQUIRED)
private String broker;
/**
* 转介人业务ID
*/
@Schema(description = "broker biz id")
@Schema(description = "broker biz id", requiredMode = Schema.RequiredMode.REQUIRED)
private String brokerBizId;
/**
* 团队名称
*/
@Schema(description = "团队名称")
@Schema(description = "所属团队")
private String team;
/**
* 所属团队业务ID
*/
@Schema(description = "所属团队 biz id")
@Schema(description = "所属团队业务ID")
private String teamBizId;
/**
* 出账项目
*/
@Schema(description = "出账项目")
private String fortuneName;
@Schema(description = "保单币种金额", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal ruleAmount;
/**
* 出账项目类型
*/
@Schema(description = "出账项目类型 字典值:csf_fortune_type")
private String fortuneType;
@Schema(description = "保单币种", requiredMode = Schema.RequiredMode.REQUIRED)
private String ruleCurrency;
/**
* 结算汇率
*/
@Schema(description = "结算汇率")
private BigDecimal exchangeRate;
@Schema(description = "保单币种→港币汇率(默认保单币种汇率)", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal defaultExchangeRate;
/**
* 出账金额 单位:港币
*/
@Schema(description = "出账金额 单位:港币")
private BigDecimal hkdAmount;
@Schema(description = "原币种", requiredMode = Schema.RequiredMode.REQUIRED)
private String originalCurrency;
/**
* 出账币种
*/
@Schema(description = "出账币种")
private String currency;
/**
* 出账日 (估)
*/
@Schema(description = "出账日 (估)")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private LocalDate payoutDate;
/**
* 出账日 (实)
*/
@Schema(description = "出账日 (实)")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date actualPayoutDate;
/**
* 出账状态
*/
@Schema(description = "出账状态 0=待出账 1=可出帐,待检核 2=完成出账 3=部分出账 4=保留 5=已失效 6=可出帐,检核完成 7=未找到当前预计发佣对应的来佣, 字典值: csf_expected_fortune_status")
private String status;
@Schema(description = "原币种金额", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal originalAmount;
@Schema(description = "原币种→港币汇率", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal originalToHkdRate;
@Schema(description = "发放币种", requiredMode = Schema.RequiredMode.REQUIRED)
private String payoutCurrency;
@Schema(description = "发放币种金额", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal payoutAmount;
@Schema(description = "港币→发放币种汇率", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal hkdToPayoutRate;
@Schema(description = "港币金额", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal hkdAmount;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
}
package com.yd.csf.service.enums;
/**
* 项目类型码枚举
* XS("销售佣金", "1")
* M1("一级管理奖", "2")
* M2("二级管理奖", "3")
* TJ("终身推荐奖", "4")
* FD("辅导奖", "5")
* OT("其他加扣款", "6")
* PA("协议约定金额", "7")
*/
public enum FortuneTypeEnum {
//项目类型枚举
XS("XS", "1"),
M1("M1", "2"),
M2("M2", "3"),
TJ("TJ", "4"),
FD("FD", "5"),
OT("OT", "6"),
PA("PA", "7"),
;
//字典项标签(名称)
private String itemLabel;
//字典项值
private String itemValue;
//构造函数
FortuneTypeEnum(String itemLabel, String itemValue) {
this.itemLabel = itemLabel;
this.itemValue = itemValue;
}
public String getItemLabel() {
return itemLabel;
}
public String getItemValue() {
return itemValue;
}
}
......@@ -54,15 +54,14 @@ public interface IExpectedFortuneService extends IService<ExpectedFortune> {
Integer getPayableNoCurrentSeq();
/**
* 生成应付款编号(序号递增) 格式:发佣类型-CSF+年份+序
* 生成应付款编号 格式:发佣类型-保单号后6位-流水
*
* @param fortuneBizType 应付款类型
* @param payoutDate 出账年月 yyyy-MM
* @param fortuneType 应付款类型
* @param policyNo 保单号
* @param fortunePeriod 出账期数
* @param expectedFortuneId 预计发佣ID
* @return 应付款编号
*/
String getPayableNo(String fortuneBizType, String payoutDate, String policyNo, Integer fortunePeriod);
String getPayableNo(String fortuneType, String policyNo, long expectedFortuneId);
/**
* 查询预计发佣和实际发佣的分页列表(手动分页)
......
......@@ -10,6 +10,7 @@ import com.yd.csf.service.vo.PolicyVO;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Zhang Jianan
......@@ -33,4 +34,6 @@ public interface PolicyService extends IService<Policy> {
List<PolicyProductInfo> getPolicyProductInfo(List<String> productLaunchBizIdList);
Map<String, PolicyProductInfo> getPolicyProductInfoMap(Collection<String> productLaunchBizIdList);
Map<String, Policy> queryPolicyMap(Collection<String> policyNoList);
}
......@@ -31,7 +31,6 @@ import com.yd.insurance.base.feign.client.insurancereconciliationcompany.ApiInsu
import com.yd.insurance.base.feign.request.insurancereconciliationcompany.ApiInsuranceReconciliationCompanyPageRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -673,8 +672,11 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
}
}
// 3. 构建实际的初始发佣记录
List<Fortune> newFortuneList = buildNewFortunes(filteredExpectedFortuneList2, commissions);
// 2.4 根据保单号、期数查询入账检核汇率
Map<String, BigDecimal> exchangeRateMap = this.queryCommissionExchangeRateMap(policyNoSet, commissionPeriodSet);
// 3. 构建实际的初始发佣记录(使用入账检核汇率)
List<Fortune> newFortuneList = buildNewFortunes(filteredExpectedFortuneList2, commissions, exchangeRateMap);
// 4. 保存发佣记录
saveNewFortunes(newFortuneList);
......@@ -682,6 +684,42 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
return true;
}
private Map<String, BigDecimal> queryCommissionExchangeRateMap(Set<String> policyNoSet, Set<Integer> commissionPeriodSet) {
if (CollectionUtils.isEmpty(policyNoSet) || CollectionUtils.isEmpty(commissionPeriodSet)) {
return new HashMap<>();
}
// 1. 查询所有符合条件的记录,按入账日期降序排序
List<Commission> commissionExchangeRateList = this.lambdaQuery()
.in(Commission::getPolicyNo, policyNoSet)
.in(Commission::getCommissionPeriod, commissionPeriodSet)
.select(Commission::getPolicyNo, Commission::getCommissionPeriod, Commission::getExchangeRate, Commission::getCommissionDate)
.orderByDesc(Commission::getCommissionDate)
.list();
// 2. 按 policyNo + commissionPeriod 分组,取每组的第一条(最新的)
Map<String, BigDecimal> exchangeRateMap = commissionExchangeRateList.stream()
.collect(Collectors.groupingBy(
commission -> buildPolicyPeriodKey(commission.getPolicyNo(), commission.getCommissionPeriod())
))
.entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().get(0).getExchangeRate()
));
// 3. 确保所有 policyNo + commissionPeriod 组合都在 Map 中,没有记录的设为 null
Map<String, BigDecimal> result = new HashMap<>();
for (String policyNo : policyNoSet) {
for (Integer commissionPeriod : commissionPeriodSet) {
String key = buildPolicyPeriodKey(policyNo, commissionPeriod);
result.put(key, exchangeRateMap.getOrDefault(key, null));
}
}
return result;
}
/**
* 保存新的发佣记录
*/
......@@ -700,7 +738,8 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
* 构建新的发佣记录
*/
private List<Fortune> buildNewFortunes(List<ExpectedFortune> expectedFortuneList,
List<Commission> commissionList) {
List<Commission> commissionList,
Map<String, BigDecimal> exchangeRateMap) {
if (CollectionUtils.isEmpty(expectedFortuneList)) {
return new ArrayList<>();
}
......@@ -713,24 +752,51 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
));
Date now = new Date();
return expectedFortuneList.stream()
.map(expectedFortune -> {
// 创建新的发佣记录
List<Fortune> newFortuneList = new ArrayList<>();
// 更新预计发佣记录的港币金额
List<ExpectedFortune> updatedExpectedFortuneList = new ArrayList<>();
for (ExpectedFortune expectedFortune : expectedFortuneList) {
Fortune fortune = new Fortune();
BeanUtils.copyProperties(expectedFortune, fortune);
fortune.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode()));
fortune.setId(null);
fortune.setFortuneBizType("R");
fortune.setExchangeRate(expectedFortune.getDefaultExchangeRate());
// 优先使用入账检核汇率,如果没有则使用默认汇率
String key = buildPolicyPeriodKey(expectedFortune.getPolicyNo(), expectedFortune.getFortunePeriod());
BigDecimal exchangeRate = exchangeRateMap.get(key);
if (exchangeRate != null) {
fortune.setExchangeRate(exchangeRate);
fortune.setOriginalToHkdRate(exchangeRate);
// 重新计算港币金额
BigDecimal hkdAmount = fortune.getRuleAmount().multiply(exchangeRate);
fortune.setHkdAmount(hkdAmount);
fortune.setCurrentPaymentAmount(hkdAmount);
fortune.setCurrentPaymentHkdAmount(hkdAmount);
// 更新预计发佣记录的港币金额
ExpectedFortune update = new ExpectedFortune();
update.setId(expectedFortune.getId());
update.setDefaultExchangeRate(exchangeRate);
update.setOriginalToHkdRate(exchangeRate);
update.setHkdAmount(hkdAmount);
update.setUnpaidAmount(hkdAmount);
updatedExpectedFortuneList.add(update);
} else {
fortune.setExchangeRate(expectedFortune.getDefaultExchangeRate());
fortune.setCurrentPaymentAmount(expectedFortune.getOriginalAmount());
fortune.setCurrentPaymentHkdAmount(expectedFortune.getHkdAmount());
}
fortune.setExpectedFortuneBizId(expectedFortune.getExpectedFortuneBizId());
fortune.setStatus(FortuneStatusEnum.CAN_SEND.getItemValue());
fortune.setIsPart(0);
// 关联来佣业务ID
String key = buildPolicyPeriodKey(expectedFortune.getPolicyNo(), expectedFortune.getFortunePeriod());
Commission matchedCommission = commissionByPolicyPeriod.get(key);
if (matchedCommission != null) {
fortune.setCommissionBizId(matchedCommission.getCommissionBizId());
......@@ -743,9 +809,18 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
fortune.setCreateTime(now);
fortune.setUpdateTime(now);
return fortune;
})
.collect(Collectors.toList());
newFortuneList.add(fortune);
}
// 更新预计发佣记录
if (CollectionUtils.isNotEmpty(updatedExpectedFortuneList)) {
boolean updateSuccess = iExpectedFortuneService.updateBatchById(updatedExpectedFortuneList);
if (!updateSuccess) {
throw new BusinessException(ResultCode.FAIL.getCode(), "更新预计发佣记录港币金额失败");
}
}
return newFortuneList;
}
/**
......@@ -768,7 +843,7 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
}
/**
* 构建保单号+期的唯一键
* 构建保单号+期的唯一键
*/
@Override
public String buildPolicyPeriodKey(String policyNo, Object period) {
......
......@@ -9,6 +9,7 @@ import com.yd.csf.feign.request.expectedfortune.ApiExpectedFortunePageRequest;
import com.yd.csf.feign.response.expectedfortune.ApiExpectedFortunePageResponse;
import com.yd.csf.service.dto.UserGradeDto;
import com.yd.csf.service.enums.CurrencyEnum;
import com.yd.csf.service.enums.FortuneTypeEnum;
import com.yd.csf.service.model.ExpectedFortune;
import com.yd.csf.service.dao.ExpectedFortuneMapper;
import com.yd.csf.service.model.Policy;
......@@ -289,26 +290,27 @@ public class ExpectedFortuneServiceImpl extends ServiceImpl<ExpectedFortuneMappe
}
@Override
public String getPayableNo(String fortuneBizType, String payoutDate, String policyNo, Integer fortunePeriod) {
// 1. 安全获取保单号后4
String last4Chars = "";
public String getPayableNo(String fortuneType, String policyNo, long expectedFortuneId) {
// 1. 安全获取保单号后6
String last6Chars = "";
if (policyNo != null && !policyNo.isEmpty()) {
int startIdx = Math.max(0, policyNo.length() - 4);
last4Chars = policyNo.substring(startIdx);
int startIdx = Math.max(0, policyNo.length() - 6);
last6Chars = policyNo.substring(startIdx);
}
// 2. 字符串左补0至4
// %4s 表示最小宽度为4,不足部分默认用空格填充在左侧
// 2. 字符串左补0至6
// %6s 表示最小宽度为6,不足部分默认用空格填充在左侧
// replace(' ', '0') 将填充的空格替换为0,实现左补0效果
String formattedPolicySuffix = String.format("%4s", last4Chars).replace(' ', '0');
String formattedPolicySuffix = String.format("%6s", last6Chars).replace(' ', '0');
// 3. 组装最终字符串
return String.format("%s%04d%02d%s%03d",
fortuneBizType,
Integer.parseInt(payoutDate.substring(0, 4)),
Integer.parseInt(payoutDate.substring(5, 7)),
// 3. 项目类型枚举转换为字符串
String fortuneTypeCode = FortuneTypeEnum.valueOf(fortuneType).getItemLabel();
// 4. 组装最终字符串
return String.format("%s-%s-%d",
fortuneTypeCode,
formattedPolicySuffix,
fortunePeriod);
expectedFortuneId);
}
@Override
......
......@@ -269,6 +269,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
/**
* 保单币种对预计来佣的结算币种的默认汇率
*
* @param policyCurrency 保单币种
* @param currency 预计来佣的结算币种
* @return 汇率
......@@ -770,7 +771,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
valiAddFortune(fortuneAddRequest);
Fortune fortune = new Fortune();
BeanUtil.copyProperties(fortuneAddRequest, fortune);
BeanUtil.copyProperties(fortuneAddRequest, fortune, "payoutDate", "actualPayoutDate");
fortune.setCurrentPaymentHkdAmount(fortune.getHkdAmount());
// 查询发佣类型名称
......@@ -789,6 +790,12 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
expectedFortune = createExpectedFortune(fortuneAddRequest, policy, fortuneName);
// 保存
expectedFortuneService.save(expectedFortune);
// 更新应付款编号
String payableNo = expectedFortuneService.getPayableNo(fortuneAddRequest.getFortuneType(), policy.getPolicyNo(), expectedFortune.getId());
expectedFortuneService.lambdaUpdate()
.set(ExpectedFortune::getPayableNo, payableNo)
.eq(ExpectedFortune::getId, expectedFortune.getId())
.update();
} else {
// 如果有预计出账记录,提示去应付款管理页面修改金额,而不是在出账页面新增
throw new BusinessException(ResultCode.FAIL.getCode(), fortuneAddRequest.getFortuneName() + " 已存在应付记录,请在应付款管理页面修改金额");
......@@ -830,13 +837,9 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
}
private ExpectedFortune createExpectedFortune(FortuneAddRequest fortuneAddRequest, Policy policy, String fortuneName) {
// 应付款编号(序号递增)
String payableNo = expectedFortuneService.getPayableNo(fortuneAddRequest.getFortuneBizType(), fortuneAddRequest.getPayoutDate(), policy.getPolicyNo(), fortuneAddRequest.getFortunePeriod());
// 创建 expectedFortune
ExpectedFortune expectedFortune = new ExpectedFortune();
BeanUtil.copyProperties(fortuneAddRequest, expectedFortune);
BeanUtil.copyProperties(fortuneAddRequest, expectedFortune, "payoutDate", "actualPayoutDate");
// 设置 policy 关联字段
expectedFortune.setInsuranceCompanyBizId(policy.getInsuranceCompanyBizId());
......@@ -849,11 +852,15 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
// 预计发佣类型名称
expectedFortune.setFortuneName(fortuneName);
// 应付款编号
expectedFortune.setPayableNo(payableNo);
expectedFortune.setPayableNo(null);
// 是否拆分
expectedFortune.setIsPart(0);
// 默认保单币种汇率
expectedFortune.setDefaultExchangeRate(fortuneAddRequest.getExchangeRate());
// 预计出账年月
expectedFortune.setPayoutDate(LocalDate.parse(fortuneAddRequest.getPayoutDate() + "-01"));
// 实际出账年月
expectedFortune.setActualPayoutDate(LocalDate.parse(fortuneAddRequest.getActualPayoutDate() + "-01"));
// 已出帐金额、待出帐金额、已出帐比例、待出帐比例
expectedFortune.setPaidAmount(BigDecimal.ZERO);
......
......@@ -388,6 +388,17 @@ public class PolicyServiceImpl extends ServiceImpl<PolicyMapper, Policy>
.collect(Collectors.toMap(PolicyProductInfo::getProductLaunchBizId, Function.identity(), (oldValue, newValue) -> newValue));
}
@Override
public Map<String, Policy> queryPolicyMap(Collection<String> policyNoList) {
// 校验参数
if (CollectionUtils.isEmpty(policyNoList)) {
return Collections.emptyMap();
}
return this.lambdaQuery().in(Policy::getPolicyNo, policyNoList).list()
.stream().collect(Collectors.toMap(Policy::getPolicyNo, Function.identity()));
}
/**
* 从JSON数组中解析自定义属性
*/
......
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