refactor: 移除风险规则 siteType fallback 逻辑,仅按站点 ID 查找专属规则

This commit is contained in:
mediabot-pt
2026-07-12 23:21:14 +08:00
parent 8b004e5c45
commit af4b2bde75

View File

@@ -100,36 +100,23 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
snapshot.put("pagesSource", pages.containsKey("source") ? pages.get("source") : "custom");
}
// 3. 风险规则(优先按站点专属规则查找,无则 fallback 到站点类型规则)
RiskRule matchedRule = null;
// 3a. 按站点 ID 查找专属规则
// 3. 风险规则(按站点 ID 查找专属规则)
if (siteId != null) {
matchedRule = riskRuleMapper.selectOne(
var matchedRule = riskRuleMapper.selectOne(
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
.eq(RiskRule::getSiteId, siteId)
.eq(RiskRule::getDeleted, 0)
.orderByDesc(RiskRule::getId)
.last("limit 1"));
}
// 3b. 无专属规则时 fallback 到站点类型规则
if (matchedRule == null && siteType != null) {
matchedRule = riskRuleMapper.selectOne(
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<RiskRule>()
.eq(RiskRule::getSiteType, siteType)
.eq(RiskRule::getDeleted, 0)
.orderByDesc(RiskRule::getId)
.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) {}
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={} ruleVersion={}", siteId, matchedRule.getVersion());
} catch (Exception ignored) {}
}
}
// 只要有任一配置(脚本/页面/规则)即视为有效快照