Commit fd7f918a by zhangxingmin

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

parents c264c145 906e0a3f
......@@ -135,7 +135,7 @@ public class ApiExpectedFortuneController implements ApiExpectedFortuneFeignClie
* @return
*/
@PostMapping("/update")
@Operation(summary = "更新保单发佣信息")
@Operation(summary = "修改出账信息")
public Result<Boolean> update(@RequestBody ExpectedFortuneUpdateRequest request) {
if (request == null || request.getExpectedFortuneBizId() == null) {
return Result.fail(ErrorCode.PARAMS_ERROR.getCode(), ErrorCode.PARAMS_ERROR.getMessage());
......
......@@ -202,10 +202,9 @@ public class ApiFortuneController {
if (CollectionUtils.isEmpty(fortuneDownloadRequest.getFortuneBizIdList())) {
throw new BusinessException(ResultCode.PARAMS_ERROR.getCode(), "请选择要出账的发佣数据");
}
try {
fortuneService.downloadAccount(fortuneDownloadRequest, response);
return Result.success(true);
} catch (Exception e) {
// // 设置响应类型为 JSON,而不是文件流
// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
// response.setContentType(MediaType.APPLICATION_JSON_VALUE);
......@@ -218,11 +217,10 @@ public class ApiFortuneController {
//
// response.getWriter().write(new ObjectMapper().writeValueAsString(errorResult));
log.error("生成出账清单失败", e);
return Result.success(false);
}
return Result.success(true);
}
/**
* 分页获取出账列表
*
......
......@@ -466,7 +466,7 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
true
);
ArrayList<ExpectedFortune> fortuneList = new ArrayList<>();
List<ExpectedFortune> fortuneList = new ArrayList<>();
for (ExpectedFortuneAddRequest expectedFortuneDto : fortuneAddRequestList) {
ExpectedFortune expectedFortune = new ExpectedFortune();
BeanUtil.copyProperties(expectedFortuneDto, expectedFortune);
......@@ -475,6 +475,11 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
expectedFortune.setExpectedFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_EXPECTED_FORTUNE.getCode()));
// 应付款编号
expectedFortune.setPayableNo(this.createPayableNo(expectedFortune.getFortuneBizType(), latest));
// 已出帐金额、待出帐金额、已出帐比例、待出帐比例
expectedFortune.setPaidAmount(BigDecimal.ZERO);
expectedFortune.setUnpaidAmount(expectedFortune.getAmount());
expectedFortune.setPaidRatio(BigDecimal.ZERO);
expectedFortune.setUnpaidRatio(BigDecimal.valueOf(100));
fortuneList.add(expectedFortune);
}
iExpectedFortuneService.saveOrUpdateBatch(fortuneList);
......@@ -486,26 +491,11 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
// 查询数据
QueryWrapper<ExpectedFortune> queryWrapper = this.getQueryWrapper(request);
List<ExpectedFortune> fortuneList = iExpectedFortuneService.list(queryWrapper);
// 关联保单信息
List<Policy> policyList = policyService.lambdaQuery()
.in(Policy::getPolicyNo, fortuneList.stream().map(ExpectedFortune::getPolicyNo).collect(Collectors.toList()))
.list();
Map<String, Policy> policyMap = policyList.stream()
.collect(Collectors.toMap(Policy::getPolicyNo, Function.identity()));
// 先转换为VO, VO 补充了关联信息(产品计划、产品险种、保险公司、用户)
List<ApiExpectedFortunePageResponse> expectedFortuneVOList = iExpectedFortuneService.toVOList(fortuneList);
// 转换为导出DTO
List<ExpectedFortuneExportDTO> exportDataList = fortuneList.stream()
.map(fortune -> {
ExpectedFortuneExportDTO dto = ExpectedFortuneExportDTO.convertToExportDTO(fortune);
// 关联保单信息
Policy policy = policyMap.get(fortune.getPolicyNo());
if (!Objects.isNull(policy)) {
dto.setInsuranceCompany(policy.getInsuranceCompany());
dto.setProductName(policy.getProductName());
}
return dto;
})
List<ExpectedFortuneExportDTO> exportDataList = expectedFortuneVOList.stream()
.map(ExpectedFortuneExportDTO::convertToExportDTO)
.collect(Collectors.toList());
// 使用EasyExcel导出
......@@ -659,6 +649,10 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
if (expectedFortune == null) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), "预计发佣数据不存在");
}
if (expectedFortune.getPaidAmount().compareTo(BigDecimal.ZERO) > 0) {
throw new BusinessException(ResultCode.FAIL.getCode(), "当前应付款已有出账金额,不能修改");
}
ExpectedFortune updateExpectedFortune = new ExpectedFortune();
BeanUtils.copyProperties(request, updateExpectedFortune);
updateExpectedFortune.setId(expectedFortune.getId());
......
......@@ -54,12 +54,6 @@ public class ExpectedFortuneUpdateRequest {
private String statusDesc;
/**
* 当前出账金额
*/
@Schema(description = "当前出账金额")
private BigDecimal currentPaymentAmount;
/**
* 出账项目
*/
@Schema(description = "出账项目")
......
......@@ -54,33 +54,39 @@ public class ApiExpectedFortunePageResponse {
private String insuranceCompanyBizId;
/**
* 保险公司
*/
@Schema(description = "保险公司")
private String insuranceCompany;
/**
* 产品计划 ID
*/
@Schema(description = "产品计划 ID")
private String productLaunchBizId;
/**
* 保单信息
* 产品计划
*/
@Schema(description = "policy info")
private PolicyInfo policy;
@Schema(description = "产品计划")
private String productName;
/**
* 出账期数(1=第一年; 2=第二年; 3=第三年; 4=第四年; 5=第五年)
*/
@Schema(description = "fortune period")
@Schema(description = "出账期数")
private Integer fortunePeriod;
/**
* 总期数
*/
@Schema(description = "fortune total period")
@Schema(description = "总期数")
private Integer fortuneTotalPeriod;
/**
* 转介人名称
* 转介人
*/
@Schema(description = "转介人名称")
@Schema(description = "转介人")
private String broker;
/**
......@@ -194,9 +200,21 @@ public class ApiExpectedFortunePageResponse {
private String ruleItemBizId;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* 创建时间
*/
@Schema(description = "create time")
@Schema(description = "创建时间")
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
private LocalDateTime updateTime;
}
......@@ -191,12 +191,18 @@ public class ExpectedFortune implements Serializable {
private BigDecimal unpaidAmount;
/**
* 发佣比例 已发佣金额/应发佣金额
* 已出账比例 已出账金额/应出账金额
*/
@TableField("paid_ratio")
private BigDecimal paidRatio;
/**
* 待出账比例
*/
@TableField("unpaid_ratio")
private BigDecimal unpaidRatio;
/**
* 是否含税 0=No, 1=Yes
*/
@TableField("is_tax")
......
......@@ -32,4 +32,6 @@ public interface IExpectedFortuneService extends IService<ExpectedFortune> {
ExpectedFortuneStatisticsVO getStatistics(List<Long> expectedFortuneIds);
IPage<ApiExpectedFortunePageResponse> getVOPage(IPage<ExpectedFortune> iPage);
List<ApiExpectedFortunePageResponse> toVOList(List<ExpectedFortune> fortuneList);
}
......@@ -455,9 +455,6 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
public Boolean generateFortune(GenerateFortuneRequest generateFortuneRequest) {
List<String> commissionBizIdList = generateFortuneRequest.getCommissionBizIdList();
List<Commission> commissions = this.lambdaQuery().in(Commission::getCommissionBizId, commissionBizIdList).list();
// 根据保单号,期数建立映射关系
Map<String, Commission> policyNoPeriodMap = commissions.stream()
.collect(Collectors.toMap(i -> i.getPolicyNo() + "_" + i.getCommissionPeriod(), commission -> commission));
// 校验来佣记录是否存在
if (CollectionUtils.isEmpty(commissions)) {
......@@ -585,6 +582,7 @@ public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commiss
fortune.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode()));
fortune.setFortuneBizType("R");
fortune.setAmount(expectedFortune.getAmount());
fortune.setCurrentPaymentAmount(expectedFortune.getAmount());
fortune.setExpectedFortuneBizId(expectedFortune.getExpectedFortuneBizId());
fortune.setStatus(FortuneStatusEnum.CAN_SEND.getItemValue());
fortune.setIsPart(0);
......
......@@ -77,25 +77,32 @@ public class ExpectedFortuneServiceImpl extends ServiceImpl<ExpectedFortuneMappe
if (CollUtil.isEmpty(expectedFortuneList)) {
return expectedFortuneVOPage;
}
// 查询关联的保单信息
List<String> policyNoList = expectedFortuneList.stream().map(ExpectedFortune::getPolicyNo).collect(Collectors.toList());
QueryWrapper<Policy> queryWrapper = new QueryWrapper<>();
queryWrapper.in("policy_no", policyNoList);
List<Policy> policyInfoList = policyService.list(queryWrapper);
Map<String, Policy> policyMap = policyInfoList.stream().collect(Collectors.toMap(Policy::getPolicyNo, Function.identity()));
List<ApiExpectedFortunePageResponse> expectedFortuneVOList = toVOList(expectedFortuneList);
expectedFortuneVOPage.setRecords(expectedFortuneVOList);
return expectedFortuneVOPage;
}
@Override
public List<ApiExpectedFortunePageResponse> toVOList(List<ExpectedFortune> expectedFortuneList) {
// 关联保单信息
List<Policy> policyList = policyService.lambdaQuery()
.in(Policy::getPolicyNo, expectedFortuneList.stream().map(ExpectedFortune::getPolicyNo).collect(Collectors.toList()))
.list();
Map<String, Policy> policyMap = policyList.stream()
.collect(Collectors.toMap(Policy::getPolicyNo, Function.identity()));
List<ApiExpectedFortunePageResponse> expectedFortuneVOList = expectedFortuneList.stream().map(expectedFortune -> {
ApiExpectedFortunePageResponse expectedFortuneVO = new ApiExpectedFortunePageResponse();
BeanUtils.copyProperties(expectedFortune, expectedFortuneVO);
if (policyMap.get(expectedFortune.getPolicyNo()) != null) {
PolicyInfo policyInfo = new PolicyInfo();
BeanUtils.copyProperties(policyMap.get(expectedFortune.getPolicyNo()), policyInfo);
expectedFortuneVO.setPolicy(policyInfo);
Policy policy = policyMap.get(expectedFortune.getPolicyNo());
if (policy != null) {
expectedFortuneVO.setInsuranceCompany(policy.getInsuranceCompany());
expectedFortuneVO.setProductName(policy.getProductName());
expectedFortuneVO.setPremium(policy.getPaymentPremium());
}
return expectedFortuneVO;
}).collect(Collectors.toList());
expectedFortuneVOPage.setRecords(expectedFortuneVOList);
return expectedFortuneVOPage;
return expectedFortuneVOList;
}
}
package com.yd.csf.service.service.impl;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Date;
......@@ -247,70 +248,98 @@ public class FortuneAccountServiceImpl extends ServiceImpl<FortuneAccountMapper,
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean completeFortuneAccount(CompleteFortuneAccountRequest completeFortuneAccountRequest) {
List<String> fortuneAccountBizIdList = completeFortuneAccountRequest.getFortuneAccountBizIdList();
List<FortuneAccount> fortuneAccountList = this.list(new QueryWrapper<FortuneAccount>().in("fortune_account_biz_id", fortuneAccountBizIdList));
if (CollectionUtils.isEmpty(fortuneAccountList)) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), ResultCode.NULL_ERROR.getMessage());
public Boolean completeFortuneAccount(CompleteFortuneAccountRequest req) {
/* 1. 参数校验 & 查询 --------------------------------------------------*/
List<String> accountBizIds = req.getFortuneAccountBizIdList();
if (CollectionUtils.isEmpty(accountBizIds)) {
throw new BusinessException("出账清单不能为空");
}
// 当前登录用户
AuthUserDto currentLoginUser = SecurityUtil.getCurrentLoginUser();
Long loginUserId = currentLoginUser.getId();
// 更新 FortuneAccount 状态为已出账
for (FortuneAccount fortuneAccount : fortuneAccountList) {
fortuneAccount.setStatus(FortuneAccountStatusEnum.SENT.getItemValue());
fortuneAccount.setFortuneAccountDate(new Date());
fortuneAccount.setUpdaterId(loginUserId.toString());
fortuneAccount.setUpdateTime(new Date());
List<FortuneAccount> accountList = this.lambdaQuery()
.in(FortuneAccount::getFortuneAccountBizId, accountBizIds)
.list();
Long loginUserId = SecurityUtil.getCurrentLoginUser().getId();
/* 2. 更新 FortuneAccount 状态为已出账 ----------------------------------*/
accountList.forEach(a -> {
a.setStatus(FortuneAccountStatusEnum.SENT.getItemValue());
a.setFortuneAccountDate(new Date());
a.setUpdaterId(loginUserId.toString());
a.setUpdateTime(new Date());
});
this.updateBatchById(accountList);
/* 3. 取出关联的所有 fortune 并一次性更新为已出账 ------------------------*/
List<String> accountBizIdList = accountList.stream()
.map(FortuneAccount::getFortuneAccountBizId).collect(Collectors.toList());
List<Fortune> fortunes = fortuneService.lambdaQuery()
.in(Fortune::getFortuneAccountBizId, accountBizIdList)
.eq(Fortune::getStatus, FortuneStatusEnum.CHECKED.getItemValue())
.list();
if (CollectionUtils.isNotEmpty(fortunes)) {
fortunes.forEach(f -> {
f.setStatus(FortuneStatusEnum.SENT.getItemValue());
f.setUpdaterId(loginUserId.toString());
f.setUpdateTime(new Date());
});
fortuneService.updateBatchById(fortunes);
}
this.updateBatchById(fortuneAccountList);
// 更新 Fortune 状态为已出账
List<String> accountBizIdList = fortuneAccountList.stream().map(FortuneAccount::getFortuneAccountBizId).collect(Collectors.toList());
List<Fortune> updateFortuneList = fortuneService.list(new QueryWrapper<Fortune>().in("fortune_account_biz_id", accountBizIdList));
if (CollectionUtils.isNotEmpty(updateFortuneList)) {
for (Fortune item : updateFortuneList) {
item.setStatus(FortuneStatusEnum.SENT.getItemValue());
item.setUpdaterId(loginUserId.toString());
item.setUpdateTime(new Date());
}
fortuneService.updateBatchById(updateFortuneList);
/* 4. 按 expected_fortune 维度重新汇总已出账金额 --------------------------*/
// 4.1 收集所有涉及的 expectedFortuneBizId
Set<String> expectedIds = fortunes.stream()
.map(Fortune::getExpectedFortuneBizId)
.collect(Collectors.toSet());
if (CollectionUtils.isEmpty(expectedIds)) {
return true; // 没有对应预计出账,直接结束
}
// 更新预计出账记录
List<String> expectedFortuneBizIdList = updateFortuneList.stream().map(Fortune::getExpectedFortuneBizId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(expectedFortuneBizIdList)) {
List<ExpectedFortune> expectedFortuneList = expectedFortuneService.list(new QueryWrapper<ExpectedFortune>().in("expected_fortune_biz_id", expectedFortuneBizIdList));
// 预计出账映射
Map<String, ExpectedFortune> expectedFortuneMap = expectedFortuneList.stream()
.collect(Collectors.toMap(ExpectedFortune::getExpectedFortuneBizId, Function.identity()));
// 遍历本次出账记录,更新预计出账记录
for (Fortune item : updateFortuneList) {
ExpectedFortune expectedFortune = expectedFortuneMap.get(item.getExpectedFortuneBizId());
if (Objects.nonNull(expectedFortune)) {
BigDecimal amount = item.getAmount();// 本次出账金额
BigDecimal paidAmount = expectedFortune.getPaidAmount();// 已出账金额
if (expectedFortune.getAmount().compareTo(paidAmount.add(amount)) == 0) {
// 已出账金额等于预计出账金额,更新状态为完成出账
expectedFortune.setPaidAmount(paidAmount.add(amount));
expectedFortune.setUnpaidAmount(BigDecimal.ZERO);
expectedFortune.setStatus(FortuneStatusEnum.SENT.getItemValue());
// 4.2 先锁再算
List<ExpectedFortune> expectedList = expectedFortuneService.lambdaQuery()
.in(ExpectedFortune::getExpectedFortuneBizId, expectedIds)
.last("FOR UPDATE")
.list();
// 4.3 全量汇总:把同一 expected_fortune 下所有 fortune 的 current_payment_amount 求和
Map<String, BigDecimal> paidMap = fortuneService.lambdaQuery()
.in(Fortune::getExpectedFortuneBizId, expectedIds)
.eq(Fortune::getStatus, FortuneStatusEnum.SENT.getItemValue())
.list()
.stream()
.collect(Collectors.groupingBy(Fortune::getExpectedFortuneBizId,
Collectors.mapping(Fortune::getCurrentPaymentAmount,
Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
// 4.4 反写 expected_fortune
expectedList.forEach(ef -> {
BigDecimal totalPaid = paidMap.getOrDefault(ef.getExpectedFortuneBizId(), BigDecimal.ZERO);
BigDecimal totalAmount = ef.getAmount();
BigDecimal unpaid = totalAmount.subtract(totalPaid);
String newStatus;
if (unpaid.compareTo(BigDecimal.ZERO) == 0) {
newStatus = FortuneStatusEnum.SENT.getItemValue(); // 全部完成
} else if (totalPaid.compareTo(BigDecimal.ZERO) > 0) {
newStatus = FortuneStatusEnum.PARTIAL_SENT.getItemValue(); // 部分完成
} else {
// 已出账金额小于预计出账金额,更新已出账金额
expectedFortune.setPaidAmount(paidAmount.add(amount));
expectedFortune.setUnpaidAmount(expectedFortune.getAmount().subtract(paidAmount.add(amount)));
expectedFortune.setUpdaterId(loginUserId.toString());
expectedFortune.setUpdateTime(LocalDateTime.now());
}
}
}
// 更新预计出账记录
expectedFortuneService.updateBatchById(expectedFortuneList);
newStatus = ef.getStatus(); // 无变化
}
expectedFortuneService.lambdaUpdate()
.set(ExpectedFortune::getPaidAmount, totalPaid)
.set(ExpectedFortune::getUnpaidAmount, unpaid)
.set(ExpectedFortune::getPaidRatio,
totalPaid.divide(totalAmount, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)))
.set(ExpectedFortune::getUnpaidRatio,
unpaid.divide(totalAmount, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)))
.set(ExpectedFortune::getStatus, newStatus)
.set(ExpectedFortune::getUpdaterId, loginUserId.toString())
.set(ExpectedFortune::getUpdateTime, LocalDateTime.now())
.eq(ExpectedFortune::getId, ef.getId())
.update();
});
return true;
}
......
......@@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
......@@ -178,43 +179,106 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
if (expectedFortune == null) {
throw new BusinessException(ResultCode.NULL_ERROR.getCode(), "预计出账数据不存在");
}
// 如果是部分出账,新增一条待出账的实际出账记录(fortune)
BigDecimal currentPaymentAmount = fortuneUpdateRequest.getCurrentPaymentAmount();
if (currentPaymentAmount != null && currentPaymentAmount.compareTo(BigDecimal.ZERO) > 0 && currentPaymentAmount.compareTo(expectedFortune.getAmount()) < 0) {
Fortune newFortune = new Fortune();
BeanUtils.copyProperties(fortune, newFortune, "id", "fortuneBizId");
newFortune.setAmount(expectedFortune.getAmount());
newFortune.setCurrentPaymentAmount(expectedFortune.getAmount().subtract(currentPaymentAmount));
newFortune.setStatus(FortuneStatusEnum.WAIT.getItemValue());
newFortune.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode()));
newFortune.setExpectedFortuneBizId(expectedFortune.getExpectedFortuneBizId());
newFortune.setIsPart(1);
// 设置预计出账日期为次月
newFortune.setPayoutDate(calculateReconciliationYearMonth(fortune));
this.save(newFortune);
if (currentPaymentAmount != null) {
if (currentPaymentAmount.compareTo(BigDecimal.ZERO) < 0) {
throw new BusinessException(ResultCode.PARAM_CHECK_ERROR.getCode(), "出账金额不能小于0");
}
if (currentPaymentAmount.compareTo(expectedFortune.getAmount()) > 0) {
throw new BusinessException(ResultCode.PARAM_CHECK_ERROR.getCode(), "出账金额不能大于应付款金额");
}
if (StringUtils.isBlank(fortuneUpdateRequest.getCurrency())) {
throw new BusinessException(ResultCode.PARAM_CHECK_ERROR.getCode(), "出账币种不能为空");
}
}
BeanUtils.copyProperties(fortuneUpdateRequest, fortune, "id", "fortuneBizId", "expectedFortuneBizId", "commissionBizId");
// 获取当前登录用户
AuthUserDto currentLoginUser = SecurityUtil.getCurrentLoginUser();
String loginUserId = currentLoginUser.getId().toString();
// 更新预计出账状态
expectedFortune.setStatus(fortuneUpdateRequest.getStatus());
expectedFortuneService.updateById(expectedFortune);
// 如果传入了金额
if (currentPaymentAmount != null) {
splitFortune(fortune, currentPaymentAmount, loginUserId, fortuneUpdateRequest);
} else {
// 如果未传入金额,仅更新预计出账状态为已出帐
expectedFortuneService.lambdaUpdate()
.set(ExpectedFortune::getStatus, fortuneUpdateRequest.getStatus())
.eq(ExpectedFortune::getId, expectedFortune.getId())
.update();
// 统一更新实际出账数据
BeanUtils.copyProperties(fortuneUpdateRequest, fortune, "id", "fortuneBizId", "expectedFortuneBizId", "commissionBizId");
// 更新实际出账数据
fortune.setUpdaterId(loginUserId);
fortune.setUpdateTime(new Date());
return this.updateById(fortune);
this.updateById(fortune);
}
return true;
}
private LocalDate calculateReconciliationYearMonth(Fortune fortune) {
// 设置预计出账日期为次月
return LocalDate.now().plusMonths(1);
/**
* 拆分发放(按本次发放金额拆)
*/
@Transactional(rollbackFor = Exception.class)
public void splitFortune(Fortune main, BigDecimal currentPaymentAmount, String loginUserId, FortuneUpdateRequest fortuneUpdateRequest) {
if (currentPaymentAmount == null || currentPaymentAmount.compareTo(BigDecimal.ZERO) <= 0)
throw new BusinessException("本次发放金额必须大于0");
if (!main.getStatus().equals(FortuneStatusEnum.CAN_SEND.getItemValue()))
throw new BusinessException("只有可出账记录才能修改金额");
BigDecimal fullAmount = main.getAmount();
if (currentPaymentAmount.compareTo(main.getCurrentPaymentAmount()) > 0)
throw new BusinessException("本次发放金额不能大于可出账金额");
// 1. 更新主行 = 本次发放金额
main.setCurrentPaymentAmount(currentPaymentAmount);
main.setStatus(FortuneStatusEnum.CHECKED.getItemValue());
main.setUpdaterId(loginUserId);
main.setUpdateTime(new Date());
// 其他字段更新
if (StringUtils.isNotBlank(fortuneUpdateRequest.getCurrency())) {
main.setCurrency(fortuneUpdateRequest.getCurrency());
}
this.updateById(main);
// 2. 剩余金额生成新行
BigDecimal leftAmount = fullAmount.subtract(currentPaymentAmount);
if (leftAmount.compareTo(BigDecimal.ZERO) > 0) {
Fortune part = new Fortune();
BeanUtils.copyProperties(main, part, "id", "fortuneBizId", "currentPaymentAmount", "status", "isPart", "payoutDate");
part.setFortuneBizId(RandomStringGenerator.generateBizId16(CommonEnum.UID_TYPE_FORTUNE.getCode()));
part.setCurrentPaymentAmount(leftAmount);
part.setStatus(FortuneStatusEnum.WAIT.getItemValue());
part.setIsPart(1);
part.setPayoutDate(LocalDate.now().plusMonths(1)); // 次月
part.setCreatorId(loginUserId);
part.setCreateTime(new Date());
this.save(part);
}
// 3. 同步 expected_fortune
ExpectedFortune ef = expectedFortuneService.lambdaQuery()
.eq(ExpectedFortune::getExpectedFortuneBizId, main.getExpectedFortuneBizId())
.one();
if (ef == null) return;
BigDecimal newPaid = ef.getPaidAmount() == null ? BigDecimal.ZERO : ef.getPaidAmount().add(currentPaymentAmount);
BigDecimal newUnpaid = ef.getAmount().subtract(newPaid);
String newStatus = newUnpaid.compareTo(BigDecimal.ZERO) == 0 ? "6" : "3";
expectedFortuneService.lambdaUpdate()
.set(ExpectedFortune::getPaidAmount, newPaid)
.set(ExpectedFortune::getUnpaidAmount, newUnpaid)
.set(ExpectedFortune::getPaidRatio,
newPaid.divide(ef.getAmount(), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)))
.set(ExpectedFortune::getUnpaidRatio,
newUnpaid.divide(ef.getAmount(), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)))
.set(ExpectedFortune::getStatus, newStatus)
.eq(ExpectedFortune::getId, ef.getId())
.update();
}
@Override
......@@ -258,6 +322,9 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
if (!StringUtils.equals(fortune.getStatus(), FortuneStatusEnum.CHECKED.getItemValue())) {
validateMsg.append(fortune.getPolicyNo()).append("-").append(fortune.getBroker()).append("未检核,不能生成出账记录; ");
}
if (StringUtils.equals(fortune.getStatus(), FortuneStatusEnum.SENT.getItemValue())) {
validateMsg.append(fortune.getPolicyNo()).append("-").append(fortune.getBroker()).append("已完成出账,不能生成出账记录; ");
}
}
if (StringUtils.isNotBlank(validateMsg.toString())) {
throw new BusinessException(ResultCode.FAIL.getCode(), validateMsg.toString());
......@@ -294,7 +361,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
// 计算出账总额
BigDecimal totalAmount = brokerFortunes.stream()
.map(Fortune::getAmount)
.map(Fortune::getCurrentPaymentAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
accountDTO.setAmount(totalAmount);
......@@ -302,7 +369,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
Map<String, BigDecimal> fortuneAmountMap = brokerFortunes.stream()
.collect(Collectors.groupingBy(
Fortune::getFortuneName,
Collectors.reducing(BigDecimal.ZERO, Fortune::getAmount, BigDecimal::add)
Collectors.reducing(BigDecimal.ZERO, Fortune::getCurrentPaymentAmount, BigDecimal::add)
));
// 设置各个fortune项目的金额
......
......@@ -6,6 +6,7 @@ import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import com.yd.csf.feign.response.expectedfortune.ApiExpectedFortunePageResponse;
import com.yd.csf.service.enums.FortuneStatusEnum;
import com.yd.csf.service.model.ExpectedFortune;
import lombok.Data;
......@@ -111,31 +112,29 @@ public class ExpectedFortuneExportDTO {
/**
* 将对象转换为导出DTO
*/
public static ExpectedFortuneExportDTO convertToExportDTO(ExpectedFortune expectedFortune) {
public static ExpectedFortuneExportDTO convertToExportDTO(ApiExpectedFortunePageResponse vo) {
ExpectedFortuneExportDTO dto = new ExpectedFortuneExportDTO();
dto.setExpectedFortuneBizId(expectedFortune.getExpectedFortuneBizId());
dto.setPayableNo(expectedFortune.getPayableNo());
dto.setFortuneBizType("R".equals(expectedFortune.getFortuneBizType()) ? "关联保单应付款" : "非关联保单应付款");
dto.setPolicyNo(expectedFortune.getPolicyNo());
dto.setPremium(expectedFortune.getPremium());
dto.setFortunePeriod(expectedFortune.getFortunePeriod());
dto.setFortuneTotalPeriod(expectedFortune.getFortuneTotalPeriod());
dto.setBroker(expectedFortune.getBroker());
dto.setTeam(expectedFortune.getTeam());
dto.setFortuneName(expectedFortune.getFortuneName());
dto.setBrokerRatio(expectedFortune.getBrokerRatio());
dto.setAmount(expectedFortune.getAmount());
dto.setCurrency(expectedFortune.getCurrency());
dto.setStatus(getStatusText(expectedFortune.getStatus()));
dto.setStatusDesc(expectedFortune.getStatusDesc());
dto.setPayoutDate(Convert.toDate(expectedFortune.getPayoutDate()));
dto.setActualPayoutDate(Convert.toDate(expectedFortune.getActualPayoutDate()));
dto.setPaidAmount(expectedFortune.getPaidAmount());
dto.setUnpaidAmount(expectedFortune.getUnpaidAmount());
dto.setPaidRatio(expectedFortune.getPaidRatio());
dto.setRemark(expectedFortune.getRemark());
dto.setCreateTime(expectedFortune.getCreateTime());
dto.setUpdateTime(expectedFortune.getUpdateTime());
dto.setExpectedFortuneBizId(vo.getExpectedFortuneBizId());
dto.setPayableNo(vo.getPayableNo());
dto.setFortuneBizType("R".equals(vo.getFortuneBizType()) ? "关联保单应付款" : "非关联保单应付款");
dto.setPolicyNo(vo.getPolicyNo());
dto.setPremium(vo.getPremium());
dto.setFortunePeriod(vo.getFortunePeriod());
dto.setFortuneTotalPeriod(vo.getFortuneTotalPeriod());
dto.setBroker(vo.getBroker());
dto.setTeam(vo.getTeam());
dto.setFortuneName(vo.getFortuneName());
dto.setBrokerRatio(vo.getBrokerRatio());
dto.setAmount(vo.getAmount());
dto.setCurrency(vo.getCurrency());
dto.setStatus(getStatusText(vo.getStatus()));
dto.setStatusDesc(vo.getStatusDesc());
dto.setPayoutDate(Convert.toDate(vo.getPayoutDate()));
dto.setActualPayoutDate(Convert.toDate(vo.getActualPayoutDate()));
dto.setPaidAmount(vo.getPaidAmount());
dto.setUnpaidAmount(vo.getUnpaidAmount());
dto.setPaidRatio(vo.getPaidRatio());
dto.setRemark(vo.getRemark());
return dto;
}
......
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