Merge remote-tracking branch 'origin/v5.7.1' into v5.7.4
# Conflicts: # rpc-dj-mindworkplate-api/pom.xml # rpc-dj-mindworkplate/pom.xml
Showing
25 changed files
with
1212 additions
and
7 deletions
This diff is collapsed.
Click to expand it.
-
一、关键问题与优化建议(Top 3)
1. 严重违规:Mybatis SQL 中使用了子查询
-
问题描述:在
ReceptionCustomerFileMapper.xml的listNeedGenerateTodayLightModReception查询中,使用了not exists (select 1 from reception_customer_file ...)子查询。这直接违反了“mybatis SQL中不允许使用子查询”的重要规则。 - 影响分析:子查询在某些数据库版本中可能导致执行计划不佳,引发全表扫描,严重影响数据库性能。
-
优化建议:使用
LEFT JOIN结合IS NULL来替代NOT EXISTS子查询。xml <select id="listNeedGenerateTodayLightModReception" resultType="cn.com.glsx.dj.mindworkplate.model.ReceptionCustomerInfo"> select distinct rci.id as id, ... from reception_customer_info rci ... left join reception_customer_file rcf on rcf.reception_id = rci.id and rcf.deleted_flag = 'N' where rci.deleted_flag = 'N' and rci.bussiness_type = 2 ... and rcf.id is null order by rci.id asc </select>
2. 逻辑错误:批量插入初始化数据时使用了错误的集合
-
问题描述:在
ReceptionCustomerFileGenerateService.java的sendWeChatPushMessages方法中,代码通过遍历receptionList并根据发送企微消息的结果将成功的记录放入sucessList。但在最后进行批量插入时,虽然判断了CollectionUtils.isNotEmpty(sucessList),实际构建insertList却错误地使用了原始的receptionList。 - 影响分析:会导致企微消息发送失败的接待记录也被错误地标记为已发送/已初始化,导致后续可能无法重试或产生脏数据。
-
优化建议:将
receptionList.stream()改为sucessList.stream()。java if (CollectionUtils.isNotEmpty(sucessList)) { Date now = new Date(); // 修正:使用 sucessList 而不是 receptionList List<ReceptionCustomerFile> insertList = sucessList.stream() .map(x -> buildInitCustomerFile(x, now)) .collect(Collectors.toList()); receptionCustomerFileMapper.batchInsertInit(insertList); }
3. 健壮性隐患:Mybatis 批量操作未在 XML 层防止空集合报错
-
问题描述:
ReceptionCustomerFileMapper.xml中的updateCustomerFileFlag和updatePushStatusByReceptionIds等方法使用了<foreach>标签进行IN查询或批量更新,但未对传入的集合是否为空进行判断。 -
影响分析:如果由于业务逻辑漏洞传入了空集合(如
ids列表为空),Mybatis 会拼装出类似WHERE id IN ()的残缺 SQL,直接引发 SQL 语法错误(SQLSyntaxErrorException)。 -
优化建议:虽然在业务层通常会做非空判断,但为了极致的健壮性,建议在业务层做好前置拦截,或在 SQL 中添加容错处理。
java // 在业务层调用前务必加上拦截 if (CollectionUtils.isEmpty(ids)) { return 0; }
二、评分明细
- 功能实现的正确性与健壮性(30/40分):违反了 SQL 不允许子查询的硬性规定,且存在集合使用错误的业务逻辑 Bug,扣除 10 分。
- 安全性与潜在风险(28/30分):整体安全性尚可,未发现明显的 SQL 注入和越权问题,但部分代码存在硬编码(如环境判断或默认商户号),扣除 2 分。
-
最佳实践与可维护性(15/20分):代码中存在较长的
switch-case映射代码(如mapDealAttribution),建议使用枚举类(Enum)来维护映射关系,提高可读性和可维护性;QWManager存在 URL 字符串硬编码拼接,扣除 5 分。 -
性能与资源利用(4/5分):在
MonitoringService中使用了CompletableFuture进行并发查询,提升了性能,但未显式设置超时时间,若底层接口阻塞可能拖垮线程池,扣除 1 分。 - 提交信息质量(4/5分):Commit 信息包含了部分功能点描述,但由于合并产生了冲突信息,略显杂乱,扣除 1 分。
总分:81分
-
问题描述:在
-
Please register or sign in to post a comment