|
|
|
@@ -42,6 +42,7 @@ type Model struct { |
|
|
|
Endpoints string `json:"endpoints,omitempty" gorm:"type:text"` |
|
|
|
Status int `json:"status" gorm:"default:1"` |
|
|
|
SyncOfficial int `json:"sync_official" gorm:"default:1"` |
|
|
|
SortOrder int `json:"sort_order" gorm:"default:0"` |
|
|
|
CreatedTime int64 `json:"created_time" gorm:"bigint"` |
|
|
|
UpdatedTime int64 `json:"updated_time" gorm:"bigint"` |
|
|
|
DeletedAt gorm.DeletedAt `json:"-" gorm:"index;uniqueIndex:uk_model_name_delete_at,priority:2"` |
|
|
|
@@ -89,7 +90,7 @@ func (mi *Model) Update() error { |
|
|
|
mi.UpdatedTime = common.GetTimestamp() |
|
|
|
// 使用 Select 强制更新所有字段,包括零值 |
|
|
|
return DB.Model(&Model{}).Where("id = ?", mi.Id). |
|
|
|
Select("model_name", "description", "icon", "tags", "type", "vendor_id", "endpoints", "status", "sync_official", "name_rule", "updated_time"). |
|
|
|
Select("model_name", "description", "icon", "tags", "type", "vendor_id", "endpoints", "status", "sync_official", "name_rule", "sort_order", "updated_time"). |
|
|
|
Updates(mi).Error |
|
|
|
} |
|
|
|
|
|
|
|
@@ -117,7 +118,7 @@ func GetVendorModelCounts() (map[int64]int64, error) { |
|
|
|
|
|
|
|
func GetAllModels(offset int, limit int) ([]*Model, error) { |
|
|
|
var models []*Model |
|
|
|
err := DB.Order("id DESC").Offset(offset).Limit(limit).Find(&models).Error |
|
|
|
err := DB.Order("sort_order ASC, id ASC").Offset(offset).Limit(limit).Find(&models).Error |
|
|
|
return models, err |
|
|
|
} |
|
|
|
|
|
|
|
@@ -165,7 +166,7 @@ func SearchModels(keyword string, vendor string, offset int, limit int) ([]*Mode |
|
|
|
if err := db.Count(&total).Error; err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
if err := db.Order("models.id DESC").Offset(offset).Limit(limit).Find(&models).Error; err != nil { |
|
|
|
if err := db.Order("sort_order ASC, models.id ASC").Offset(offset).Limit(limit).Find(&models).Error; err != nil { |
|
|
|
return nil, 0, err |
|
|
|
} |
|
|
|
return models, total, nil |
|
|
|
|