fix: 适配校验页两个 bug
1. buildSnapshot 改用 selectRecentBySiteId(按updated_at取最新配置),不再依赖 is_latest 修复:编辑脚本后保存预览版,buildSnapshot 读到旧脚本导致快照生成失败,发布按钮不出现 2. approveConfig 版本号排序改为 CAST(version AS UNSIGNED) 数值排序 修复:version 是 VARCHAR,字母序导致 '9' > '10',版本号永远过不了 10
This commit is contained in:
@@ -91,12 +91,12 @@ public class AdminController {
|
||||
|
||||
Long reviewerId = (Long) request.getAttribute("accountId");
|
||||
|
||||
// 自动分配版本号:取该站点已审批的最大版本号 + 1
|
||||
// 自动分配版本号:取该站点已审批的最大版本号 + 1(version 是 VARCHAR,需 CAST 数值排序)
|
||||
var latestApproved = siteConfigMapper.selectList(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SiteConfig>()
|
||||
.eq(SiteConfig::getSiteId, config.getSiteId())
|
||||
.eq(SiteConfig::getStatus, ConfigStatus.APPROVED)
|
||||
.orderByDesc(SiteConfig::getVersion));
|
||||
.last("ORDER BY CAST(version AS UNSIGNED) DESC"));
|
||||
int nextVersion = 1;
|
||||
if (!latestApproved.isEmpty()) {
|
||||
try { nextVersion = Integer.parseInt(latestApproved.get(0).getVersion()) + 1; }
|
||||
|
||||
@@ -18,6 +18,10 @@ public interface SiteConfigMapper extends BaseMapper<SiteConfig> {
|
||||
@Select("SELECT * FROM site_configs WHERE site_id = #{siteId} AND is_latest = 1 AND deleted = 0 LIMIT 1")
|
||||
SiteConfig selectLatestBySiteId(@Param("siteId") String siteId);
|
||||
|
||||
/** 取最后更新的配置(用于快照构建,不受 is_latest 限制) */
|
||||
@Select("SELECT * FROM site_configs WHERE site_id = #{siteId} AND deleted = 0 ORDER BY updated_at DESC LIMIT 1")
|
||||
SiteConfig selectRecentBySiteId(@Param("siteId") String siteId);
|
||||
|
||||
@Select("SELECT * FROM site_configs WHERE site_id = #{siteId} AND status = 'approved' AND deleted = 0 ORDER BY created_at DESC")
|
||||
List<SiteConfig> selectApprovedBySiteId(@Param("siteId") String siteId);
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
|
||||
var site = siteMapper.selectBySiteId(siteId);
|
||||
String siteType = site != null && site.getSiteType() != null ? site.getSiteType().getValue() : null;
|
||||
|
||||
// 1. 脚本
|
||||
SiteConfig latest = siteConfigMapper.selectLatestBySiteId(siteId);
|
||||
// 1. 脚本(取最后更新的配置,不受 is_latest 限制,确保未审批的脚本也能入快照)
|
||||
SiteConfig latest = siteConfigMapper.selectRecentBySiteId(siteId);
|
||||
if (latest != null && latest.getScriptStoragePath() != null && !latest.getScriptStoragePath().isBlank()) {
|
||||
try {
|
||||
String script = storageService.read(latest.getScriptStoragePath());
|
||||
|
||||
Reference in New Issue
Block a user