Commit da12096c by 范富荣

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

2 parents a579305c 018560e1
......@@ -20,4 +20,10 @@ public class ProjectGroupStoreQueryDTO implements Serializable {
@ApiModelProperty(notes = "搜索关键字")
private String search;
@ApiModelProperty(notes = "门店号")
private String merchantId;
@ApiModelProperty(notes = "门店名称")
private String merchantName;
}
......@@ -79,6 +79,7 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote {
try {
// 自定义区间(无时间维度)→ 查BI获取有产值门店
if (request.getTimeDimension() == null || request.getTimeDimension().isEmpty()) {
log.info("查询门店预警汇总列表 - 自定义区间(无时间维度)→ 查BI获取有产值门店");
return RpcResponse.success(buildSummaryFromBi(request));
}
......@@ -86,9 +87,11 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote {
if (request.getWarningType() == null) {
// 未选预警类型 → 查 pg_store_output 获取有产值门店,left join 预警摘要
log.info("查询门店预警汇总列表 - 未选预警类型 → 查 pg_store_output 获取有产值门店,left join 预警摘要");
return RpcResponse.success(buildSummaryFromStoreOutput(request, filteredMerchantIds));
}
// 选了预警类型 → 查 warning_record 筛选触发该类型的门店
log.info("查询门店预警汇总列表 - 选了预警类型 → 查 warning_record 筛选触发该类型的门店");
return RpcResponse.success(warningRecordService.queryStoreSummary(request, filteredMerchantIds));
} catch (RpcServiceException e) {
log.error("查询门店预警汇总列表失败", e);
......
......@@ -258,11 +258,6 @@ public class WarningEngineService {
String[] parts = pairKey.split("_");
String storeIdStr = parts[0];
String staffId = parts[1];
// 取第一个条件的 itemCode 拼 key 查 BI 条目,获取门店员工基本信息
PgWarningMetricDict firstDict = metricDictMap.get(conditions.get(0).getMetricId());
String firstItemCode = firstDict != null ? firstDict.getStaffIndexCode() : null;
BiMetricQueryService.ItemDetail staffItem = metricValues.get(buildMetricKey(storeIdStr, staffId, firstItemCode));
Map<Integer, Boolean> conditionResults = new LinkedHashMap<>();
for (ConditionDTO cond : conditions) {
PgWarningMetricDict dict = metricDictMap.get(cond.getMetricId());
......@@ -287,7 +282,7 @@ public class WarningEngineService {
if (!satisfiedGroups.isEmpty()) {
List<ConditionDTO> triggeredCondtionList = satisfiedGroups.stream()
.flatMap(List::stream).collect(Collectors.toList());
List<PgWarningRecord> records = buildStaffRecords(config, storeIdStr, staffId, staffItem,
List<PgWarningRecord> records = buildStaffRecords(config, storeIdStr, staffId,
periodStart, periodEnd, timeDimension, triggeredCondtionList, metricValues, metricDictMap, preloadedThresholds);
for (PgWarningRecord record : records) {
batch.add(record);
......@@ -671,7 +666,6 @@ public class WarningEngineService {
* @param config 预警配置
* @param storeIdStr 门店 ID(字符串)
* @param staffId 员工 ID
* @param staffItem BI 查回的员工条目(含姓名、手机号)
* @param periodStart 周期开始
* @param periodEnd 周期结束
* @param timeDimension 时间维度
......@@ -684,7 +678,6 @@ public class WarningEngineService {
*/
private List<PgWarningRecord> buildStaffRecords(PgWarningConfig config,
String storeIdStr, String staffId,
BiMetricQueryService.ItemDetail staffItem,
Date periodStart, Date periodEnd, String timeDimension,
List<ConditionDTO> triggeredConditionList,
Map<String, BiMetricQueryService.ItemDetail> metricValues,
......@@ -695,6 +688,19 @@ public class WarningEngineService {
PgWarningMetricDict dict = metricDictMap.get(triggeredCond.getMetricId());
String itemCode = dict != null ? dict.getStaffIndexCode() : null;
BigDecimal triggeredValue = getStaffValueFromResult(metricValues, storeIdStr, staffId, itemCode);
// 用触发条件的 itemCode 精确匹配,兜底扫描同店同员工任意条目
BiMetricQueryService.ItemDetail staffItem = metricValues.get(buildMetricKey(storeIdStr, staffId, itemCode));
if (staffItem == null) {
for (BiMetricQueryService.ItemDetail item : metricValues.values()) {
if (storeIdStr.equals(item.getMerchantId()) && staffId.equals(item.getStaffId())) {
staffItem = item;
break;
}
}
}
if (staffItem == null) {
continue;
}
PgWarningRecord record = buildBaseRecord(config, periodStart, periodEnd, timeDimension);
record.setMonitorTarget(1);
......
......@@ -23,6 +23,12 @@
</if>
)
</if>
<if test="merchantId != null and merchantId != ''">
and s.merchant_id LIKE CONCAT('%', #{merchantId}, '%')
</if>
<if test="merchantName != null and merchantName != ''">
and s.merchant_name LIKE CONCAT('%', #{merchantName}, '%')
</if>
ORDER BY s.created_date DESC, s.id DESC
</select>
......
  • @wangxw1
    commented
    Master

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

    1. 时间区间查询逻辑发生重大变更,存在较高业务逻辑错误风险

    • 问题描述:在 MyBatis 的 XML 中,时间区间的匹配逻辑发生了反转。
      • 修改前:si.start_date <= #{endDate} AND si.end_date >= #{startDate}(语义为:数据库记录的时间区间与查询的时间区间存在交集/重叠即可查出)。
      • 修改后:si.start_date <= #{startDate} AND si.end_date >= #{endDate}(语义为:数据库记录的时间区间必须完全包含查询的时间区间才能查出)。
    • 影响分析:这是一个非常关键的业务逻辑变更。通常在查询某段时间内的策略或驻店记录时,业务期望的是“只要在这段时间内有效过”(即取交集)。修改后的逻辑极其严格,会导致原本在查询区间内部分生效的记录被过滤掉,可能引发严重的线上漏数据问题。
    • 优化建议:请务必与产品/业务方二次确认,本次需求是否明确要求“策略的生效时间必须完全覆盖查询的时间区间”。如果是为了修复时间查询的 Bug,通常修改前的“交集逻辑”才是处理时间段重叠的标准解法。若确实需要完全包含,请在代码附近补充注释说明此特殊业务场景。

    2. 提交信息(Commit Message)缺乏关键变更原因

    • 问题描述:提交信息为“修改查询员工驻店类型逻辑”,但未解释为何要将时间匹配逻辑从“求交集”改为“求包含”。
    • 影响分析:时间边界条件的修改往往是 Bug 产生的高发区。缺乏具体背景和原因的提交信息,会导致后续排查问题或进行代码回溯时,其他开发者无法理解该变更的真实意图。
    • 优化建议:建议在 Commit Message 中补充具体的业务背景。例如:“修改查询员工驻店类型逻辑:因业务要求,现需策略时间完全覆盖查询时间段才予展示,故调整 start_date 和 end_date 的判断边界”。

    二、评分明细

    • 1. 功能实现的正确性与健壮性(30/40分)
      • 理由:代码语法无误,但时间区间的逻辑变更(从交集变为包含)极其容易引发业务侧的严重数据遗漏。由于无法确定这是否为真实业务意图,存在较高的逻辑错误风险,故扣除10分。未发现违反“禁用子查询”和“Dubbo接口参数变更”的红线规则。
    • 2. 安全性与潜在风险(30/30分)
      • 理由:SQL 参数依然使用 #{} 占位符进行预编译,不存在 SQL 注入风险。无越权或敏感信息泄露等安全隐患。
    • 3. 最佳实践与可维护性(20/20分)
      • 理由:MyBatis XML 结构清晰,格式规范,符合常规工程实践。
    • 4. 性能与资源利用(5/5分)
      • 理由:普通的字段区间比较,不涉及复杂的函数操作,若 start_date 和 end_date 有合理索引,不会产生明显的性能瓶颈。
    • 5. 提交信息质量(2/5分)
      • 理由:Commit 信息过于简略,只说明了“改了什么”,完全没有说明针对核心判断条件进行反转的“为什么”,不利于代码的可追溯性。

    总分:87分

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