refactor: 移除风险规则 siteType fallback 逻辑,仅按站点 ID 查找专属规则
This commit is contained in:
@@ -100,36 +100,23 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
|
|||||||
snapshot.put("pagesSource", pages.containsKey("source") ? pages.get("source") : "custom");
|
snapshot.put("pagesSource", pages.containsKey("source") ? pages.get("source") : "custom");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 风险规则(优先按站点专属规则查找,无则 fallback 到站点类型规则)
|
// 3. 风险规则(按站点 ID 查找专属规则)
|
||||||
RiskRule matchedRule = null;
|
|
||||||
// 3a. 按站点 ID 查找专属规则
|
|
||||||
if (siteId != null) {
|
if (siteId != null) {
|
||||||
matchedRule = riskRuleMapper.selectOne(
|
var matchedRule = riskRuleMapper.selectOne(
|
||||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
|
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
|
||||||
.eq(RiskRule::getSiteId, siteId)
|
.eq(RiskRule::getSiteId, siteId)
|
||||||
.eq(RiskRule::getDeleted, 0)
|
.eq(RiskRule::getDeleted, 0)
|
||||||
.orderByDesc(RiskRule::getId)
|
.orderByDesc(RiskRule::getId)
|
||||||
.last("limit 1"));
|
.last("limit 1"));
|
||||||
}
|
if (matchedRule != null) {
|
||||||
// 3b. 无专属规则时 fallback 到站点类型规则
|
try {
|
||||||
if (matchedRule == null && siteType != null) {
|
List<Map<String, Object>> rulesList = om.readValue(matchedRule.getRulesJson(),
|
||||||
matchedRule = riskRuleMapper.selectOne(
|
new TypeReference<List<Map<String, Object>>>() {});
|
||||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
|
snapshot.put("riskRules", rulesList);
|
||||||
.eq(RiskRule::getSiteType, siteType)
|
snapshot.put("riskRulesVersion", matchedRule.getVersion());
|
||||||
.eq(RiskRule::getDeleted, 0)
|
log.debug("快照风险规则: siteId={} ruleVersion={}", siteId, matchedRule.getVersion());
|
||||||
.orderByDesc(RiskRule::getId)
|
} catch (Exception ignored) {}
|
||||||
.last("limit 1"));
|
}
|
||||||
}
|
|
||||||
if (matchedRule != null) {
|
|
||||||
try {
|
|
||||||
List<Map<String, Object>> rulesList = om.readValue(matchedRule.getRulesJson(),
|
|
||||||
new TypeReference<List<Map<String, Object>>>() {});
|
|
||||||
snapshot.put("riskRules", rulesList);
|
|
||||||
snapshot.put("riskRulesVersion", matchedRule.getVersion());
|
|
||||||
log.debug("快照风险规则: siteId={} ruleSource={} ruleVersion={}", siteId,
|
|
||||||
matchedRule.getSiteId() != null && matchedRule.getSiteId().equals(siteId) ? "site" : "siteType",
|
|
||||||
matchedRule.getVersion());
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只要有任一配置(脚本/页面/规则)即视为有效快照
|
// 只要有任一配置(脚本/页面/规则)即视为有效快照
|
||||||
|
|||||||
Reference in New Issue
Block a user