diff --git a/par-core/src/main/java/com/par/core/service/impl/SiteSnapshotServiceImpl.java b/par-core/src/main/java/com/par/core/service/impl/SiteSnapshotServiceImpl.java index 26076ee..0596067 100644 --- a/par-core/src/main/java/com/par/core/service/impl/SiteSnapshotServiceImpl.java +++ b/par-core/src/main/java/com/par/core/service/impl/SiteSnapshotServiceImpl.java @@ -134,12 +134,11 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService { return null; } - // 删除旧 draft,保证最新只有一条 - snapshotMapper.deleteBySiteIdAndStatus(siteId, "draft"); + int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1; SiteSnapshot snapshot = new SiteSnapshot(); snapshot.setSiteId(siteId); - snapshot.setVersion((latestDraft != null) ? latestDraft.getVersion() + 1 : 1); + snapshot.setVersion(newVersion); populateSnapshotFields(snapshot, data); snapshot.setChecksum(checksum); snapshot.setStatus("draft"); @@ -150,7 +149,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService { String bundleJson = toBundleJson(snapshot); jsonCache.put(draftKey(siteId), bundleJson); - log.info("快照已更新: siteId={}, version={}, checksum={}", siteId, snapshot.getVersion(), checksum.substring(0, 8)); + log.info("快照已更新: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8)); return snapshot; } catch (Exception e) { log.error("更新快照失败 siteId={}", siteId, e); @@ -178,12 +177,11 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService { return latestDraft; } - // 删除旧 draft,保证最新只有一条 - snapshotMapper.deleteBySiteIdAndStatus(siteId, "draft"); + int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1; SiteSnapshot snapshot = new SiteSnapshot(); snapshot.setSiteId(siteId); - snapshot.setVersion((latestDraft != null) ? latestDraft.getVersion() + 1 : 1); + snapshot.setVersion(newVersion); populateSnapshotFields(snapshot, data); snapshot.setChecksum(checksum); snapshot.setStatus("draft"); @@ -194,7 +192,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService { String bundleJson = toBundleJson(snapshot); jsonCache.put(draftKey(siteId), bundleJson); - log.info("预览版已保存: siteId={}, version={}, checksum={}", siteId, snapshot.getVersion(), checksum.substring(0, 8)); + log.info("预览版已保存: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8)); return snapshot; } catch (Exception e) { log.error("保存预览版失败 siteId={}", siteId, e); @@ -236,8 +234,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService { return current; } - // 先删旧 published,再改当前 draft 为 published(事务保证原子性) - snapshotMapper.deleteBySiteIdAndStatus(siteId, "published"); + // 更新状态为 published draft.setStatus("published"); draft.setPublishedAt(LocalDateTime.now()); snapshotMapper.updateById(draft);