feat: 编辑器增加「重置」和「丢弃预览版」按钮,支持回退预览版快照
This commit is contained in:
@@ -23,4 +23,8 @@ public interface SiteSnapshotMapper extends BaseMapper<SiteSnapshot> {
|
||||
/** 查询站点最新快照:draft 优先,无 draft 则取 published */
|
||||
@Select("SELECT * FROM site_snapshots WHERE site_id = #{siteId} AND status IN ('draft','published') ORDER BY CASE WHEN status = 'draft' THEN 0 ELSE 1 END, version DESC LIMIT 1")
|
||||
SiteSnapshot selectLatestWithDraft(@Param("siteId") String siteId);
|
||||
|
||||
/** 删除站点指定状态的快照 */
|
||||
@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);
|
||||
}
|
||||
|
||||
@@ -71,4 +71,10 @@ public interface SiteSnapshotService {
|
||||
* @return 成功发布的站点数
|
||||
*/
|
||||
int publishChanged();
|
||||
|
||||
/**
|
||||
* 丢弃预览版快照(删除所有 draft 记录),回退到正式版
|
||||
* @return 删除的 draft 记录数
|
||||
*/
|
||||
int discardDraft(String siteId);
|
||||
}
|
||||
|
||||
@@ -333,6 +333,19 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int discardDraft(String siteId) {
|
||||
int deleted = snapshotMapper.deleteBySiteIdAndStatus(siteId, "draft");
|
||||
if (deleted > 0) {
|
||||
jsonCache.invalidate(draftKey(siteId));
|
||||
log.info("预览版已丢弃: siteId={}, 删除 {} 条记录", siteId, deleted);
|
||||
} else {
|
||||
log.info("站点 {} 无预览版可丢弃", siteId);
|
||||
}
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/** 将快照转为 mediabot 可用的 JSON 字符串 */
|
||||
private String toBundleJson(SiteSnapshot snapshot) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user