feat: 每站点独立版本号+总版本=SUM+规则变更同步所有同类型站点
This commit is contained in:
@@ -55,6 +55,9 @@ public class Site {
|
||||
@TableField("current_config_id")
|
||||
private Long currentConfigId;
|
||||
|
||||
@TableField("version")
|
||||
private Integer version;
|
||||
|
||||
@TableField("status")
|
||||
private SiteStatus status;
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Manifest 全局版本号管理
|
||||
* 任何站点/页面/规则/脚本变更时递增,mediabot 据此判断是否需要拉取最新数据
|
||||
* Manifest 版本管理:每个站点独立版本,总版本 = 所有站点版本之和
|
||||
* 站点/页面/脚本变更时递增对应站点版本,规则变更时递增同类型所有站点版本
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -16,15 +16,21 @@ public class ManifestVersionService {
|
||||
|
||||
private final JdbcTemplate jdbc;
|
||||
|
||||
/** 获取当前版本号 */
|
||||
/** 全局总版本 = 所有站点版本之和 */
|
||||
public int current() {
|
||||
Integer v = jdbc.queryForObject("SELECT version FROM manifest_version WHERE id=1", Integer.class);
|
||||
return v != null ? v : 1;
|
||||
Integer v = jdbc.queryForObject("SELECT COALESCE(SUM(version), 0) FROM sites WHERE deleted=0", Integer.class);
|
||||
return v != null ? v : 0;
|
||||
}
|
||||
|
||||
/** 递增版本号并返回新值 */
|
||||
public int increment() {
|
||||
jdbc.update("UPDATE manifest_version SET version = version + 1, updated_at = NOW() WHERE id=1");
|
||||
/** 递增指定站点的版本号 */
|
||||
public int increment(String siteId) {
|
||||
jdbc.update("UPDATE sites SET version = version + 1 WHERE site_id = ? AND deleted=0", siteId);
|
||||
return current();
|
||||
}
|
||||
|
||||
/** 递增指定类型下所有站点的版本号(用于风险规则变更) */
|
||||
public void incrementByType(String siteType) {
|
||||
jdbc.update("UPDATE sites SET version = version + 1 WHERE site_type = ? AND deleted=0",
|
||||
siteType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
config.setIsLatest(false);
|
||||
|
||||
siteConfigMapper.insert(config);
|
||||
versionService.increment();
|
||||
versionService.increment(siteId);
|
||||
log.info("Config submitted: siteId={}, version={}, id={}, scriptPath={}", siteId, version, config.getId(), scriptPath);
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class RiskRuleServiceImpl implements RiskRuleService {
|
||||
// 存七牛云 + 本地缓存
|
||||
String storagePath = String.format("rules/%s/v%d.json", siteType, nextVer);
|
||||
storageService.store(storagePath, json);
|
||||
versionService.increment();
|
||||
versionService.incrementByType(siteType);
|
||||
log.info("风险规则已保存: siteType={}, version={}, path={}", siteType, nextVer, storagePath);
|
||||
} catch (Exception e) {
|
||||
log.error("保存风险规则失败 siteType={}", siteType, e);
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SitePagesServiceImpl implements SitePagesService {
|
||||
// 存七牛云 + 本地缓存
|
||||
String storagePath = String.format("pages/%s/v%s.json", siteId, version);
|
||||
storageService.store(storagePath, json);
|
||||
versionService.increment();
|
||||
versionService.increment(siteId);
|
||||
log.info("页面配置已保存: siteId={}, version={}, path={}", siteId, version, storagePath);
|
||||
} catch (Exception e) {
|
||||
log.error("保存页面配置失败 siteId={}", siteId, e);
|
||||
|
||||
@@ -232,7 +232,7 @@ public class SiteServiceImpl implements SiteService {
|
||||
try { site.setStatus(SiteStatus.fromValue(status)); } catch (Exception ignored) {}
|
||||
}
|
||||
siteMapper.updateById(site);
|
||||
versionService.increment();
|
||||
versionService.increment(siteId);
|
||||
log.info("站点编辑: siteId={}", siteId);
|
||||
return site;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user