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)
|
log.Printf("[DEBUG] Version %d: ID=%d, ApplicationID=%d, Version=%s\n", i, v.ID, v.ApplicationID, v.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
latestVersionIDs := make(map[uint]uint)
|
versionIDs := make([]uint, len(versions))
|
||||||
var latestIDs []uint
|
versionAppIDMap := make(map[uint]uint)
|
||||||
database.DB.Model(&model.Version{}).
|
for i, v := range versions {
|
||||||
Where("application_id IN ?", appIDs).
|
versionIDs[i] = v.ID
|
||||||
Select("MAX(id)").
|
versionAppIDMap[v.ID] = v.ApplicationID
|
||||||
Group("application_id").
|
}
|
||||||
Pluck("MAX(id)", &latestIDs)
|
|
||||||
for _, id := range latestIDs {
|
var allVersionsForApps []model.Version
|
||||||
latestVersionIDs[id] = id
|
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 {
|
type VersionWithAppName struct {
|
||||||
@@ -147,11 +153,23 @@ func handleGetAllVersions(c *gin.Context) {
|
|||||||
for i, v := range versions {
|
for i, v := range versions {
|
||||||
appName := appNameMap[v.ApplicationID]
|
appName := appNameMap[v.ApplicationID]
|
||||||
log.Printf("[DEBUG] Mapping version %d: ApplicationID=%d -> AppName=%s\n", i, v.ApplicationID, appName)
|
log.Printf("[DEBUG] Mapping version %d: ApplicationID=%d -> AppName=%s\n", i, v.ApplicationID, appName)
|
||||||
if _, isLatest := latestVersionIDs[v.ID]; isLatest {
|
|
||||||
v.Status = "active"
|
isSuperseded := false
|
||||||
} else {
|
if forcedIDs, ok := appForcedVersionIDs[v.ApplicationID]; ok {
|
||||||
v.Status = "superseded"
|
for _, forcedID := range forcedIDs {
|
||||||
|
if forcedID > v.ID {
|
||||||
|
isSuperseded = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isSuperseded {
|
||||||
|
v.Status = "superseded"
|
||||||
|
} else {
|
||||||
|
v.Status = "active"
|
||||||
|
}
|
||||||
|
|
||||||
result[i] = VersionWithAppName{
|
result[i] = VersionWithAppName{
|
||||||
Version: v,
|
Version: v,
|
||||||
ApplicationName: appName,
|
ApplicationName: appName,
|
||||||
@@ -187,14 +205,13 @@ func handleGetVersionByID(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var latestID uint
|
computedStatus := "active"
|
||||||
|
var forcedCount int64
|
||||||
database.DB.Model(&model.Version{}).
|
database.DB.Model(&model.Version{}).
|
||||||
Where("application_id = ?", version.ApplicationID).
|
Where("application_id = ? AND id > ? AND update_strategy = ?", version.ApplicationID, version.ID, "forced").
|
||||||
Select("MAX(id)").
|
Count(&forcedCount)
|
||||||
Scan(&latestID)
|
if forcedCount > 0 {
|
||||||
computedStatus := "superseded"
|
computedStatus = "superseded"
|
||||||
if version.ID == latestID {
|
|
||||||
computedStatus = "active"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Success(c, gin.H{
|
response.Success(c, gin.H{
|
||||||
|
|||||||
@@ -90,16 +90,16 @@ export function getColumns(options: ColumnOptions, t: (key: string) => string):
|
|||||||
accessorKey: 'status',
|
accessorKey: 'status',
|
||||||
header: () => t('admin.versions.columns.status'),
|
header: () => t('admin.versions.columns.status'),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const strategy = row.original.update_strategy
|
const status = row.original.status
|
||||||
const statusClasses: Record<string, string> = {
|
const statusClasses: Record<string, string> = {
|
||||||
optional: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400',
|
active: 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400',
|
||||||
forced: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400',
|
superseded: 'bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400',
|
||||||
}
|
}
|
||||||
const statusLabels: Record<string, string> = {
|
const statusLabels: Record<string, string> = {
|
||||||
optional: t('admin.versions.strategies.optional'),
|
active: t('admin.versions.status.active'),
|
||||||
forced: t('admin.versions.strategies.forced'),
|
superseded: t('admin.versions.status.superseded'),
|
||||||
}
|
}
|
||||||
return h(Badge, { class: statusClasses[strategy] || statusClasses.optional }, () => statusLabels[strategy] || strategy)
|
return h(Badge, { class: statusClasses[status] || statusClasses.superseded }, () => statusLabels[status] || status)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user