Commit b3ef17f0 by 谢海旭

Merge remote-tracking branch 'origin/v5.8.2' into v5.8.2

2 parents 04bf14eb 1933f2f2
...@@ -621,10 +621,7 @@ public class ProjectGroupService { ...@@ -621,10 +621,7 @@ public class ProjectGroupService {
Integer sortNo = condition.getInt("sortNo"); Integer sortNo = condition.getInt("sortNo");
Integer metricId = condition.getInt("metricId"); Integer metricId = condition.getInt("metricId");
String operator = StringUtils.trimToNull(condition.getStr("operator")); String operator = StringUtils.trimToNull(condition.getStr("operator"));
String thresholdType = StringUtils.trimToNull(condition.getStr("thresholdType")); JSONObject threshold = condition.getJSONObject("threshold");
String thresholdValue = StringUtils.trimToNull(condition.getStr("thresholdValue"));
String thresholdMin = StringUtils.trimToNull(condition.getStr("thresholdMin"));
String thresholdMax = StringUtils.trimToNull(condition.getStr("thresholdMax"));
String nextLogic = StringUtils.upperCase(StringUtils.trimToNull(condition.getStr("nextLogic"))); String nextLogic = StringUtils.upperCase(StringUtils.trimToNull(condition.getStr("nextLogic")));
if (sortNo == null) { if (sortNo == null) {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "ruleJson条件排序号不能为空"); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "ruleJson条件排序号不能为空");
...@@ -635,6 +632,13 @@ public class ProjectGroupService { ...@@ -635,6 +632,13 @@ public class ProjectGroupService {
if (StringUtils.isBlank(operator) || (!VALID_SINGLE_OPERATORS.contains(operator) && !VALID_RANGE_OPERATORS.contains(operator))) { if (StringUtils.isBlank(operator) || (!VALID_SINGLE_OPERATORS.contains(operator) && !VALID_RANGE_OPERATORS.contains(operator))) {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "ruleJson操作符不合法"); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "ruleJson操作符不合法");
} }
if (threshold == null) {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "ruleJson阈值类型不合法");
}
String thresholdType = StringUtils.trimToNull(threshold.getStr("type"));
String thresholdValue = StringUtils.trimToNull(threshold.getStr("value"));
String thresholdMin = StringUtils.trimToNull(threshold.getStr("min"));
String thresholdMax = StringUtils.trimToNull(threshold.getStr("max"));
if (StringUtils.isBlank(thresholdType) || !VALID_THRESHOLD_TYPES.contains(thresholdType)) { if (StringUtils.isBlank(thresholdType) || !VALID_THRESHOLD_TYPES.contains(thresholdType)) {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "ruleJson阈值类型不合法"); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "ruleJson阈值类型不合法");
} }
......
  • @wangxw1
    commented
    Master

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

    1. 性能与资源瓶颈:在内存中进行全量数据聚合统计

    • 问题描述:在 StrategyInfoService.countStrategyStatusByCreatedUUid 方法中,代码通过 selectByExample 查询出该创建人的所有策略列表,然后通过 for 循环在内存中统计各 pushFlag 的数量。
    • 影响分析:当某个用户的策略历史数据量较大时,将所有记录的完整实体全量加载到内存中,会造成极大的内存占用和网络开销,严重时会引发 OOM(内存溢出)并拖慢系统响应速度。
    • 优化建议:应下推至数据库层面进行聚合计算。建议在 Mapper 中手写 SQL,使用 GROUP BY 直接返回统计结果。 代码示例: xml <!-- 在 Mapper.xml 中添加 --> <select id="countStrategyStatus" resultType="java.util.Map"> SELECT push_flag as pushFlag, COUNT(1) as count FROM strategy_info WHERE created_uuid = #{createdUUid} AND deleted_flag = 'N' GROUP BY push_flag </select>

    2. 稳定性与可用性风险:循环中频繁发起 RPC 调用(N+1问题)

    • 问题描述:syncCollaborativeTaskStatus 方法在定时任务中执行,查询出所有未完成的策略后,在 for 循环内部逐条调用下游 RPC 接口 taskCenterRemote.getTaskDetail(request) 查询状态。
    • 影响分析:这是典型的 RPC N+1 问题。如果未完成的策略数据较多,定时任务会在短时间内发起大量网络请求,不仅会导致当前定时任务执行时间过长甚至超时,还会给下游“任务中心”服务带来巨大的瞬时并发压力,可能导致下游服务雪崩。
    • 优化建议:
      1. 首选方案:协调下游服务提供批量查询接口(如 getTaskDetails(List<String> bizInstanceIds)),一次 RPC 调用获取所有状态。
      2. 备选方案:如果下游无法提供批量接口,必须对本次查询进行分页/分批限制(例如每次定时任务最多只处理 50 或 100 条),避免无限度的循环调用。

    3. 接口兼容性风险:破坏性变更 Dubbo API DTO 字段类型

    • 问题描述:在 rpc-dj-strategy-api 模块的 MentoringApprovalInfoDTO 和 MentoringTaskDetailDTO 中,将已有的 approvalTime 和 mentoringTime 字段的数据类型由 String 直接修改为了 Date。
    • 影响分析:(触发危险实现规则) 属于 Dubbo API 契约的破坏性变更。如果服务消费方没有同步更新依赖包并同时发布,旧版本的消费方在反序列化新版本返回的数据(或新版本接收旧版本数据)时,会抛出序列化异常(如 HessianException),直接导致线上接口调用失败。
    • 优化建议:对于已上线的对外 DTO,严禁直接修改已有字段的数据类型。建议保留原 String 类型字段(可标记 @Deprecated),同时新增 Date 类型的新字段(如 approvalDate),并在服务提供端做好双写/兼容逻辑,确保平滑升级。

    二、评分明细

    • 功能实现的正确性与健壮性(28 / 40分):业务逻辑基本实现,但将本应由数据库承担的聚合计算放在了内存中处理,且定时任务缺乏对处理数据量上限的控制,在极端边界情况(数据量大)下健壮性极差。
    • 安全性与潜在风险(15 / 30分):直接修改对外提供的 API DTO 字段类型,属于高危的破坏性变更,极易引发上下游序列化不一致的生产事故,风险较高。
    • 最佳实践与可维护性(12 / 20分):在循环中发起 RPC 调用违背了分布式系统设计的最佳实践;代码中存在部分硬编码(如策略类型 Arrays.asList(9, 10, 11, 12)),建议提取为枚举或常量。
    • 性能与资源利用(0 / 5分):存在明显的性能瓶颈,内存全量聚合和循环 RPC 调用对 CPU、内存、网络及下游资源都造成了极大的不必要浪费。
    • 提交信息质量(3 / 5分):提交信息为 "策略中心 (by xiehx);Merge...",不够清晰,未能准确描述本次新增的具体业务功能(如协同任务状态同步、策略统计等),缺乏追溯价值。

    总分:58分

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