refactor: 版本号由PAR审核通过时自动分配
- submitConfig: 不再比较版本号,相同hash跳过,不同hash都插入pending - approveConfig: 自动取最大版本号+1 分配(如 1, 2, 3...) - 存储路径含hash前缀避免同名冲突
This commit is contained in:
@@ -71,6 +71,19 @@ public class AdminController {
|
||||
|
||||
Long reviewerId = (Long) request.getAttribute("accountId");
|
||||
|
||||
// 自动分配版本号:取该站点已审批的最大版本号 + 1
|
||||
var latestApproved = siteConfigMapper.selectList(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SiteConfig>()
|
||||
.eq(SiteConfig::getSiteId, config.getSiteId())
|
||||
.eq(SiteConfig::getStatus, ConfigStatus.APPROVED)
|
||||
.orderByDesc(SiteConfig::getVersion));
|
||||
int nextVersion = 1;
|
||||
if (!latestApproved.isEmpty()) {
|
||||
try { nextVersion = Integer.parseInt(latestApproved.get(0).getVersion()) + 1; }
|
||||
catch (NumberFormatException ignored) {}
|
||||
}
|
||||
config.setVersion(String.valueOf(nextVersion));
|
||||
|
||||
config.setStatus(ConfigStatus.APPROVED);
|
||||
config.setReviewerId(reviewerId);
|
||||
config.setReviewedAt(LocalDateTime.now());
|
||||
|
||||
@@ -59,28 +59,21 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
@Override
|
||||
public SiteConfig submitConfig(String siteId, String version, String configJson,
|
||||
String schemaVersion, Long submitterId) {
|
||||
SiteConfig existing = getConfig(siteId, version);
|
||||
String configHash = HmacUtil.sha256(configJson);
|
||||
String storagePath = String.format("configs/%s/%s.json", siteId, version);
|
||||
String storagePath = String.format("configs/%s/%s/%s.json", siteId, version, configHash.substring(0, 8));
|
||||
|
||||
// 版本已存在 → 根据 hash 判断是重复还是更新
|
||||
if (existing != null) {
|
||||
if (configHash.equals(existing.getConfigHash())) {
|
||||
log.info("配置未变化,跳过: siteId={}, version={}, hash={}", siteId, version, configHash);
|
||||
return existing;
|
||||
}
|
||||
// hash 不同 → 覆盖更新
|
||||
log.info("配置内容变化,更新: siteId={}, version={}, oldHash={}, newHash={}",
|
||||
siteId, version, existing.getConfigHash(), configHash);
|
||||
storageService.store(storagePath, configJson);
|
||||
existing.setConfigHash(configHash);
|
||||
existing.setFileSize((long) configJson.getBytes(StandardCharsets.UTF_8).length);
|
||||
existing.setStoragePath(storagePath);
|
||||
siteConfigMapper.updateById(existing);
|
||||
return existing;
|
||||
// 相同 hash 的提交 → 真正重复,跳过
|
||||
SiteConfig sameHash = siteConfigMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SiteConfig>()
|
||||
.eq(SiteConfig::getSiteId, siteId)
|
||||
.eq(SiteConfig::getConfigHash, configHash)
|
||||
.eq(SiteConfig::getDeleted, 0));
|
||||
if (sameHash != null) {
|
||||
log.info("配置未变化,跳过: siteId={}, hash={}", siteId, configHash);
|
||||
return sameHash;
|
||||
}
|
||||
|
||||
// 存储到抽象存储层(七牛或本地)
|
||||
// 存储到抽象存储层
|
||||
try {
|
||||
storageService.store(storagePath, configJson);
|
||||
} catch (Exception e) {
|
||||
@@ -90,7 +83,7 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
|
||||
SiteConfig config = new SiteConfig();
|
||||
config.setSiteId(siteId);
|
||||
config.setVersion(version);
|
||||
config.setVersion(version); // 客户端提交的版本号,仅供参考
|
||||
config.setConfigHash(configHash);
|
||||
config.setStoragePath(storagePath);
|
||||
config.setFileSize((long) configJson.getBytes(StandardCharsets.UTF_8).length);
|
||||
@@ -100,7 +93,7 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
config.setIsLatest(false);
|
||||
|
||||
siteConfigMapper.insert(config);
|
||||
log.info("Config submitted: siteId={}, version={}, id={}", siteId, version, config.getId());
|
||||
log.info("Config submitted: siteId={}, version={}, id={}, hash={}", siteId, version, config.getId(), configHash);
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user