Commit 9e224425 by jianan

应付明细7

parent 34effecd
...@@ -1232,25 +1232,44 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService ...@@ -1232,25 +1232,44 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
@Override @Override
public Result<PayableReportResponse> payableReport(ApiExpectedFortunePageRequest request) { public Result<PayableReportResponse> payableReport(ApiExpectedFortunePageRequest request) {
// 构建查询条件 // 1. 参数校验
if (request == null) {
return Result.fail(ResultCode.PARAMS_ERROR.getCode(), "查询参数不能为空");
}
if (request.getPageNo() == null || request.getPageNo() < 1) {
request.setPageNo(1);
}
if (request.getPageSize() == null || request.getPageSize() < 1) {
request.setPageSize(10);
}
// 2. 构建查询条件(复用 getQueryWrapper,与 /list 共用同一套条件)
QueryWrapper<ExpectedFortune> queryWrapper = this.getQueryWrapper(request); QueryWrapper<ExpectedFortune> queryWrapper = this.getQueryWrapper(request);
// 先查询所有符合条件的记录ID(用于统计) // 3. 移除 QueryWrapper 中的排序,避免在 UNION ALL 的子查询中出现 ORDER BY
List<ExpectedFortune> allFortuneList = iExpectedFortuneService.list(queryWrapper); queryWrapper.getExpression().getOrderBy().clear();
List<Long> allFortuneIdList = allFortuneList.stream().map(ExpectedFortune::getId).collect(Collectors.toList());
// 4. 查询统计数据(直接传递 QueryWrapper,在 SQL 中聚合计算,不再加载明细到内存)
ExpectedFortuneStatisticsVO statisticsVO = iExpectedFortuneService.queryListStatistics(queryWrapper);
// 查询统计数据(基于所有符合条件的记录) // 计算待出账金额和已出账比例
ExpectedFortuneStatisticsVO statisticsVO = this.getStatistics(allFortuneIdList); BigDecimal totalAmount = statisticsVO.getTotalExpectedAmount();
BigDecimal totalPaidAmount = statisticsVO.getTotalPaidAmount();
statisticsVO.setTotalUnpaidAmount(totalAmount.subtract(totalPaidAmount));
BigDecimal divided = BigDecimal.ZERO;
if (totalAmount.compareTo(BigDecimal.ZERO) > 0) {
divided = totalPaidAmount.divide(totalAmount, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
}
statisticsVO.setPaidAmountRatio(divided);
// 应付款报表分页查询 - 按保单号和期数维度统计 // 5. 应付款报表分页查询(按保单号和期数维度统计,直接传递 QueryWrapper)
Page<PayableReportVO> reportPage = new Page<>(request.getPageNo(), request.getPageSize()); Page<PayableReportVO> reportPage = new Page<>(request.getPageNo(), request.getPageSize());
IPage<PayableReportVO> payableReportPage = new Page<>(request.getPageNo(), request.getPageSize()); IPage<PayableReportVO> payableReportPage = iExpectedFortuneService.payableReportPage(reportPage, queryWrapper);
if (!CollectionUtils.isEmpty(allFortuneIdList)) {
payableReportPage = iExpectedFortuneService.payableReportPage(reportPage, allFortuneIdList);
}
// 6. 数据补充(转介人等级、保单持有人、产品名称等信息)
payableReportPage = convertPayableReportVO(payableReportPage); payableReportPage = convertPayableReportVO(payableReportPage);
// 组装返回结果
// 7. 组装返回结果
PayableReportResponse response = new PayableReportResponse(); PayableReportResponse response = new PayableReportResponse();
response.setStatisticsVO(statisticsVO); response.setStatisticsVO(statisticsVO);
response.setPage(payableReportPage); response.setPage(payableReportPage);
......
...@@ -33,11 +33,11 @@ public interface ExpectedFortuneMapper extends BaseMapper<ExpectedFortune> { ...@@ -33,11 +33,11 @@ public interface ExpectedFortuneMapper extends BaseMapper<ExpectedFortune> {
/** /**
* 应付款报表 - 按保单号和期数维度统计(分页) * 应付款报表 - 按保单号和期数维度统计(分页)
* @param page 分页参数 * @param page 分页参数
* @param expectedFortuneIds 预计发佣ID列表 * @param queryWrapper 查询条件
* @return 应付款报表VO分页列表 * @return 应付款报表VO分页列表
*/ */
IPage<PayableReportVO> payableReportPage(@Param("page") Page<PayableReportVO> page, IPage<PayableReportVO> payableReportPage(@Param("page") Page<PayableReportVO> page,
@Param("expectedFortuneIds") List<Long> expectedFortuneIds); @Param("ew") QueryWrapper<ExpectedFortune> queryWrapper);
/** /**
* 更新预计发佣记录的出账状态 * 更新预计发佣记录的出账状态
......
...@@ -41,10 +41,10 @@ public interface IExpectedFortuneService extends IService<ExpectedFortune> { ...@@ -41,10 +41,10 @@ public interface IExpectedFortuneService extends IService<ExpectedFortune> {
* 应付款报表 - 按保单号和期数维度统计(分页) * 应付款报表 - 按保单号和期数维度统计(分页)
* *
* @param page 分页参数 * @param page 分页参数
* @param expectedFortuneIds 预计发佣ID列表 * @param queryWrapper 查询条件
* @return 应付款报表VO分页列表 * @return 应付款报表VO分页列表
*/ */
IPage<PayableReportVO> payableReportPage(Page<PayableReportVO> page, List<Long> expectedFortuneIds); IPage<PayableReportVO> payableReportPage(Page<PayableReportVO> page, QueryWrapper<ExpectedFortune> queryWrapper);
void updateBatchByBizId(List<String> expectedFortuneBizIdList, String status); void updateBatchByBizId(List<String> expectedFortuneBizIdList, String status);
......
...@@ -258,8 +258,8 @@ public class ExpectedFortuneServiceImpl extends ServiceImpl<ExpectedFortuneMappe ...@@ -258,8 +258,8 @@ public class ExpectedFortuneServiceImpl extends ServiceImpl<ExpectedFortuneMappe
} }
@Override @Override
public IPage<PayableReportVO> payableReportPage(Page<PayableReportVO> page, List<Long> expectedFortuneIds) { public IPage<PayableReportVO> payableReportPage(Page<PayableReportVO> page, QueryWrapper<ExpectedFortune> queryWrapper) {
return baseMapper.payableReportPage(page, expectedFortuneIds); return baseMapper.payableReportPage(page, queryWrapper);
} }
@Override @Override
......
...@@ -87,13 +87,14 @@ ...@@ -87,13 +87,14 @@
left join policy_follow pf on ef.policy_no = pf.policy_no left join policy_follow pf on ef.policy_no = pf.policy_no
<where> <where>
ef.fortune_biz_type = 'R' ef.fortune_biz_type = 'R'
<if test="expectedFortuneIds != null and expectedFortuneIds.size > 0">
and ef.id in
<foreach collection="expectedFortuneIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
and ef.is_deleted = 0 and ef.is_deleted = 0
AND ef.is_part in (0,1)
<if test="ew != null and ew.sqlSegment != null and ew.sqlSegment != ''">
AND ef.id IN (
SELECT ef2.id FROM expected_fortune ef2
WHERE ${ew.sqlSegment}
)
</if>
</where> </where>
group by ef.policy_no, ef.fortune_period group by ef.policy_no, ef.fortune_period
union all union all
...@@ -130,13 +131,14 @@ ...@@ -130,13 +131,14 @@
left join policy p on ef.policy_no = p.policy_no left join policy p on ef.policy_no = p.policy_no
<where> <where>
ef.fortune_biz_type = 'U' ef.fortune_biz_type = 'U'
<if test="expectedFortuneIds != null and expectedFortuneIds.size > 0">
and ef.id in
<foreach collection="expectedFortuneIds" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
and ef.is_deleted = 0 and ef.is_deleted = 0
AND ef.is_part in (0,1)
<if test="ew != null and ew.sqlSegment != null and ew.sqlSegment != ''">
AND ef.id IN (
SELECT ef2.id FROM expected_fortune ef2
WHERE ${ew.sqlSegment}
)
</if>
</where> </where>
</select> </select>
......
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