Commit e3e24753 by 杨卫

feat:策略中心自测提交

1 parent 39e537fa
...@@ -20,6 +20,7 @@ import cn.com.glsx.dj.strategy.model.projectgroup.PgGroupInfo; ...@@ -20,6 +20,7 @@ import cn.com.glsx.dj.strategy.model.projectgroup.PgGroupInfo;
import cn.com.glsx.dj.strategy.model.projectgroup.PgStoreOutput; import cn.com.glsx.dj.strategy.model.projectgroup.PgStoreOutput;
import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningMetricDict; import cn.com.glsx.dj.strategy.model.projectgroup.PgWarningMetricDict;
import cn.com.glsx.dj.strategy.service.warning.BiMetricQueryService; import cn.com.glsx.dj.strategy.service.warning.BiMetricQueryService;
import cn.com.glsx.dj.strategy.service.warning.EcoCoefficientQueryService;
import cn.com.glsx.dj.strategy.service.warning.MerchantFilterUtil; import cn.com.glsx.dj.strategy.service.warning.MerchantFilterUtil;
import cn.com.glsx.dj.strategy.service.warning.StoreOutputService; import cn.com.glsx.dj.strategy.service.warning.StoreOutputService;
import cn.com.glsx.dj.strategy.service.warning.WarningRecordService; import cn.com.glsx.dj.strategy.service.warning.WarningRecordService;
...@@ -70,6 +71,9 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote { ...@@ -70,6 +71,9 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote {
@Resource @Resource
private StoreOutputService storeOutputService; private StoreOutputService storeOutputService;
@Resource
private EcoCoefficientQueryService ecoCoefficientQueryService;
@Override @Override
public RpcResponse<List<StoreWarningSummaryDTO>> findWarningSummary(WarningRecordQueryRequest request) { public RpcResponse<List<StoreWarningSummaryDTO>> findWarningSummary(WarningRecordQueryRequest request) {
try { try {
...@@ -319,8 +323,13 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote { ...@@ -319,8 +323,13 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote {
BigDecimal nextValue = nextByStore.get(storeId); BigDecimal nextValue = nextByStore.get(storeId);
if (nextValue == null) { if (nextValue == null) {
nextValue = BigDecimal.ZERO; nextValue = BigDecimal.ZERO;
} else if (needPercentScale) { } else {
nextValue = nextValue.multiply(new BigDecimal("100")); if ("生态系数".equals(metricName)) {
nextValue = applyEcoCoefficient(metricCode, nextValue);
}
if (needPercentScale) {
nextValue = nextValue.multiply(new BigDecimal("100"));
}
} }
metricDto.setNextValue(nextValue); metricDto.setNextValue(nextValue);
...@@ -499,4 +508,20 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote { ...@@ -499,4 +508,20 @@ public class WarningEngineRemoteImpl implements WarningEngineRemote {
filterDto.setEndDate(request.getEndDate()); filterDto.setEndDate(request.getEndDate());
return merchantFilterUtil.getIntersectionMerchantIds(filterDto); return merchantFilterUtil.getIntersectionMerchantIds(filterDto);
} }
/**
* 生态系数转换——生态预警时将BI原值替换为生态系数。
*/
private BigDecimal applyEcoCoefficient(String metricCode, BigDecimal value) {
if (value == null || metricCode == null) {
return value;
}
try {
BigDecimal coefficient = ecoCoefficientQueryService.getCoefficient(metricCode, value);
return coefficient != null ? coefficient : value;
} catch (Exception e) {
log.warn("生态系数转换失败,metricCode={}", metricCode, e);
return value;
}
}
} }
...@@ -36,6 +36,16 @@ public class EcoCoefficientQueryService implements ApplicationListener<Applicati ...@@ -36,6 +36,16 @@ public class EcoCoefficientQueryService implements ApplicationListener<Applicati
private final Map<String, List<EcoCoefficientRule>> ruleCache = new ConcurrentHashMap<>(); private final Map<String, List<EcoCoefficientRule>> ruleCache = new ConcurrentHashMap<>();
/** 获取缓存的指标编码列表(调试用) */
public Map<String, List<EcoCoefficientRule>> getRuleCache() {
return ruleCache;
}
/** 获取缓存指标编码数量(调试用) */
public int getCacheSize() {
return ruleCache.size();
}
@Override @Override
public void onApplicationEvent(ApplicationReadyEvent event) { public void onApplicationEvent(ApplicationReadyEvent event) {
reloadRules(); reloadRules();
...@@ -74,7 +84,7 @@ public class EcoCoefficientQueryService implements ApplicationListener<Applicati ...@@ -74,7 +84,7 @@ public class EcoCoefficientQueryService implements ApplicationListener<Applicati
} }
List<EcoCoefficientRule> rules = ruleCache.get(indicatorCode); List<EcoCoefficientRule> rules = ruleCache.get(indicatorCode);
if (CollectionUtils.isEmpty(rules)) { if (CollectionUtils.isEmpty(rules)) {
log.info("未找到生态系数规则,indicatorCode:{}", indicatorCode); log.info("未找到生态系数规则,indicatorCode:{},当前缓存指标编码列表:{}", indicatorCode, ruleCache.keySet());
return null; return null;
} }
BigDecimal coefficient = matchRules(rules, metricValue); BigDecimal coefficient = matchRules(rules, metricValue);
......
...@@ -139,7 +139,6 @@ public class WarningRecordService { ...@@ -139,7 +139,6 @@ public class WarningRecordService {
private ProjectGroupWarningRecordQueryDTO buildQueryDTO(WarningRecordQueryRequest request) { private ProjectGroupWarningRecordQueryDTO buildQueryDTO(WarningRecordQueryRequest request) {
ProjectGroupWarningRecordQueryDTO dto = new ProjectGroupWarningRecordQueryDTO(); ProjectGroupWarningRecordQueryDTO dto = new ProjectGroupWarningRecordQueryDTO();
dto.setProjectGroupId(request.getGroupId());
dto.setBusinessType(request.getBusinessType()); dto.setBusinessType(request.getBusinessType());
dto.setWarningType(request.getWarningType()); dto.setWarningType(request.getWarningType());
dto.setMetricId(request.getMetricTypeId()); dto.setMetricId(request.getMetricTypeId());
...@@ -150,7 +149,6 @@ public class WarningRecordService { ...@@ -150,7 +149,6 @@ public class WarningRecordService {
dto.setStoreId(request.getStoreId()); dto.setStoreId(request.getStoreId());
dto.setStaffId(request.getStaffId()); dto.setStaffId(request.getStaffId());
dto.setStoreName(request.getStoreName()); dto.setStoreName(request.getStoreName());
dto.setIsStrategySent(request.getIsStrategySent());
dto.setStaffIds(request.getStaffIds()); dto.setStaffIds(request.getStaffIds());
return dto; return dto;
} }
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
<select id="selectAllEnabled" resultType="cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule"> <select id="selectAllEnabled" resultType="cn.com.glsx.dj.mindworkplate.model.EcoCoefficientRule">
SELECT SELECT
id, indicator_code, min_penetration, max_penetration, id, indicator_code indicatorCode, min_penetration minPenetration, max_penetration maxPenetration,
coefficient, sort_order, enabled, create_time, update_time coefficient coefficient, sort_order sortOrder, enabled, create_time createTime, update_time updateTime
FROM eco_coefficient_rule FROM eco_coefficient_rule
WHERE enabled = 1 WHERE enabled = 1
ORDER BY indicator_code ASC, sort_order ASC ORDER BY indicator_code ASC, sort_order ASC
......
...@@ -17,7 +17,7 @@ public class WarningEngineServiceTest extends BaseServiceTest { ...@@ -17,7 +17,7 @@ public class WarningEngineServiceTest extends BaseServiceTest {
@Test @Test
public void testWarningComputeExecutor() { public void testWarningComputeExecutor() {
executor.execute(""); executor.execute("2026-05-31");
} }
@Test @Test
......
  • @wangxw1
    commented
    Master

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

    1. 严重:Dubbo 接口请求参数被静默丢弃,破坏服务契约(功能正确性)

    • 问题描述:在 WarningRecordService.java 的 buildQueryDTO 方法中,移除了 dto.setProjectGroupId(request.getGroupId()) 和 dto.setIsStrategySent(request.getIsStrategySent()) 的赋值逻辑。
    • 影响分析:触发了“Dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的重要规则。虽然没有直接修改接口签名,但服务端静默丢弃了消费端传来的 groupId 和 isStrategySent 参数。如果消费端依然依赖这两个字段进行数据过滤,将导致查询结果不准确,产生严重的业务逻辑错误或越权查询风险。
    • 优化建议:恢复这两个参数的映射赋值。如果业务逻辑确实不再需要这两个参数,必须先在消费端进行排查和同步修改,并走正规的接口废弃(@Deprecated)与版本升级流程,严禁单方面在服务端丢弃入参。

    2. 中等:业务逻辑中存在硬编码(魔法值),极易导致逻辑失效(最佳实践)

    • 问题描述:在 WarningEngineRemoteImpl.java 中,使用了硬编码的中文字符串进行业务判断:if ("生态系数".equals(metricName))。
    • 影响分析:使用魔法值(尤其是中文字符串)作为核心业务判断条件是非常脆弱的。如果上游数据字典或数据库中将指标名称修改为“生态指标”或带有空格,该逻辑将直接失效且不会报错,导致生态系数无法正确转换。
    • 优化建议:强烈建议使用指标编码(metricCode)来进行判断,或者将该字符串提取为全局常量/枚举类。
    • 代码示例: java // 推荐使用 metricCode 判断,或定义常量:public static final String ECO_METRIC_NAME = "生态系数"; if (EcoMetricEnum.ECO_COEFFICIENT.getCode().equals(metricCode)) { nextValue = applyEcoCoefficient(metricCode, nextValue); }

    3. 中等:为调试暴露内部状态及高频日志打印风险(可维护性与性能)

    • 问题描述:
      1. EcoCoefficientQueryService.java 中新增了 getRuleCache() 方法直接返回了内部 ConcurrentHashMap 的引用。
      2. 在 getCoefficient 缓存未命中时,日志打印了 ruleCache.keySet()。
    • 影响分析:
      1. 将“调试用”代码提交到生产环境违反工程规范。直接返回内部可变集合的引用,破坏了类的封装性,外部调用者可以随意修改缓存内容,存在线程安全和数据被篡改的风险。
      2. getCoefficient 是在 for 循环中被调用的,如果出现缓存未命中的情况,频繁对 ConcurrentHashMap 执行 keySet() 并拼接打印日志,会产生不必要的性能开销和日志风暴。
    • 优化建议:删除仅供调试使用的 getRuleCache() 和 getCacheSize() 方法;移除日志中的 ruleCache.keySet() 打印,仅保留 indicatorCode 即可。

    二、评分明细

    • 功能实现的正确性与健壮性(25/40分)
      • 扣分理由:服务端静默丢弃了 Dubbo 请求对象中的 groupId 和 isStrategySent 参数,严重破坏了服务契约,可能导致消费端查询结果异常。applyEcoCoefficient 异常兜底逻辑尚可,未发现 MyBatis 子查询违规。
    • 安全性与潜在风险(28/30分)
      • 扣分理由:暴露内部缓存对象引用(getRuleCache),存在一定的数据被意外篡改的内存安全风险。未见 SQL 注入等常规高危漏洞。
    • 最佳实践与可维护性(12/20分)
      • 扣分理由:核心业务逻辑依赖中文魔法值("生态系数")进行判断,极不推荐;将带有“调试用”注释的代码直接提交到主干,工程规范性较差。
    • 性能与资源利用(3/5分)
      • 扣分理由:在可能高频调用的方法中,打印包含整个 Map KeySet 的日志,在异常场景下存在性能损耗和日志刷屏风险。
    • 提交信息质量(1/5分)
      • 扣分理由:Commit message 为 feat:策略中心自测提交 (by 杨卫),毫无价值。无法从中看出本次提交增加了生态系数转换逻辑、修改了 MyBatis 映射等实际变更,不具备可追溯性。

    总分:69分

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