fix: 快照版本号取全表最大+1,修复发布后版本回退到1导致的唯一键冲突

bug: selectLatestDraft 只查 status='draft',发布后 draft→published 查不到,下一版又从 1 开始
fix: selectMaxVersion 查全表 MAX(version),保证单调递增
This commit is contained in:
mediabot-pt
2026-07-07 23:47:53 +08:00
parent f65b8d0e2e
commit b19821bf83
2 changed files with 6 additions and 2 deletions

View File

@@ -27,4 +27,8 @@ public interface SiteSnapshotMapper extends BaseMapper<SiteSnapshot> {
/** 删除站点指定状态的快照 */
@org.apache.ibatis.annotations.Delete("DELETE FROM site_snapshots WHERE site_id = #{siteId} AND status = #{status}")
int deleteBySiteIdAndStatus(@Param("siteId") String siteId, @Param("status") String status);
/** 取站点快照的最大版本号 */
@Select("SELECT COALESCE(MAX(version), 0) FROM site_snapshots WHERE site_id = #{siteId}")
int selectMaxVersion(@Param("siteId") String siteId);
}

View File

@@ -136,7 +136,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
return null;
}
int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1;
int newVersion = snapshotMapper.selectMaxVersion(siteId) + 1;
SiteSnapshot snapshot = new SiteSnapshot();
snapshot.setSiteId(siteId);
@@ -179,7 +179,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
return latestDraft;
}
int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1;
int newVersion = snapshotMapper.selectMaxVersion(siteId) + 1;
SiteSnapshot snapshot = new SiteSnapshot();
snapshot.setSiteId(siteId);