Commit 9bef99bc by 林永健

```

feat(integral): 添加积分转出批量操作数量限制

- 新增 assertBatchSizeNotExceeded 方法用于校验批量操作数量
- 在批量查询转出记录方法中添加数量限制检查
- 在批量审核转出记录方法中添加数量限制检查
- 在批量处理转出记录方法中添加数量限制检查
- 配置文件中设置默认批量操作限制为 3000 条
- 超出限制时抛出 RpcServiceException 异常提示用户
```
1 parent a559d083
...@@ -516,6 +516,13 @@ public class IntegralTransferOutService { ...@@ -516,6 +516,13 @@ public class IntegralTransferOutService {
} }
} }
private void assertBatchSizeNotExceeded(int size) {
Integer limit = env.getProperty("scrm.integral.transfer.out.batch.size.limit", Integer.class, 3000);
if (size > limit) {
throw new RpcServiceException("批量操作记录数超过限制(" + limit + "条),请添加筛选条件后重试");
}
}
/** /**
* 为查询结果填充手动标签路径(避免列表 SQL 连表标签表)。 * 为查询结果填充手动标签路径(避免列表 SQL 连表标签表)。
* *
...@@ -632,6 +639,7 @@ public class IntegralTransferOutService { ...@@ -632,6 +639,7 @@ public class IntegralTransferOutService {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
throw new RpcServiceException("没有符合记录的提现记录"); throw new RpcServiceException("没有符合记录的提现记录");
} }
assertBatchSizeNotExceeded(list.size());
List<Integer> ids = list.stream().map(IntegralTransferOut::getId).collect(Collectors.toList()); List<Integer> ids = list.stream().map(IntegralTransferOut::getId).collect(Collectors.toList());
IntegralTransferOutOperationDTO operationDTO = new IntegralTransferOutOperationDTO(); IntegralTransferOutOperationDTO operationDTO = new IntegralTransferOutOperationDTO();
...@@ -663,6 +671,7 @@ public class IntegralTransferOutService { ...@@ -663,6 +671,7 @@ public class IntegralTransferOutService {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
throw new RpcServiceException("没有符合记录的提现记录"); throw new RpcServiceException("没有符合记录的提现记录");
} }
assertBatchSizeNotExceeded(list.size());
List<Integer> ids = list.stream().map(IntegralTransferOut::getId).collect(Collectors.toList()); List<Integer> ids = list.stream().map(IntegralTransferOut::getId).collect(Collectors.toList());
long totalAmount = list.stream().mapToLong(IntegralTransferOut::getPayAmount).sum(); long totalAmount = list.stream().mapToLong(IntegralTransferOut::getPayAmount).sum();
...@@ -1000,6 +1009,7 @@ public class IntegralTransferOutService { ...@@ -1000,6 +1009,7 @@ public class IntegralTransferOutService {
if (CollectionUtils.isEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) {
throw new RpcServiceException("没有符合条件的提现记录"); throw new RpcServiceException("没有符合条件的提现记录");
} }
assertBatchSizeNotExceeded(ids.size());
} }
IntegralTransferOutBatchResultDTO result = new IntegralTransferOutBatchResultDTO(); IntegralTransferOutBatchResultDTO result = new IntegralTransferOutBatchResultDTO();
for (Integer id : ids) { for (Integer id : ids) {
...@@ -1435,6 +1445,7 @@ public class IntegralTransferOutService { ...@@ -1435,6 +1445,7 @@ public class IntegralTransferOutService {
if (CollectionUtils.isEmpty(list)) { if (CollectionUtils.isEmpty(list)) {
throw new RpcServiceException("没有符合记录的提现记录"); throw new RpcServiceException("没有符合记录的提现记录");
} }
assertBatchSizeNotExceeded(list.size());
List<Integer> ids = list.stream().map(IntegralTransferOut::getId).collect(Collectors.toList()); List<Integer> ids = list.stream().map(IntegralTransferOut::getId).collect(Collectors.toList());
return getBatchChecksByIds(ids); return getBatchChecksByIds(ids);
} catch (Exception e) { } catch (Exception e) {
......
  • @wangxw1
    commented
    Owner

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

    1. [严重] 内存溢出(OOM)风险与资源浪费:后置校验无法防止大量数据加载

    • 问题描述:代码逻辑是在执行完数据库查询,将结果映射为 list 或 ids 集合后,才调用 assertBatchSizeNotExceeded(list.size()) 进行数量校验。这属于“事后校验”。
    • 影响分析:如果用户未加筛选条件,数据库中符合条件的记录有十万甚至百万条,这些数据会被全量查询并实例化为 Java 对象加载到内存中。这不仅会造成严重的 CPU 和数据库 IO 资源浪费,在并发场景下极易引发 JVM 内存溢出(OOM),导致整个服务宕机。
    • 优化建议:应改为“事前校验”或“限制查询数量”。
      • 方案 A(推荐):在查询全量数据前,先执行 COUNT 查询,若 count > limit,直接抛出异常拦截。
      • 方案 B:修改底层 MyBatis 的查询 SQL,强制加上 LIMIT {limit + 1}。如果返回的 list.size() > limit,说明超限,抛出异常。这样内存最多只加载 3001 条数据。

    2. [一般] 最佳实践:配置项获取方式不够优雅

    • 问题描述:在 assertBatchSizeNotExceeded 方法中,每次调用都会通过 env.getProperty(...) 去解析并获取环境变量。
    • 影响分析:虽然 Spring Environment 的性能尚可,但在方法内部频繁读取配置不符合 Spring 框架的最佳实践,降低了代码的可读性,且不利于单元测试。
    • 优化建议:建议使用 @Value 注解将配置项在 Bean 初始化时注入到成员变量中。如果项目中使用了动态配置中心(如 Nacos/Apollo),可配合相关注解实现动态刷新。 ```java // 作为类的成员变量注入 @Value("${scrm.integral.transfer.out.batch.size.limit:3000}") private Integer batchSizeLimit;

    private void assertBatchSizeNotExceeded(int size) { if (size > batchSizeLimit) { throw new RpcServiceException("批量操作记录数超过限制(" + batchSizeLimit + "条),请添加筛选条件后重试"); } }

    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(25/40分)**:基础的拦截逻辑已实现,能给前端正确的异常提示。但因为采用了“事后拦截”的策略,未能从根本上阻断大批量数据查询,健壮性存在明显缺陷,扣 15 分。
    - **安全性与潜在风险(25/30分)**:无 SQL 注入、越权等常规安全漏洞。但由于内存溢出(OOM)风险属于系统可用性维度的安全隐患,扣 5 分。
    - **最佳实践与可维护性(17/20分)**:代码结构清晰,方法抽取合理。但环境变量的硬编码获取方式不符合 Spring 最佳实践,扣 3 分。
    - **性能与资源利用(2/5分)**:无效的深部分页或大数据量加载会给数据库和应用服务器带来不必要的巨大压力,扣 3 分。
    - **提交信息质量(5/5分)**:Commit Message 使用了规范的 `feat` 前缀,并用列表清晰地描述了变更细节和默认配置,质量很高,得满分。
    
    总分:74分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!