Commit a23d61a8 by 周立明

feat: 添加分账规则测试主进度更新功能

1. 新增progress字段到DivisionRuleTest实体类及ORM映射
2. 新增更新主测试进度的远程接口和实现
3. 完善测试记录默认进度初始化
4. 增加参数非空校验和异常处理
1 parent f9b39580
...@@ -80,6 +80,12 @@ public class DivisionRuleTest implements Serializable { ...@@ -80,6 +80,12 @@ public class DivisionRuleTest implements Serializable {
private BigDecimal orderMoney; private BigDecimal orderMoney;
/** /**
* 测试进度
*/
@Column(name = "progress")
private Byte progress;
/**
* 子测试进度 * 子测试进度
*/ */
@Column(name = "sub_progress") @Column(name = "sub_progress")
......
...@@ -38,5 +38,10 @@ public interface DivisionRuleTestRemote { ...@@ -38,5 +38,10 @@ public interface DivisionRuleTestRemote {
@ApiMethod("重新测试") @ApiMethod("重新测试")
@ApiParam(name="record",notes="分账规则测试记录",dataType= ApiParam.DataTypeEnum.OBJECT,required=true) @ApiParam(name="record",notes="分账规则测试记录",dataType= ApiParam.DataTypeEnum.OBJECT,required=true)
@ApiResponse("返回分账规则测试记录") @ApiResponse("返回分账规则测试记录")
RpcResponse<MerchantDivisionRuleProcessDTO> retest(DivisionRuleTestDTO record); RpcResponse<MerchantDivisionRuleProcessDTO> retest(@NotNull DivisionRuleTestDTO record);
@ApiMethod("更新主测试进度")
@ApiParam(name="record",notes="分账规则测试记录",dataType= ApiParam.DataTypeEnum.OBJECT,required=true)
@ApiResponse("返回更新结果")
RpcResponse<Boolean> updateMainProgress(@NotNull DivisionRuleTestDTO record);
} }
package cn.com.glsx.dj.smartcarlife.remote; package cn.com.glsx.dj.smartcarlife.remote;
import javax.validation.constraints.NotNull;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -65,4 +67,15 @@ public class DivisionRuleTestRemoteImpl implements DivisionRuleTestRemote { ...@@ -65,4 +67,15 @@ public class DivisionRuleTestRemoteImpl implements DivisionRuleTestRemote {
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
@Override
public RpcResponse<Boolean> updateMainProgress(@NotNull DivisionRuleTestDTO record) {
try{
divisionRuleTestService.updateMainProgress(record);
return RpcResponse.success(true);
}catch(RpcServiceException e){
logger.error(e.getMessage(),e);
return RpcResponse.error(e);
}
}
} }
...@@ -511,6 +511,7 @@ public class DivisionRuleTestService { ...@@ -511,6 +511,7 @@ public class DivisionRuleTestService {
r.setCreatedDate(new Date()); r.setCreatedDate(new Date());
r.setUpdatedDate(r.getCreatedDate()); r.setUpdatedDate(r.getCreatedDate());
r.setDeletedFlag(DeletedFlagEnum.N.name()); r.setDeletedFlag(DeletedFlagEnum.N.name());
r.setProgress((byte)1);//默认第一步
divisionRuleTestMapper.insertUseGeneratedKeys(r); divisionRuleTestMapper.insertUseGeneratedKeys(r);
} }
if(isBase){ if(isBase){
...@@ -616,4 +617,28 @@ public class DivisionRuleTestService { ...@@ -616,4 +617,28 @@ public class DivisionRuleTestService {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR,e.getMessage()); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR,e.getMessage());
} }
} }
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void updateMainProgress(DivisionRuleTestDTO record) {
RpcAssert.assertNotNull(record, DefaultErrorEnum.DATA_NULL,"DivisionRuleTestDTO is null");
RpcAssert.assertNotNull(record.getDivisionRuleId(), DefaultErrorEnum.DATA_NULL,"DivisionRuleTestDTO.divisionRuleId is null");
RpcAssert.assertNotNull(record.getPaymentChannelId(),DefaultErrorEnum.DATA_NULL,"DivisionRuleTestDTO.paymentChannelId is null");
RpcAssert.assertNotNull(record.getProgress(),DefaultErrorEnum.DATA_NULL,"DivisionRuleTestDTO.progress is null");
RpcAssert.assertNotEmpty(record.getUpdatedBy(),DefaultErrorEnum.DATA_NULL,"DivisionRuleTestDTO.updatedBy is null");
try {
List<DivisionRuleTestDTO> list = divisionRuleTestMapper.list(DivisionRuleTest.builder()
.divisionRuleId(record.getDivisionRuleId()).paymentChannelId(record.getPaymentChannelId())
.build());
RpcAssert.assertNotEmpty(list,DefaultErrorEnum.DATA_NULL,"未找到分账测试记录数据");
DivisionRuleTestDTO r = list.get(0);
divisionRuleTestMapper.updateByPrimaryKeySelective(DivisionRuleTest.builder()
.id(r.getId()).updatedBy(record.getUpdatedBy()).progress(record.getProgress())
.build());
}catch(RpcServiceException e) {
throw e;
}catch(Exception e) {
log.error(e.getMessage(),e);
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR,e.getMessage());
}
}
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
<result column="division_rule_id" jdbcType="INTEGER" property="divisionRuleId" /> <result column="division_rule_id" jdbcType="INTEGER" property="divisionRuleId" />
<result column="order_code" jdbcType="VARCHAR" property="orderCode" /> <result column="order_code" jdbcType="VARCHAR" property="orderCode" />
<result column="order_money" property="orderMoney"/> <result column="order_money" property="orderMoney"/>
<result column="progress" jdbcType="TINYINT" property="progress" />
<result column="sub_progress" jdbcType="TINYINT" property="subProgress" /> <result column="sub_progress" jdbcType="TINYINT" property="subProgress" />
<result column="test_flag" property="testFlag"/> <result column="test_flag" property="testFlag"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy" /> <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
...@@ -25,7 +26,7 @@ ...@@ -25,7 +26,7 @@
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, merchant_id, payment_channel_id, payment_channel_name, division_rule_id, id, merchant_id, payment_channel_id, payment_channel_name, division_rule_id,
order_code,order_money, sub_progress,test_flag, created_by, created_date, updated_by, updated_date, deleted_flag order_code,order_money, progress,sub_progress,test_flag, created_by, created_date, updated_by, updated_date, deleted_flag
</sql> </sql>
<resultMap extends="BaseResultMap" id="DTOResultMap" type="cn.com.glsx.dj.smartcarlife.dto.DivisionRuleTestDTO"> <resultMap extends="BaseResultMap" id="DTOResultMap" type="cn.com.glsx.dj.smartcarlife.dto.DivisionRuleTestDTO">
...@@ -67,7 +68,7 @@ ...@@ -67,7 +68,7 @@
<select id="list" parameterType="cn.com.glsx.dj.smartcarlife.model.DivisionRuleTest" resultMap="DTOResultMap"> <select id="list" parameterType="cn.com.glsx.dj.smartcarlife.model.DivisionRuleTest" resultMap="DTOResultMap">
select select
dcldrt.id, dcldrt.division_rule_id, dcldrt.payment_channel_id, dcldrt.payment_channel_name, dclpc.pay_platform, dcldrt.id, dcldrt.division_rule_id, dcldrt.payment_channel_id, dcldrt.payment_channel_name, dclpc.pay_platform,
dcldrt.order_code,dcldrt.order_money, sub_progress, dcldrt.merchant_id, dcldrt.order_code,dcldrt.order_money, progress,sub_progress, dcldrt.merchant_id,
dcldrt.test_flag, dcldrt.test_flag,
dcldrtmd.id as dcldrtmd_id, dcldrtmd.division_rule_test_id as dcldrtmd_division_rule_test_id, dcldrtmd.order_code as dcldrtmd_order_code, dcldrtmd.id as dcldrtmd_id, dcldrtmd.division_rule_test_id as dcldrtmd_division_rule_test_id, dcldrtmd.order_code as dcldrtmd_order_code,
dcldrtmd.merchant_id as dcldrtmd_merchant_id, dcldrtmd.merchant_name as dcldrtmd_merchant_name, dcldrtmd.merchant_id as dcldrtmd_merchant_id, dcldrtmd.merchant_name as dcldrtmd_merchant_name,
...@@ -103,6 +104,7 @@ ...@@ -103,6 +104,7 @@
division_rule_id, division_rule_id,
dcldrt.order_code, dcldrt.order_code,
dcldrt.order_money, dcldrt.order_money,
progress,
sub_progress, sub_progress,
dcldrt.test_flag, dcldrt.test_flag,
dcldrt.merchant_id, dcldrt.merchant_id,
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 违反核心规范:Dubbo 接口已有请求参数发生变更

    • 问题描述:在 DivisionRuleTestRemote.java 中,对已存在的 retest 方法参数 DivisionRuleTestDTO record 新增了 @NotNull 注解。
    • 影响分析:触发了“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的重要规则。在 RPC 接口中修改已有方法的签名或校验注解,会破坏向下兼容性。如果旧版本的消费者未升级 API 包,或者传递了 null 值,提供者端的 Dubbo 校验过滤器将直接抛出 ConstraintViolationException(或类似异常),导致线上存量业务报错。
    • 优化建议:撤销对已有 retest 方法参数的 @NotNull 修改。如果必须校验,请在 DivisionRuleTestRemoteImpl 的方法体内部进行手动校验,以保证接口契约的绝对兼容。

    2. 性能与最佳实践:为了更新单字段执行了极度冗余的重型关联查询

    • 问题描述:在 DivisionRuleTestService.updateMainProgress 方法中,为了获取主键 ID 以执行更新,调用了 divisionRuleTestMapper.list(...)。
    • 影响分析:查看 XML 可知,list 方法映射的是 DTOResultMap,该查询包含了多表关联(Join)以及嵌套的集合映射,是一个极度消耗数据库资源的重型查询。仅仅为了获取 id 来更新 progress 字段而执行整个聚合根的复杂查询,会严重浪费数据库 CPU、内存及网络带宽,在高并发下易成为性能瓶颈。
    • 优化建议:废弃先查后改的逻辑,直接通过业务唯一键(divisionRuleId 和 paymentChannelId)执行单条 Update 语句。 代码示例: java // Mapper 接口新增方法 int updateProgressByRuleAndChannel(@Param("divisionRuleId") Integer divisionRuleId, @Param("paymentChannelId") Integer paymentChannelId, @Param("progress") Byte progress, @Param("updatedBy") String updatedBy); xml <!-- XML 实现 --> <update id="updateProgressByRuleAndChannel"> update division_rule_test set progress = #{progress}, updated_by = #{updatedBy}, updated_date = NOW() where division_rule_id = #{divisionRuleId} and payment_channel_id = #{paymentChannelId} </update>

    3. 违反核心规范:MyBatis SQL 语句中使用了子查询

    • 问题描述:在 DivisionRuleTestMapper.xml 的 <select id="list"> 修改中(Diff 文件的 103-110 行附近),新增了 progress 字段。从代码缩进和上下文结构可以明显判断,该字段被添加到了一个内部子查询中。
    • 影响分析:触发了“mybatis的sql语句不允许使用子查询”的重要规则。MySQL 对子查询的优化通常较差,容易导致无法命中索引、产生临时表或文件排序,随着数据量级增长,极易引发慢 SQL,拖垮整个数据库实例。
    • 优化建议:重构该 list 查询,消除子查询。建议将子查询改写为标准的 JOIN 关联查询;或者在 Java 内存中进行分步处理(先查询符合条件的主表 ID 集合,再通过 IN 查询关联数据并在内存中组装)。

    二、评分明细

    • 功能实现的正确性与健壮性(25/40分): 扣分原因:修改了已有的 Dubbo 接口参数(增加 @NotNull),属于危险实现,极易引发线上向下兼容性故障。新增的更新逻辑包含了基础的非空校验,健壮性尚可。
    • 安全性与潜在风险(30/30分): 未发现明显的 SQL 注入、越权或敏感信息泄露等安全漏洞。
    • 最佳实践与可维护性(10/20分): 扣分原因:MyBatis 存在子查询,违反了明确的工程规范;代码复用了沉重的 list 方法来做简单数据更新,不符合读写职责分离与轻量化设计的最佳实践。
    • 性能与资源利用(2/5分): 扣分原因:为了更新单个字段,加载了包含多表 Join 的庞大 DTO 对象,存在极其明显的资源浪费和性能隐患。
    • 提交信息质量(5/5分): Commit 信息清晰准确,分条列出了本次变更的核心内容,可追溯性良好。

    总分:72分

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