Commit 340904d5 by 张富康

feat(shopmall): 添加订单编号阳光积分详情查询功能

- 新增 ShopmallStaffMotivationDTO 中的 orderCodeList 字段
- 在 ShopmallStaffMotivationMapper 中添加 getOrderCodeMotivationList 方法
- 实现 getOrderCodeMotivationList 的 SQL 查询逻辑
- 在 StaffMotivationRemote 接口中添加远程调用方法
- 实现 StaffMotivationRemoteImpl 中的 getOrderCodeMotivationList 方法
- 在 StaffMotivationService 中添加业务逻辑实现
- 更新 pom.xml 版本号从 4.56.0-SNAPSHOT 到 5.8.2-SNAPSHOT
- 更新相关依赖版本号到 5.8.2-SNAPSHOT
1 parent 4aecbc43
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<name>rpc-scrm-shopmall-api</name> <name>rpc-scrm-shopmall-api</name>
<properties> <properties>
<deploy.scanPackage>cn.com.glsx.shopmall.remote</deploy.scanPackage> <deploy.scanPackage>cn.com.glsx.shopmall.remote</deploy.scanPackage>
<shopmall.api.version>5.6.4-SNAPSHOT</shopmall.api.version> <shopmall.api.version>5.8.2-SNAPSHOT</shopmall.api.version>
<stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version> <stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version>
</properties> </properties>
<dependencies> <dependencies>
......
...@@ -105,6 +105,11 @@ public class ShopmallStaffMotivationDTO extends ShopmallStaffMotivation implemen ...@@ -105,6 +105,11 @@ public class ShopmallStaffMotivationDTO extends ShopmallStaffMotivation implemen
@Transient @Transient
private String deliveryEmployeeName; private String deliveryEmployeeName;
/**
* 订单编号集合
*/
private List<String> orderCodeList;
public ShopmallStaffMotivationDTO(Integer merchantId, String staffUuid, String orderCode) { public ShopmallStaffMotivationDTO(Integer merchantId, String staffUuid, String orderCode) {
super(); super();
this.setMerchantId(merchantId); this.setMerchantId(merchantId);
......
...@@ -61,4 +61,8 @@ public interface StaffMotivationRemote { ...@@ -61,4 +61,8 @@ public interface StaffMotivationRemote {
@ApiMethod("变更手机号(积分迁移)") @ApiMethod("变更手机号(积分迁移)")
RpcResponse<Boolean> changeStaffScore(ShopmallStaffScoreChangeDTO dto); RpcResponse<Boolean> changeStaffScore(ShopmallStaffScoreChangeDTO dto);
@ApiMethod("订单编号阳光积分详情")
RpcResponse<List<ShopmallStaffMotivationDTO>> getOrderCodeMotivationList(ShopmallStaffMotivationDTO requestDTO);
} }
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
</parent> </parent>
<groupId>cn.com.glsx.scrm</groupId> <groupId>cn.com.glsx.scrm</groupId>
<artifactId>rpc-scrm-shopmall</artifactId> <artifactId>rpc-scrm-shopmall</artifactId>
<version>4.56.0-SNAPSHOT</version> <version>5.8.2-SNAPSHOT</version>
<name>rpc-scrm-shopmall</name> <name>rpc-scrm-shopmall</name>
<packaging>war</packaging> <packaging>war</packaging>
<properties> <properties>
<stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version> <stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version>
<shopmall.api.version>5.6.4-SNAPSHOT</shopmall.api.version> <shopmall.api.version>5.8.2-SNAPSHOT</shopmall.api.version>
<smartcarlife.api.version>5.6.4-SNAPSHOT</smartcarlife.api.version> <smartcarlife.api.version>5.6.4-SNAPSHOT</smartcarlife.api.version>
<platform-payment.api.version>5.6.4-SNAPSHOT</platform-payment.api.version> <platform-payment.api.version>5.6.4-SNAPSHOT</platform-payment.api.version>
</properties> </properties>
......
...@@ -23,4 +23,6 @@ public interface ShopmallStaffMotivationMapper extends OreMapper<ShopmallStaffMo ...@@ -23,4 +23,6 @@ public interface ShopmallStaffMotivationMapper extends OreMapper<ShopmallStaffMo
void deleteById(@Param("id")Integer id); void deleteById(@Param("id")Integer id);
List<ShopmallStaffMotivationDTO> findByOrderCodeAndStatus(@Param("orderCode") String orderCode, @Param("status") Integer status, @Param("generateType") Integer generateType); List<ShopmallStaffMotivationDTO> findByOrderCodeAndStatus(@Param("orderCode") String orderCode, @Param("status") Integer status, @Param("generateType") Integer generateType);
List<ShopmallStaffMotivationDTO> getOrderCodeMotivationList(@Param("orderCodeList") List<String> orderCodeList);
} }
\ No newline at end of file \ No newline at end of file
...@@ -133,4 +133,14 @@ public class StaffMotivationRemoteImpl implements StaffMotivationRemote { ...@@ -133,4 +133,14 @@ public class StaffMotivationRemoteImpl implements StaffMotivationRemote {
return RpcResponse.error(e); return RpcResponse.error(e);
} }
} }
@Override
public RpcResponse<List<ShopmallStaffMotivationDTO>> getOrderCodeMotivationList(ShopmallStaffMotivationDTO requestDTO) {
try {
return RpcResponse.success(staffMotivationService.getOrderCodeMotivationList(requestDTO));
} catch (RpcServiceException e) {
log.error(e.getMessage(), e);
return RpcResponse.error(e);
}
}
} }
...@@ -799,4 +799,8 @@ public class StaffMotivationService { ...@@ -799,4 +799,8 @@ public class StaffMotivationService {
// 审批记录是否需要迁移(因为订单绑定的受益人也没变,审批记录作为快照数据理应不变) // 审批记录是否需要迁移(因为订单绑定的受益人也没变,审批记录作为快照数据理应不变)
return true; return true;
} }
public List<ShopmallStaffMotivationDTO> getOrderCodeMotivationList(ShopmallStaffMotivationDTO requestDTO) {
return staffMotivationMapper.getOrderCodeMotivationList(requestDTO.getOrderCodeList());
}
} }
...@@ -253,4 +253,20 @@ ...@@ -253,4 +253,20 @@
<update id="deleteById"> <update id="deleteById">
update shopmall_staff_motivation set deleted_flag = 'D', updated_date = now() where id = #{id} update shopmall_staff_motivation set deleted_flag = 'D', updated_date = now() where id = #{id}
</update> </update>
<select id="getOrderCodeMotivationList" resultType="cn.com.glsx.scrm.shopmall.dto.integral.motivation.ShopmallStaffMotivationDTO">
select order_code as orderCode, status as status, refund_type as refundType
from shopmall_staff_motivation
where deleted_flag = 'N'
<if test="orderCodeList != null and orderCodeList.size() > 0">
and order_code in
<foreach collection="orderCodeList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
and generate_type = 0
and (status = 1 or (status = 2 and refund_type = 1))
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Owner

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

    1. 严重问题:Mybatis 动态 SQL 存在全表扫描与 OOM 风险(健壮性与性能)

    • 问题描述:在 ShopmallStaffMotivationMapper.xml 的 getOrderCodeMotivationList 方法中,使用了 <if test="orderCodeList != null and orderCodeList.size() > 0"> 来包裹 IN 查询条件。
    • 影响分析:如果调用方传入的 orderCodeList 为空集合或 null,该 <if> 块将被跳过,SQL 将退化为不带订单编号过滤条件的查询。这会导致数据库扫描并返回所有状态符合条件的数据,极易引发数据库性能抖动、应用内存溢出(OOM)及服务雪崩。
    • 优化建议:在 Java 业务层(Service)进行前置拦截,如果集合为空,则直接返回空集合,不发起数据库查询。 java // StaffMotivationService.java public List<ShopmallStaffMotivationDTO> getOrderCodeMotivationList(ShopmallStaffMotivationDTO requestDTO) { if (requestDTO == null || CollectionUtils.isEmpty(requestDTO.getOrderCodeList())) { return new ArrayList<>(); } return staffMotivationMapper.getOrderCodeMotivationList(requestDTO.getOrderCodeList()); }

    2. 架构规范问题:直接修改已有 DTO 违反 Dubbo 接口参数变更规范(最佳实践)

    • 问题描述:为了支持新的批量查询接口,在已有的核心实体 DTO ShopmallStaffMotivationDTO 中直接新增了 List<String> orderCodeList 字段。
    • 影响分析:根据规范,dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现。ShopmallStaffMotivationDTO 是一个通用实体 DTO,可能被多个已有接口作为入参或出参使用。向其中添加仅供特定查询使用的集合字段,会导致 DTO 职责不单一(代码坏味道:大杂烩类),增加序列化开销,且容易引起其他使用该 DTO 的接口产生歧义。
    • 优化建议:为该查询接口剥离并创建专属的 Request DTO。 java // 新增专用的请求类 public class OrderMotivationQueryReqDTO implements Serializable { private List<String> orderCodeList; // getter setter } // 修改 Remote 接口签名 @ApiMethod("订单编号阳光积分详情") RpcResponse<List<ShopmallStaffMotivationDTO>> getOrderCodeMotivationList(OrderMotivationQueryReqDTO requestDTO);

    3. 潜在缺陷:Service 层缺乏对入参的空指针校验(健壮性)

    • 问题描述:在 StaffMotivationService 中,直接调用了 requestDTO.getOrderCodeList()。
    • 影响分析:如果 Dubbo 消费者在调用 getOrderCodeMotivationList 时传入的 requestDTO 为 null,服务端将抛出 NullPointerException,导致请求异常失败,缺乏防御性编程。
    • 优化建议:在 Service 层或 Impl 层增加对 requestDTO 自身的判空逻辑(可结合问题 1 的优化建议一并处理)。

    二、评分明细

    • 功能实现的正确性与健壮性(25/40分): 扣分原因:存在严重的边界情况未处理。当传入的订单列表为空时,Mybatis 动态 SQL 会导致全表扫描;此外,Service 层缺乏对 requestDTO 的 NPE 防御性校验。未发现 Mybatis 子查询问题。
    • 安全性与潜在风险(25/30分): 扣分原因:全表扫描漏洞不仅是功能缺陷,在生产环境中极易被放大为可用性安全风险(引发拒绝服务 DoS 或 OOM)。SQL 注入方面处理良好(使用了安全的 foreach 拼接)。
    • 最佳实践与可维护性(10/20分): 扣分原因:直接在已有通用 DTO 中追加特定接口的查询字段,触犯了“已有请求参数变更视为危险实现”的规则,违反了单一职责原则,降低了代码的可维护性。
    • 性能与资源利用(2/5分): 扣分原因:动态 SQL 缺失兜底逻辑带来的全表扫描风险,对数据库性能和应用内存资源构成直接威胁。
    • 提交信息质量(5/5分): 得分原因:Commit 信息非常规范,清晰地列出了新增字段、Mapper、XML、Remote 接口及版本号变更等细节,可追溯性极强。

    总分:67分

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