fix: 状态列根据是否有更新的强制版本判断生效/失效
This commit is contained in:
@@ -127,15 +127,21 @@ func handleGetAllVersions(c *gin.Context) {
|
||||
log.Printf("[DEBUG] Version %d: ID=%d, ApplicationID=%d, Version=%s\n", i, v.ID, v.ApplicationID, v.Version)
|
||||
}
|
||||
|
||||
latestVersionIDs := make(map[uint]uint)
|
||||
var latestIDs []uint
|
||||
database.DB.Model(&model.Version{}).
|
||||
Where("application_id IN ?", appIDs).
|
||||
Select("MAX(id)").
|
||||
Group("application_id").
|
||||
Pluck("MAX(id)", &latestIDs)
|
||||
for _, id := range latestIDs {
|
||||
latestVersionIDs[id] = id
|
||||
versionIDs := make([]uint, len(versions))
|
||||
versionAppIDMap := make(map[uint]uint)
|
||||
for i, v := range versions {
|
||||
versionIDs[i] = v.ID
|
||||
versionAppIDMap[v.ID] = v.ApplicationID
|
||||
}
|
||||
|
||||
var allVersionsForApps []model.Version
|
||||
database.DB.Where("application_id IN ?", appIDs).Select("id, application_id, update_strategy").Find(&allVersionsForApps)
|
||||
|
||||
appForcedVersionIDs := make(map[uint][]uint)
|
||||
for _, v := range allVersionsForApps {
|
||||
if v.UpdateStrategy == "forced" {
|
||||
appForcedVersionIDs[v.ApplicationID] = append(appForcedVersionIDs[v.ApplicationID], v.ID)
|
||||
}
|
||||
}
|
||||
|
||||
type VersionWithAppName struct {
|
||||
@@ -147,11 +153,23 @@ func handleGetAllVersions(c *gin.Context) {
|
||||
for i, v := range versions {
|
||||
appName := appNameMap[v.ApplicationID]
|
||||
log.Printf("[DEBUG] Mapping version %d: ApplicationID=%d -> AppName=%s\n", i, v.ApplicationID, appName)
|
||||
if _, isLatest := latestVersionIDs[v.ID]; isLatest {
|
||||
v.Status = "active"
|
||||
} else {
|
||||
v.Status = "superseded"
|
||||
|
||||
isSuperseded := false
|
||||
if forcedIDs, ok := appForcedVersionIDs[v.ApplicationID]; ok {
|
||||
for _, forcedID := range forcedIDs {
|
||||
if forcedID > v.ID {
|
||||
isSuperseded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if isSuperseded {
|
||||
v.Status = "superseded"
|
||||
} else {
|
||||
v.Status = "active"
|
||||
}
|
||||
|
||||
result[i] = VersionWithAppName{
|
||||
Version: v,
|
||||
ApplicationName: appName,
|
||||
@@ -187,14 +205,13 @@ func handleGetVersionByID(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var latestID uint
|
||||
computedStatus := "active"
|
||||
var forcedCount int64
|
||||
database.DB.Model(&model.Version{}).
|
||||
Where("application_id = ?", version.ApplicationID).
|
||||
Select("MAX(id)").
|
||||
Scan(&latestID)
|
||||
computedStatus := "superseded"
|
||||
if version.ID == latestID {
|
||||
computedStatus = "active"
|
||||
Where("application_id = ? AND id > ? AND update_strategy = ?", version.ApplicationID, version.ID, "forced").
|
||||
Count(&forcedCount)
|
||||
if forcedCount > 0 {
|
||||
computedStatus = "superseded"
|
||||
}
|
||||
|
||||
response.Success(c, gin.H{
|
||||
|
||||
Reference in New Issue
Block a user