diff --git a/par-api/src/main/java/com/par/api/controller/AdminController.java b/par-api/src/main/java/com/par/api/controller/AdminController.java index 4bd584c..d094810 100644 --- a/par-api/src/main/java/com/par/api/controller/AdminController.java +++ b/par-api/src/main/java/com/par/api/controller/AdminController.java @@ -357,23 +357,18 @@ public class AdminController { // 2. 使用快照服务发布有变更的站点 int publishedCount = snapshotService.publishChanged(); - // 3. 兼容:为所有站点生成旧的 bundles/ 路径(从快照读取) + // 3. 兼容:为有 published 快照的站点生成旧的 bundles/ 路径 int bundleCount = 0; @SuppressWarnings("unchecked") var sites = (List>) manifest.get("sites"); for (var site : sites) { String siteId = (String) site.get("siteId"); try { - var active = snapshotService.getActive(siteId); - if (active != null) { - // 生成兼容的 bundle JSON 并上传到旧路径 - Map bundle = snapshotService.buildSnapshot(siteId); - if (bundle != null) { - String bundleJson = new com.fasterxml.jackson.databind.ObjectMapper() - .writeValueAsString(bundle); - storageService.store("bundles/" + siteId + ".json", bundleJson); - bundleCount++; - } + // 直接读取已发布的快照(此时 publishChanged 已执行完毕,缓存中有最新数据) + String activeJson = snapshotService.getActiveBundleJson(siteId); + if (activeJson != null && !activeJson.isEmpty()) { + storageService.store("bundles/" + siteId + ".json", activeJson); + bundleCount++; } } catch (Exception e) { log.warn("生成兼容 bundle 失败 siteId={}: {}", siteId, e.getMessage()); 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 b5ce314..0eb6186 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 @@ -156,6 +156,12 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService { snapshot.setStatus("draft"); snapshotMapper.insert(snapshot); + + // 刷新 draft 和 preview 缓存(审批通过后异步生成 draft,需立即可被预览查询到) + String bundleJson = toBundleJson(snapshot); + draftJsonCache.put(siteId, bundleJson); + previewJsonCache.put(siteId, bundleJson); + log.info("快照已更新: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8)); return snapshot; } catch (Exception e) { @@ -195,9 +201,10 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService { snapshotMapper.insert(snapshot); - // 刷新 draft 缓存 + // 刷新 draft 和 preview 缓存 String bundleJson = toBundleJson(snapshot); draftJsonCache.put(siteId, bundleJson); + previewJsonCache.put(siteId, bundleJson); log.info("草稿已保存: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8)); return snapshot; diff --git a/web/src/views/Sites.vue b/web/src/views/Sites.vue index a512822..7780fa9 100644 --- a/web/src/views/Sites.vue +++ b/web/src/views/Sites.vue @@ -56,6 +56,7 @@

站点编辑: {{ editSiteId }}

返回列表 + 保存站点 保存草稿 发布正式版