Commit 6fe34a9b by jianan

出账检核-增加币种42

parent dd60f236
...@@ -33,6 +33,7 @@ import com.yd.csf.service.dto.QueryPolicyBrokerDto; ...@@ -33,6 +33,7 @@ import com.yd.csf.service.dto.QueryPolicyBrokerDto;
import com.yd.csf.service.dto.UserGradeDto; import com.yd.csf.service.dto.UserGradeDto;
import com.yd.csf.service.enums.CurrencyEnum; import com.yd.csf.service.enums.CurrencyEnum;
import com.yd.csf.service.enums.FortuneStatusEnum; 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.helper.FeignResultHelper;
import com.yd.csf.service.model.*; import com.yd.csf.service.model.*;
import com.yd.csf.service.service.*; import com.yd.csf.service.service.*;
...@@ -685,7 +686,7 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService ...@@ -685,7 +686,7 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
ExpectedFortune updateObj = new ExpectedFortune(); ExpectedFortune updateObj = new ExpectedFortune();
updateObj.setId(expectedFortune.getId()); 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, updateObj.setFortuneType(GetDictItemListByDictTypeResponse.getItemValue(dictTypeResponses,
"csf_fortune_type", expectedFortune.getFortuneName())); "csf_fortune_type", expectedFortune.getFortuneName()));
...@@ -1055,9 +1056,6 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService ...@@ -1055,9 +1056,6 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
expectedFortune.setExpectedFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_EXPECTED_FORTUNE.getCode())); expectedFortune.setExpectedFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_EXPECTED_FORTUNE.getCode()));
// 预计发佣类型名称 // 预计发佣类型名称
expectedFortune.setFortuneName(queryByDict(expectedFortuneDto.getFortuneType())); expectedFortune.setFortuneName(queryByDict(expectedFortuneDto.getFortuneType()));
// 应付款编号(序号递增)
expectedFortune.setPayableNo(this.createPayableNo(expectedFortune.getFortuneBizType(), expectedFortuneDto.getPayoutDate(), expectedFortuneDto.getPolicyNo(), expectedFortuneDto.getFortunePeriod()));
// 已出帐金额、待出帐金额、已出帐比例、待出帐比例 // 已出帐金额、待出帐金额、已出帐比例、待出帐比例
expectedFortune.setPaidAmount(BigDecimal.ZERO); expectedFortune.setPaidAmount(BigDecimal.ZERO);
...@@ -1069,6 +1067,20 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService ...@@ -1069,6 +1067,20 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
fortuneList.add(expectedFortune); fortuneList.add(expectedFortune);
} }
iExpectedFortuneService.saveOrUpdateBatch(fortuneList); 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; return true;
} }
...@@ -1212,37 +1224,6 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService ...@@ -1212,37 +1224,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 * @param request
......
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> { ...@@ -54,15 +54,14 @@ public interface IExpectedFortuneService extends IService<ExpectedFortune> {
Integer getPayableNoCurrentSeq(); Integer getPayableNoCurrentSeq();
/** /**
* 生成应付款编号(序号递增) 格式:发佣类型-CSF+年份+序 * 生成应付款编号 格式:发佣类型-保单号后6位-流水
* *
* @param fortuneBizType 应付款类型 * @param fortuneType 应付款类型
* @param payoutDate 出账年月 yyyy-MM
* @param policyNo 保单号 * @param policyNo 保单号
* @param fortunePeriod 出账期数 * @param expectedFortuneId 预计发佣ID
* @return 应付款编号 * @return 应付款编号
*/ */
String getPayableNo(String fortuneBizType, String payoutDate, String policyNo, Integer fortunePeriod); String getPayableNo(String fortuneType, String policyNo, long expectedFortuneId);
/** /**
* 查询预计发佣和实际发佣的分页列表(手动分页) * 查询预计发佣和实际发佣的分页列表(手动分页)
......
...@@ -31,7 +31,6 @@ import com.yd.insurance.base.feign.client.insurancereconciliationcompany.ApiInsu ...@@ -31,7 +31,6 @@ import com.yd.insurance.base.feign.client.insurancereconciliationcompany.ApiInsu
import com.yd.insurance.base.feign.request.insurancereconciliationcompany.ApiInsuranceReconciliationCompanyPageRequest; import com.yd.insurance.base.feign.request.insurancereconciliationcompany.ApiInsuranceReconciliationCompanyPageRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -673,8 +672,11 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss ...@@ -673,8 +672,11 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
} }
} }
// 3. 构建实际的初始发佣记录 // 2.4 根据保单号、期数查询入账检核汇率
List<Fortune> newFortuneList = buildNewFortunes(filteredExpectedFortuneList2, commissions); Map<String, BigDecimal> exchangeRateMap = this.queryCommissionExchangeRateMap(policyNoSet, commissionPeriodSet);
// 3. 构建实际的初始发佣记录(使用入账检核汇率)
List<Fortune> newFortuneList = buildNewFortunes(filteredExpectedFortuneList2, commissions, exchangeRateMap);
// 4. 保存发佣记录 // 4. 保存发佣记录
saveNewFortunes(newFortuneList); saveNewFortunes(newFortuneList);
...@@ -682,6 +684,42 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss ...@@ -682,6 +684,42 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
return true; 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 ...@@ -700,7 +738,8 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
* 构建新的发佣记录 * 构建新的发佣记录
*/ */
private List<Fortune> buildNewFortunes(List<ExpectedFortune> expectedFortuneList, private List<Fortune> buildNewFortunes(List<ExpectedFortune> expectedFortuneList,
List<Commission> commissionList) { List<Commission> commissionList,
Map<String, BigDecimal> exchangeRateMap) {
if (CollectionUtils.isEmpty(expectedFortuneList)) { if (CollectionUtils.isEmpty(expectedFortuneList)) {
return new ArrayList<>(); return new ArrayList<>();
} }
...@@ -713,24 +752,51 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss ...@@ -713,24 +752,51 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
)); ));
Date now = new Date(); 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(); Fortune fortune = new Fortune();
BeanUtils.copyProperties(expectedFortune, fortune); BeanUtils.copyProperties(expectedFortune, fortune);
fortune.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode())); fortune.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode()));
fortune.setId(null); fortune.setId(null);
fortune.setFortuneBizType("R"); 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.setCurrentPaymentAmount(expectedFortune.getOriginalAmount());
fortune.setCurrentPaymentHkdAmount(expectedFortune.getHkdAmount()); fortune.setCurrentPaymentHkdAmount(expectedFortune.getHkdAmount());
}
fortune.setExpectedFortuneBizId(expectedFortune.getExpectedFortuneBizId()); fortune.setExpectedFortuneBizId(expectedFortune.getExpectedFortuneBizId());
fortune.setStatus(FortuneStatusEnum.CAN_SEND.getItemValue()); fortune.setStatus(FortuneStatusEnum.CAN_SEND.getItemValue());
fortune.setIsPart(0); fortune.setIsPart(0);
// 关联来佣业务ID // 关联来佣业务ID
String key = buildPolicyPeriodKey(expectedFortune.getPolicyNo(), expectedFortune.getFortunePeriod());
Commission matchedCommission = commissionByPolicyPeriod.get(key); Commission matchedCommission = commissionByPolicyPeriod.get(key);
if (matchedCommission != null) { if (matchedCommission != null) {
fortune.setCommissionBizId(matchedCommission.getCommissionBizId()); fortune.setCommissionBizId(matchedCommission.getCommissionBizId());
...@@ -743,9 +809,18 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss ...@@ -743,9 +809,18 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
fortune.setCreateTime(now); fortune.setCreateTime(now);
fortune.setUpdateTime(now); fortune.setUpdateTime(now);
return fortune; newFortuneList.add(fortune);
}) }
.collect(Collectors.toList());
// 更新预计发佣记录
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 ...@@ -768,7 +843,7 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
} }
/** /**
* 构建保单号+期的唯一键 * 构建保单号+期的唯一键
*/ */
@Override @Override
public String buildPolicyPeriodKey(String policyNo, Object period) { public String buildPolicyPeriodKey(String policyNo, Object period) {
......
...@@ -9,6 +9,7 @@ import com.yd.csf.feign.request.expectedfortune.ApiExpectedFortunePageRequest; ...@@ -9,6 +9,7 @@ import com.yd.csf.feign.request.expectedfortune.ApiExpectedFortunePageRequest;
import com.yd.csf.feign.response.expectedfortune.ApiExpectedFortunePageResponse; import com.yd.csf.feign.response.expectedfortune.ApiExpectedFortunePageResponse;
import com.yd.csf.service.dto.UserGradeDto; import com.yd.csf.service.dto.UserGradeDto;
import com.yd.csf.service.enums.CurrencyEnum; 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.model.ExpectedFortune;
import com.yd.csf.service.dao.ExpectedFortuneMapper; import com.yd.csf.service.dao.ExpectedFortuneMapper;
import com.yd.csf.service.model.Policy; import com.yd.csf.service.model.Policy;
...@@ -289,26 +290,27 @@ public class ExpectedFortuneServiceImpl extends ServiceImpl<ExpectedFortuneMappe ...@@ -289,26 +290,27 @@ public class ExpectedFortuneServiceImpl extends ServiceImpl<ExpectedFortuneMappe
} }
@Override @Override
public String getPayableNo(String fortuneBizType, String payoutDate, String policyNo, Integer fortunePeriod) { public String getPayableNo(String fortuneType, String policyNo, long expectedFortuneId) {
// 1. 安全获取保单号后4 // 1. 安全获取保单号后6
String last4Chars = ""; String last6Chars = "";
if (policyNo != null && !policyNo.isEmpty()) { if (policyNo != null && !policyNo.isEmpty()) {
int startIdx = Math.max(0, policyNo.length() - 4); int startIdx = Math.max(0, policyNo.length() - 6);
last4Chars = policyNo.substring(startIdx); last6Chars = policyNo.substring(startIdx);
} }
// 2. 字符串左补0至4 // 2. 字符串左补0至6
// %4s 表示最小宽度为4,不足部分默认用空格填充在左侧 // %6s 表示最小宽度为6,不足部分默认用空格填充在左侧
// replace(' ', '0') 将填充的空格替换为0,实现左补0效果 // replace(' ', '0') 将填充的空格替换为0,实现左补0效果
String formattedPolicySuffix = String.format("%4s", last4Chars).replace(' ', '0'); String formattedPolicySuffix = String.format("%6s", last6Chars).replace(' ', '0');
// 3. 组装最终字符串 // 3. 项目类型枚举转换为字符串
return String.format("%s%04d%02d%s%03d", String fortuneTypeCode = FortuneTypeEnum.valueOf(fortuneType).getItemLabel();
fortuneBizType,
Integer.parseInt(payoutDate.substring(0, 4)), // 4. 组装最终字符串
Integer.parseInt(payoutDate.substring(5, 7)), return String.format("%s-%s-%d",
fortuneTypeCode,
formattedPolicySuffix, formattedPolicySuffix,
fortunePeriod); expectedFortuneId);
} }
@Override @Override
......
...@@ -789,6 +789,12 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune> ...@@ -789,6 +789,12 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
expectedFortune = createExpectedFortune(fortuneAddRequest, policy, fortuneName); expectedFortune = createExpectedFortune(fortuneAddRequest, policy, fortuneName);
// 保存 // 保存
expectedFortuneService.save(expectedFortune); 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 { } else {
// 如果有预计出账记录,提示去应付款管理页面修改金额,而不是在出账页面新增 // 如果有预计出账记录,提示去应付款管理页面修改金额,而不是在出账页面新增
throw new BusinessException(ResultCode.FAIL.getCode(), fortuneAddRequest.getFortuneName() + " 已存在应付记录,请在应付款管理页面修改金额"); throw new BusinessException(ResultCode.FAIL.getCode(), fortuneAddRequest.getFortuneName() + " 已存在应付记录,请在应付款管理页面修改金额");
...@@ -830,10 +836,6 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune> ...@@ -830,10 +836,6 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
} }
private ExpectedFortune createExpectedFortune(FortuneAddRequest fortuneAddRequest, Policy policy, String fortuneName) { private ExpectedFortune createExpectedFortune(FortuneAddRequest fortuneAddRequest, Policy policy, String fortuneName) {
// 应付款编号(序号递增)
String payableNo = expectedFortuneService.getPayableNo(fortuneAddRequest.getFortuneBizType(), fortuneAddRequest.getPayoutDate(), policy.getPolicyNo(), fortuneAddRequest.getFortunePeriod());
// 创建 expectedFortune // 创建 expectedFortune
ExpectedFortune expectedFortune = new ExpectedFortune(); ExpectedFortune expectedFortune = new ExpectedFortune();
BeanUtil.copyProperties(fortuneAddRequest, expectedFortune); BeanUtil.copyProperties(fortuneAddRequest, expectedFortune);
...@@ -849,7 +851,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune> ...@@ -849,7 +851,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
// 预计发佣类型名称 // 预计发佣类型名称
expectedFortune.setFortuneName(fortuneName); expectedFortune.setFortuneName(fortuneName);
// 应付款编号 // 应付款编号
expectedFortune.setPayableNo(payableNo); expectedFortune.setPayableNo(null);
// 是否拆分 // 是否拆分
expectedFortune.setIsPart(0); expectedFortune.setIsPart(0);
// 默认保单币种汇率 // 默认保单币种汇率
......
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