fix: 重复提交按hash判重,同hash跳过,异hash覆盖更新
This commit is contained in:
@@ -60,14 +60,26 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
public SiteConfig submitConfig(String siteId, String version, String configJson,
|
public SiteConfig submitConfig(String siteId, String version, String configJson,
|
||||||
String schemaVersion, Long submitterId) {
|
String schemaVersion, Long submitterId) {
|
||||||
SiteConfig existing = getConfig(siteId, version);
|
SiteConfig existing = getConfig(siteId, version);
|
||||||
if (existing != null) {
|
|
||||||
log.info("配置版本已存在,跳过: siteId={}, version={}", siteId, version);
|
|
||||||
return existing;
|
|
||||||
}
|
|
||||||
|
|
||||||
String configHash = HmacUtil.sha256(configJson);
|
String configHash = HmacUtil.sha256(configJson);
|
||||||
String storagePath = String.format("configs/%s/%s.json", siteId, version);
|
String storagePath = String.format("configs/%s/%s.json", siteId, version);
|
||||||
|
|
||||||
|
// 版本已存在 → 根据 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;
|
||||||
|
}
|
||||||
|
|
||||||
// 存储到抽象存储层(七牛或本地)
|
// 存储到抽象存储层(七牛或本地)
|
||||||
try {
|
try {
|
||||||
storageService.store(storagePath, configJson);
|
storageService.store(storagePath, configJson);
|
||||||
|
|||||||
Reference in New Issue
Block a user