|
|
@@ -285,8 +285,22 @@ public class IndicatorMappingService {
|
|
|
public void setDefStatus(Integer defStatus) { this.defStatus = defStatus; }
|
|
|
}
|
|
|
|
|
|
- /** 惰性注册新定义(code 规则:indicator.<cat>.<name> / bacteria.<name> / food.<name>) */
|
|
|
+ /**
|
|
|
+ * 惰性注册新定义(code 规则:indicator.<cat>.<name> / bacteria.<name> / food.<name>)。
|
|
|
+ *
|
|
|
+ * <p><b>防污染(T04)</b>:</p>
|
|
|
+ * <ul>
|
|
|
+ * <li>疑似垃圾名(数值/范围/百分比等被误当作指标名)直接跳过,不建定义、不建规则,返回 null;
|
|
|
+ * 调用方(NormalizeIndicatorPipeline 等)对 null 已做安全跳过。</li>
|
|
|
+ * <li>新定义与 auto_created 规则一律按 <b>status=0(pending)</b> 登记,不冒进管理端字典列表
|
|
|
+ * (与 IndicatorService.listDefinitions 的 Q17 默认 status=1 语义一致),待管理端确认/合并。</li>
|
|
|
+ * </ul>
|
|
|
+ */
|
|
|
private Long lazyRegister(String sourceType, String rawName) {
|
|
|
+ if (isGarbageName(rawName)) {
|
|
|
+ log.warn("惰性注册跳过(疑似垃圾名/无意义值)sourceType={}, raw={}", sourceType, rawName);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
DefinitionCode code = buildCode(sourceType, rawName);
|
|
|
IndicatorDefinition def = new IndicatorDefinition();
|
|
|
def.setDomain("physical");
|
|
|
@@ -299,15 +313,39 @@ public class IndicatorMappingService {
|
|
|
def.setValueType(inferValueType(sourceType));
|
|
|
def.setGoodDirection("neutral");
|
|
|
def.setSortOrder(0);
|
|
|
- def.setStatus(1);
|
|
|
+ def.setStatus(0);
|
|
|
def.setCreatedAt(new Date());
|
|
|
def.setUpdatedAt(new Date());
|
|
|
definitionMapper.insert(def);
|
|
|
- registerRule(sourceType, rawName, def.getId(), "auto_created", 1);
|
|
|
- log.info("惰性注册指标定义 sourceType={}, raw={} → defId={}", sourceType, rawName, def.getId());
|
|
|
+ registerRule(sourceType, rawName, def.getId(), "auto_created", 0);
|
|
|
+ log.info("惰性注册指标定义(pending 待确认)sourceType={}, raw={} → defId={}",
|
|
|
+ sourceType, rawName, def.getId());
|
|
|
return def.getId();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 疑似垃圾名判定:纯数值 / 数值区间 / 百分比串等被误当作指标名的无意义值。
|
|
|
+ * 例:参考区间被解析成 "5.1543-18.1656"、"0-0.0999",覆盖率 "99%"。
|
|
|
+ */
|
|
|
+ private boolean isGarbageName(String rawName) {
|
|
|
+ if (rawName == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String t = rawName.trim();
|
|
|
+ if (t.isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 纯数字/带 . - , 的数值或区间串(以数字开头),如 "5.1543-18.1656"、"0-0.0999"
|
|
|
+ if (t.matches("^[0-9][0-9.,\\-]*$")) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 百分比,如 "99%"、"12.5%"
|
|
|
+ if (t.matches("^[0-9.,]+%$")) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
private void registerRule(String sourceType, String rawName, Long definitionId, String matchType, int status) {
|
|
|
IndicatorMappingRule rule = new IndicatorMappingRule();
|
|
|
rule.setSourceType(sourceType);
|