fix: 快照版本号取全表最大+1,修复发布后版本回退到1导致的唯一键冲突
bug: selectLatestDraft 只查 status='draft',发布后 draft→published 查不到,下一版又从 1 开始 fix: selectMaxVersion 查全表 MAX(version),保证单调递增
This commit is contained in:
@@ -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}")
|
@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);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1;
|
int newVersion = snapshotMapper.selectMaxVersion(siteId) + 1;
|
||||||
|
|
||||||
SiteSnapshot snapshot = new SiteSnapshot();
|
SiteSnapshot snapshot = new SiteSnapshot();
|
||||||
snapshot.setSiteId(siteId);
|
snapshot.setSiteId(siteId);
|
||||||
@@ -179,7 +179,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
|
|||||||
return latestDraft;
|
return latestDraft;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1;
|
int newVersion = snapshotMapper.selectMaxVersion(siteId) + 1;
|
||||||
|
|
||||||
SiteSnapshot snapshot = new SiteSnapshot();
|
SiteSnapshot snapshot = new SiteSnapshot();
|
||||||
snapshot.setSiteId(siteId);
|
snapshot.setSiteId(siteId);
|
||||||
|
|||||||
Reference in New Issue
Block a user