Commit 6d133f0f by 林永健

feat(integral): 添加一键付款前限制门店校验功能

- 在 IntegralController 中新增 transferOutCheckAllPayHasLimitStore 接口
- 在 IntegralTransferOutMapper 中添加 existsLimitStore 方法和对应的 SQL 查询
- 在 IntegralTransferOutRemote 和实现类中新增 checkAllPayHasLimitStore 远程调用
- 在 IntegralTransferOutService 中实现限制门店校验业务逻辑
- 重构 IntegralTransferOutMapper.xml 中的查询条件为可复用的 sql 片段
- 添加专门用于限制门店校验的 existsLimitStore 查询,使用 select 1 limit 1 优化性能
1 parent 66335d48
......@@ -119,6 +119,11 @@ public interface IntegralTransferOutRemote {
@ApiResponse("结果")
RpcResponse<Boolean> allPay(IntegralTransferOutDTO request);
@ApiMethod("一键付款前校验是否存在限制门店")
@ApiParam(name = "request", notes = "参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("是否存在限制门店")
RpcResponse<Boolean> checkAllPayHasLimitStore(IntegralTransferOutDTO request);
@ApiMethod("一键操作获取合计金额,校验")
@ApiParam(name = "request", notes = "参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("结果")
......
......@@ -74,4 +74,12 @@ public interface IntegralTransferOutMapper extends OreMapper<IntegralTransferOut
* @return 去重后的省份快照行
*/
List<IntegralTransferOut> listDistinctProvinces();
/**
* 判断是否存在限制门店(一键付款前校验,select 1 limit 1,不走 list 全量查询)。
*
* @param request 查询条件
* @return 1=存在,null=不存在
*/
Integer existsLimitStore(IntegralTransferOutDTO request);
}
\ No newline at end of file
......@@ -342,6 +342,21 @@ public class IntegralTransferOutRemoteImpl implements IntegralTransferOutRemote
}
@Override
public RpcResponse<Boolean> checkAllPayHasLimitStore(IntegralTransferOutDTO request) {
try {
return RpcResponse.success(integralTransferOutService.checkAllPayHasLimitStore(request));
} catch (Exception e) {
log.error("IntegralTransferOutRemote.checkAllPayHasLimitStore exception:{}", e);
if (e instanceof RpcServiceException) {
RpcServiceException rse = (RpcServiceException) e;
return RpcResponse.error(rse);
} else {
return RpcResponse.error(DefaultErrorEnum.SERVER_ERROR);
}
}
}
@Override
public RpcResponse<IntegralTransferOutBatchCheckDTO> getAllCheckByCondition(IntegralTransferOutDTO request) {
try {
return RpcResponse.success(integralTransferOutService.getAllCheckByCondition(request));
......
......@@ -676,6 +676,28 @@ public class IntegralTransferOutService {
}
/**
* 一键付款前校验是否存在限制门店。
*
* @param request 查询条件(与一键付款筛选条件一致)
* @return true=存在限制门店,false=不存在
*/
public Boolean checkAllPayHasLimitStore(IntegralTransferOutDTO request) {
try {
List<String> merchantNos = listLimitStoreMerchantNos();
if (CollectionUtils.isEmpty(merchantNos)) {
return false;
}
request.setLimitStoreMerchantNos(merchantNos);
// SQL 已过滤 transfer_type != 0(排除积分提现),与一键付款逻辑一致;select 1 limit 1 仅判断是否存在
Integer exists = integralTransferOutMapper.existsLimitStore(request);
return exists != null && exists > 0;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e.getMessage());
}
}
/**
* 通过id查询详情
*
* @param id
......
......@@ -86,96 +86,7 @@
from shopmall_integral_transfer_out ito
<where>
ito.deleted_flag = 'N'
<if test="merchantId != null">
and ito.merchant_id = #{merchantId}
</if>
<if test="merchantName != null and merchantName != ''">
and ito.merchant_name = #{merchantName}
</if>
<if test="channel != null and channel != ''">
and ito.channel = #{channel}
</if>
<if test="outSettleOrderId != null and outSettleOrderId != ''">
and ito.out_settle_order_id like CONCAT('%',#{outSettleOrderId},'%')
</if>
<if test="customerName != null and customerName != ''">
and ito.customer_name like CONCAT('%',#{customerName},'%')
</if>
<if test="customerPhone != null and customerPhone != ''">
and ito.customer_phone like CONCAT('%',#{customerPhone},'%')
</if>
<if test="name != null and name != ''">
and ito.name like CONCAT('%',#{name},'%')
</if>
<if test="status != null and status != ''">
and ito.status = #{status}
</if>
<if test="applyDateStart != null and applyDateStart != ''">
and ito.created_date &gt;= #{applyDateStart}
</if>
<if test="applyDateEnd != null and applyDateEnd != ''">
and ito.created_date &lt;= #{applyDateEnd}
</if>
<if test="payDateStart != null and payDateStart != ''">
and ito.pay_date &gt;= #{payDateStart}
</if>
<if test="payDateEnd != null and payDateEnd != ''">
and ito.pay_date &lt;= #{payDateEnd}
</if>
<if test="receiptDateStart != null and receiptDateStart != ''">
and ito.receipt_date &gt;= #{receiptDateStart}
</if>
<if test="receiptDateEnd != null and receiptDateEnd != ''">
and ito.receipt_date &lt;= #{receiptDateEnd}
</if>
<if test="transferType != null">
and ito.transfer_type = #{transferType}
</if>
<if test="mode != null">
and ito.mode = #{mode}
</if>
<if test="withdrawalSource != null">
and ito.source = #{withdrawalSource}
</if>
<if test="paymentEntityCode != null and paymentEntityCode != ''">
and ito.payment_entity_code = #{paymentEntityCode}
</if>
<if test="levyCode != null and levyCode != ''">
and ito.levy_code = #{levyCode}
</if>
<if test="levyChannelCode != null and levyChannelCode != ''">
and ito.levy_channel_code = #{levyChannelCode}
</if>
<if test="approvalId != null">
and ito.approval_id = #{approvalId}
</if>
<if test="realityMerchantName != null and realityMerchantName != ''">
and ito.reality_platform_merchant_name like CONCAT('%',#{realityMerchantName},'%')
</if>
<if test="mainBrandIds != null and mainBrandIds.size() > 0">
and
<foreach collection="mainBrandIds" item="brandId" open="(" close=")" separator=" or ">
FIND_IN_SET(#{brandId}, ito.main_brand_id)
</foreach>
</if>
<if test="provinceCodes != null and provinceCodes.size() > 0">
and ito.province_code in
<foreach collection="provinceCodes" item="code" open="(" close=")" separator=",">
#{code}
</foreach>
</if>
<if test="merchantIds != null and merchantIds.size() > 0">
and ito.merchant_id in
<foreach collection="merchantIds" item="merchantIdItem" open="(" close=")" separator=",">
#{merchantIdItem}
</foreach>
</if>
<if test="transferOutTagIds != null and transferOutTagIds.size() > 0">
and ito.transfer_out_tag_id in
<foreach collection="transferOutTagIds" item="tagId" open="(" close=")" separator=",">
#{tagId}
</foreach>
</if>
<include refid="ListWhereConditions" />
<choose>
<when test="limitStoreFlagQuery != null and limitStoreFlagQuery == 'Y'.toString()">
<if test="limitStoreMerchantNos != null and limitStoreMerchantNos.size() > 0">
......@@ -202,6 +113,120 @@
order by ito.id desc
</select>
<sql id="ListWhereConditions">
<if test="merchantId != null">
and ito.merchant_id = #{merchantId}
</if>
<if test="merchantName != null and merchantName != ''">
and ito.merchant_name = #{merchantName}
</if>
<if test="channel != null and channel != ''">
and ito.channel = #{channel}
</if>
<if test="outSettleOrderId != null and outSettleOrderId != ''">
and ito.out_settle_order_id like CONCAT('%',#{outSettleOrderId},'%')
</if>
<if test="customerName != null and customerName != ''">
and ito.customer_name like CONCAT('%',#{customerName},'%')
</if>
<if test="customerPhone != null and customerPhone != ''">
and ito.customer_phone like CONCAT('%',#{customerPhone},'%')
</if>
<if test="name != null and name != ''">
and ito.name like CONCAT('%',#{name},'%')
</if>
<if test="status != null and status != ''">
and ito.status = #{status}
</if>
<if test="applyDateStart != null and applyDateStart != ''">
and ito.created_date &gt;= #{applyDateStart}
</if>
<if test="applyDateEnd != null and applyDateEnd != ''">
and ito.created_date &lt;= #{applyDateEnd}
</if>
<if test="payDateStart != null and payDateStart != ''">
and ito.pay_date &gt;= #{payDateStart}
</if>
<if test="payDateEnd != null and payDateEnd != ''">
and ito.pay_date &lt;= #{payDateEnd}
</if>
<if test="receiptDateStart != null and receiptDateStart != ''">
and ito.receipt_date &gt;= #{receiptDateStart}
</if>
<if test="receiptDateEnd != null and receiptDateEnd != ''">
and ito.receipt_date &lt;= #{receiptDateEnd}
</if>
<if test="transferType != null">
and ito.transfer_type = #{transferType}
</if>
<if test="mode != null">
and ito.mode = #{mode}
</if>
<if test="withdrawalSource != null">
and ito.source = #{withdrawalSource}
</if>
<if test="paymentEntityCode != null and paymentEntityCode != ''">
and ito.payment_entity_code = #{paymentEntityCode}
</if>
<if test="levyCode != null and levyCode != ''">
and ito.levy_code = #{levyCode}
</if>
<if test="levyChannelCode != null and levyChannelCode != ''">
and ito.levy_channel_code = #{levyChannelCode}
</if>
<if test="approvalId != null">
and ito.approval_id = #{approvalId}
</if>
<if test="realityMerchantName != null and realityMerchantName != ''">
and ito.reality_platform_merchant_name like CONCAT('%',#{realityMerchantName},'%')
</if>
<if test="mainBrandIds != null and mainBrandIds.size() > 0">
and
<foreach collection="mainBrandIds" item="brandId" open="(" close=")" separator=" or ">
FIND_IN_SET(#{brandId}, ito.main_brand_id)
</foreach>
</if>
<if test="provinceCodes != null and provinceCodes.size() > 0">
and ito.province_code in
<foreach collection="provinceCodes" item="code" open="(" close=")" separator=",">
#{code}
</foreach>
</if>
<if test="merchantIds != null and merchantIds.size() > 0">
and ito.merchant_id in
<foreach collection="merchantIds" item="merchantIdItem" open="(" close=")" separator=",">
#{merchantIdItem}
</foreach>
</if>
<if test="transferOutTagIds != null and transferOutTagIds.size() > 0">
and ito.transfer_out_tag_id in
<foreach collection="transferOutTagIds" item="tagId" open="(" close=")" separator=",">
#{tagId}
</foreach>
</if>
</sql>
<!-- 判断是否存在限制门店(仅用于一键付款前校验,不走 list 全量查询) -->
<select id="existsLimitStore" resultType="java.lang.Integer">
select 1
from shopmall_integral_transfer_out ito
<where>
ito.deleted_flag = 'N'
and ito.transfer_type != 0
<include refid="ListWhereConditions" />
<if test="limitStoreMerchantNos != null and limitStoreMerchantNos.size() > 0">
and ito.merchant_id in
<foreach collection="limitStoreMerchantNos" item="merchantNo" open="(" close=")" separator=",">
#{merchantNo}
</foreach>
</if>
<if test="limitStoreMerchantNos == null or limitStoreMerchantNos.size() == 0">
and 1=0
</if>
</where>
limit 1
</select>
<select id="getDetailById" resultMap="DetailResultMap">
select
ito.id,ito.out_settle_order_id, ito.staff_withdrawal_id, ito.customer_name, ito.customer_open_id, ito.customer_phone,ito.merchant_name, ito.integral_amount,
......
  • @wangxw1
    commented
    Owner

    一、关键问题与优化建议(Top 3)

    1. 敏感信息泄露风险(安全性)

    • 问题描述:在 IntegralTransferOutService.java 的 checkAllPayHasLimitStore 方法中,捕获异常时直接将底层异常信息抛出:throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e.getMessage());。
    • 影响分析:如果发生数据库异常,e.getMessage() 可能会包含 SQL 语句、表名、字段名等底层敏感信息。将其封装在 RPC 异常中透传,极易导致敏感信息暴露给上游调用方甚至前端用户,存在安全隐患。
    • 优化建议:日志中保留完整堆栈用于排查问题,对外抛出异常时使用统一的、脱敏的错误提示。 java // 优化示例 catch (Exception e) { log.error("校验限制门店发生数据库异常, request: {}", request, e); // 仅抛出枚举中定义好的标准错误信息,不透传 e.getMessage() throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR); }

    2. 篡改方法入参导致副作用(最佳实践)

    • 问题描述:在 IntegralTransferOutService.java 中,直接修改了传入的 DTO 参数:request.setLimitStoreMerchantNos(merchantNos);。
    • 影响分析:修改入参是一种反模式(带来副作用)。在 RPC 场景或复杂的业务链路中,调用方可能在后续逻辑中继续使用该 request 对象,隐式地改变对象状态会导致难以排查的 Bug。
    • 优化建议:避免污染原入参。建议在 Mapper 接口中使用 @Param 注解将 request 和 merchantNos 作为两个独立参数传递,或在 Service 中构建专门的 Query 对象。 java // Mapper 接口修改示例 Integer existsLimitStore(@Param("req") IntegralTransferOutDTO request, @Param("limitNos") List<String> limitNos);

    3. XML 中存在无法触达的死代码(可维护性)

    • 问题描述:在 IntegralTransferOutMapper.xml 的 existsLimitStore 方法中,存在如下判断逻辑: <if test="limitStoreMerchantNos == null or limitStoreMerchantNos.size() == 0"> and 1=0 </if>
    • 影响分析:在 Service 层的逻辑中,已经前置判断了 if (CollectionUtils.isEmpty(merchantNos)) { return false; },因此当集合为空时根本不会发起数据库调用。XML 中的这段防御性代码实际上是死代码(Dead Code),增加了代码的阅读和维护成本。
    • 优化建议:直接移除 XML 中这块冗余的 <if> 判断,保持 SQL 模板的简洁。

    二、评分明细

    • 功能实现的正确性与健壮性(40/40分): 逻辑实现完全正确。成功规避了 MyBatis 返回单一聚合结果时可能为 null 的 NPE 风险(exists != null && exists > 0 处理得很严谨)。未触发“使用子查询”和“变更已有远程接口参数”的红线规则。

    • 安全性与潜在风险(25/30分): 扣除 5 分。SQL 层面正确使用了 MyBatis 预编译和 CONCAT 防范注入,安全性良好;但 Service 层存在透传 e.getMessage() 导致底层数据库敏感信息泄露的风险。

    • 最佳实践与可维护性(16/20分): 扣除 4 分。XML 抽取 <sql id="ListWhereConditions"> 提升了复用性,值得表扬。但 Service 层存在修改入参(副作用)的不良习惯,且 XML 中包含无用的死代码。

    • 性能与资源利用(5/5分): 满分。针对“是否存在”的校验场景,精准使用了 select 1 ... limit 1 替代了原有的全量 list 查询,避免了不必要的网络传输和内存开销,性能优化意识极佳。

    • 提交信息质量(5/5分): 满分。Commit 遵循了 Angular 规范(feat:),并且详细列出了 Controller、Mapper、Remote、Service 等各层的具体变更点及优化目的,清晰可追溯。

    总分:91分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!