Commit 7b08b78e by jianan

Merge branch 'refs/heads/test_zjn' into test

parents 976f5fa0 432acea3
......@@ -968,22 +968,59 @@ public class ApiExpectedFortuneServiceImpl implements ApiExpectedFortuneService
@Override
public Result<ApiExpectedFortunePageResponseVO> list(ApiExpectedFortunePageRequest request) {
Page<ExpectedFortune> page = new Page<>(request.getPageNo(), request.getPageSize());
// 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);
}
QueryWrapper<ExpectedFortune> queryWrapper = this.getQueryWrapper(request);
IPage<ExpectedFortune> iPage = iExpectedFortuneService.page(page, queryWrapper);
// 查询统计数据
List<ExpectedFortune> fortuneList = iExpectedFortuneService.list(queryWrapper);
ExpectedFortuneStatisticsVO statisticsVO = this.getStatistics(fortuneList.stream().map(ExpectedFortune::getId).collect(Collectors.toList()));
long startTime = System.currentTimeMillis();
try {
// 2. 构建查询条件
QueryWrapper<ExpectedFortune> queryWrapper = this.getQueryWrapper(request);
// 3. 查询分页列表(UNION ALL 查询,包含预计发佣和实际发佣)
IPage<ApiExpectedFortunePageResponse> iPage = iExpectedFortuneService.queryListNew(
request.getPageNo(),
request.getPageSize(),
queryWrapper
);
// 查询实际发佣列表
List<Fortune> expectedFortuneList = fortuneService.list();
// 4. 查询统计数据(使用 SQL 聚合,不加载明细)
ExpectedFortuneStatisticsVO statisticsVO = iExpectedFortuneService.queryListStatistics(queryWrapper);
// 组装返回结果
ApiExpectedFortunePageResponseVO response = new ApiExpectedFortunePageResponseVO();
response.setStatisticsVO(statisticsVO);
response.setPage(iExpectedFortuneService.getVOPage(iPage));
return Result.success(response);
// 计算已出账比例
BigDecimal totalAmount = statisticsVO.getTotalExpectedAmount();
BigDecimal totalPaidAmount = statisticsVO.getTotalPaidAmount();
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. 组装返回结果
ApiExpectedFortunePageResponseVO response = new ApiExpectedFortunePageResponseVO();
response.setStatisticsVO(statisticsVO);
response.setPage(iPage); // 恢复分页数据
log.info("查询应付款管理列表完成, 耗时: {}ms, 页码: {}, 页大小: {}, 总记录数: {}",
System.currentTimeMillis() - startTime,
request.getPageNo(),
request.getPageSize(),
iPage.getTotal());
return Result.success(response);
} catch (Exception e) {
log.error("查询应付款管理列表失败", e);
return Result.fail(ResultCode.FAIL.getCode(), "查询失败: " + e.getMessage());
}
}
@Override
......
......@@ -18,6 +18,12 @@ public class ApiExpectedFortunePageResponse {
private Long id;
/**
* 是否实际出账:1-预计出账 2-实际出账
*/
@Schema(description = "是否实际出账:1-预计出账 2-实际出账")
private Integer type;
/**
* 预计出账表唯一业务id
*/
@Schema(description = "expected fortune biz id")
......@@ -131,23 +137,19 @@ public class ApiExpectedFortunePageResponse {
@Schema(description = "转介人介绍费占比")
private String brokerRatio;
/**
* 标准出佣金额
*/
@Schema(description = "标准出佣金额")
private BigDecimal standardAmount;
// ========== 保单币种及金额(基本法币种) ==========
/**
* 应出账金额(预计发佣金额 = 标准发佣金额 * 转介人介绍费占比)
* 保单币种金额(保单币种金额 = 标准发佣金额 * 转介人介绍费占比)
*/
@Schema(description = "应出账金额(预计发佣金额 = 标准发佣金额 * 转介人介绍费占比)")
private BigDecimal amount;
@Schema(description = "保单币种金额(保单币种金额 = 标准发佣金额 * 转介人介绍费占比)")
private BigDecimal ruleAmount;
/**
* 出账币种
* 保单币种
*/
@Schema(description = "出账币种")
private String currency;
@Schema(description = "保单币种")
private String ruleCurrency;
/**
* 出账币种名称
......@@ -156,15 +158,15 @@ public class ApiExpectedFortunePageResponse {
private String currencyName;
/**
* 默认结算汇率
* 保单币种 -> 港币汇率
*/
@Schema(description = "默认结算汇率")
private BigDecimal defaultExchangeRate;
@Schema(description = "保单币种 -> 港币汇率")
private BigDecimal exchangeRate;
/**
* 港币预计出账金额
* HKD应出账金额
*/
@Schema(description = "港币预计出账金额")
@Schema(description = "HKD应出账金额")
private BigDecimal hkdAmount;
/**
......@@ -180,23 +182,23 @@ public class ApiExpectedFortunePageResponse {
private String statusDesc;
/**
* 预计出账日期
* 出账年月(估)
*/
@Schema(description = "预计出账日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Schema(description = "出账年月(估)")
@JsonFormat(pattern = "yyyy-MM", timezone = "GMT+8")
private LocalDate payoutDate;
/**
* 实际出账日期
* 出账年月(实)
*/
@Schema(description = "实际出账日期")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Schema(description = "出账年月(实)")
@JsonFormat(pattern = "yyyy-MM", timezone = "GMT+8")
private LocalDate actualPayoutDate;
/**
* 已出账金额
* 已出账金额(HKD)
*/
@Schema(description = "已出账金额")
@Schema(description = "已出账金额(HKD)")
private BigDecimal paidAmount;
/**
......
package com.yd.csf.service.dao;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yd.csf.feign.request.expectedfortune.ApiExpectedFortunePageRequest;
......@@ -44,4 +45,13 @@ public interface ExpectedFortuneMapper extends BaseMapper<ExpectedFortune> {
* @param status 出账状态
*/
void updateBatchByBizId(@Param("expectedFortuneBizIdList") List<String> expectedFortuneBizIdList, @Param("status") String status);
IPage<ApiExpectedFortunePageResponse> queryListNew(Integer pageNo, Integer pageSize, @Param("ew") QueryWrapper<ExpectedFortune> queryWrapper);
/**
* 查询预计发佣和实际发佣的统计数据(使用 SQL 聚合)
* @param queryWrapper 查询条件
* @return 统计信息
*/
ExpectedFortuneStatisticsVO queryListStatistics(@Param("ew") QueryWrapper<ExpectedFortune> queryWrapper);
}
......@@ -188,7 +188,7 @@ public class ExpectedFortune implements Serializable {
private LocalDate actualPayoutDate;
/**
* 默认保单币种汇率
* 默认保单币种 -> 港币汇率
*/
@TableField("default_exchange_rate")
private BigDecimal defaultExchangeRate;
......
package com.yd.csf.service.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yd.csf.feign.request.expectedfortune.ApiExpectedFortunePageRequest;
......@@ -56,4 +57,13 @@ public interface IExpectedFortuneService extends IService<ExpectedFortune> {
* @return 应付款编号
*/
String getPayableNo(String fortuneType);
IPage<ApiExpectedFortunePageResponse> queryListNew(Integer pageNo, Integer pageSize, QueryWrapper<ExpectedFortune> queryWrapper);
/**
* 查询预计发佣和实际发佣的统计数据(使用 SQL 聚合)
* @param queryWrapper 查询条件
* @return 统计信息
*/
ExpectedFortuneStatisticsVO queryListStatistics(QueryWrapper<ExpectedFortune> queryWrapper);
}
......@@ -211,4 +211,20 @@ public class ExpectedFortuneServiceImpl extends ServiceImpl<ExpectedFortuneMappe
LocalDate.now().getYear() % 100,
currentSeq + 1);
}
@Override
public IPage<ApiExpectedFortunePageResponse> queryListNew(Integer pageNo, Integer pageSize, QueryWrapper<ExpectedFortune> queryWrapper) {
return this.baseMapper.queryListNew(pageNo, pageSize, queryWrapper);
}
@Override
public ExpectedFortuneStatisticsVO queryListStatistics(QueryWrapper<ExpectedFortune> queryWrapper) {
ExpectedFortuneStatisticsVO statistics = this.baseMapper.queryListStatistics(queryWrapper);
if (statistics == null) {
return new ExpectedFortuneStatisticsVO();
}
return statistics;
}
}
......@@ -149,4 +149,160 @@
and ef.is_deleted = 0
</where>
</select>
<select id="queryListNew"
resultType="com.yd.csf.feign.response.expectedfortune.ApiExpectedFortunePageResponse">
<bind name="offset" value="(pageNo - 1) * pageSize" />
SELECT
ef.id,
ef.expected_fortune_biz_id,
ef.fortune_biz_type,
ef.is_part,
ef.payable_no,
ef.policy_no,
ef.premium,
ef.policy_currency,
ef.insurance_company_biz_id,
ef.product_launch_biz_id,
ef.fortune_period,
ef.fortune_total_period,
ef.broker,
ef.broker_biz_id,
ef.team,
ef.team_biz_id,
ef.fortune_name,
ef.fortune_type,
ef.broker_ratio,
ef.rule_amount,
ef.rule_currency,
ef.status,
ef.status_desc,
ef.payout_date,
ef.actual_payout_date,
ef.default_exchange_rate,
ef.original_currency,
ef.original_amount,
ef.original_to_hkd_rate,
ef.payout_currency,
ef.payout_amount,
ef.hkd_to_payout_rate,
ef.hkd_amount,
ef.paid_amount,
ef.unpaid_amount,
ef.paid_ratio,
ef.unpaid_ratio,
ef.is_tax,
ef.tax_amount,
ef.net_amount,
ef.rule_item_biz_id,
ef.remark,
ef.create_time,
ef.creator_name,
ef.update_time,
1 as type
FROM expected_fortune ef
<where>
ef.is_deleted = 0
AND ef.is_part IN (0, 1)
<if test="ew != null">
<if test="ew.sqlSegment != null and ew.sqlSegment != ''">
AND ${ew.sqlSegment}
</if>
</if>
</where>
UNION ALL
SELECT
f.id,
f.expected_fortune_biz_id,
f.fortune_biz_type,
f.is_part,
f.payable_no,
f.policy_no,
f.premium,
f.policy_currency,
NULL as insurance_company_biz_id,
NULL as product_launch_biz_id,
f.fortune_period,
f.fortune_total_period,
f.broker,
f.broker_biz_id,
f.team,
f.team_biz_id,
f.fortune_name,
f.fortune_type,
NULL as broker_ratio,
f.rule_amount,
f.rule_currency,
f.status,
NULL as status_desc,
f.payout_date,
f.actual_payout_date,
f.exchange_rate as default_exchange_rate,
f.original_currency,
f.original_amount,
f.original_to_hkd_rate,
f.payout_currency,
f.payout_amount,
f.hkd_to_payout_rate,
f.hkd_amount,
f.current_payment_amount as paid_amount,
0 as unpaid_amount,
f.current_payment_ratio as paid_ratio,
0 as unpaid_ratio,
f.is_tax,
f.tax_amount,
f.net_amount,
NULL as rule_item_biz_id,
f.remark,
f.create_time,
NULL as creator_name,
f.update_time,
2 as type
FROM fortune f
<where>
f.is_deleted = 0
AND f.is_part IN (0, 1)
<if test="ew != null">
<if test="ew.sqlSegment != null and ew.sqlSegment != ''">
AND ${ew.sqlSegment}
</if>
</if>
</where>
ORDER BY id ASC
LIMIT #{pageSize} OFFSET #{offset}
</select>
<select id="queryListStatistics" resultType="com.yd.csf.service.vo.ExpectedFortuneStatisticsVO">
SELECT
COALESCE(SUM(ef.hkd_amount), 0) AS totalExpectedAmount,
COALESCE(SUM(ef.paid_amount), 0) AS totalPaidAmount,
COALESCE(SUM(ef.unpaid_amount), 0) AS totalUnpaidAmount,
COALESCE(
(SELECT SUM(p.total_payment_premium) * MAX(ef2.default_exchange_rate)
FROM expected_fortune ef2
LEFT JOIN policy p ON ef2.policy_no = p.policy_no
WHERE ef2.is_deleted = 0 AND ef2.is_part IN (0, 1)
<if test="ew != null">
<if test="ew.sqlSegment != null and ew.sqlSegment != ''">
AND ${ew.sqlSegment}
</if>
</if>
), 0
) AS totalPremiumAmount,
COUNT(DISTINCT ef.policy_no) AS totalPolicyCount
FROM expected_fortune ef
<where>
ef.is_deleted = 0
AND ef.is_part IN (0, 1)
<if test="ew != null">
<if test="ew.sqlSegment != null and ew.sqlSegment != ''">
AND ${ew.sqlSegment}
</if>
</if>
</where>
</select>
</mapper>
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