Files
jh-zz/actions/configs.go

49 lines
743 B
Go
Raw Permalink Normal View History

2025-08-05 10:51:35 +08:00
package actions
import (
"jhman/model"
"gorm.io/gorm"
2025-08-05 10:51:35 +08:00
)
2025-09-10 18:26:59 +08:00
func FindConfigs(tx *gorm.DB) ([]model.Config, error) {
2025-08-05 10:51:35 +08:00
var configs []model.Config
2025-09-10 18:26:59 +08:00
err := tx.Find(&configs).Error
2025-08-05 10:51:35 +08:00
if err != nil {
return nil, err
}
return configs, nil
}
func UpdateConfigs(tx *gorm.DB, configs []model.ConfigUpdate) error {
if len(configs) == 0 {
return nil
}
2025-08-11 16:14:16 +08:00
// 批量更新配置
for _, config := range configs {
2025-09-10 18:26:59 +08:00
err := tx.
Where("id = ?", config.Id).
Updates(&config).
Error
2025-08-11 16:14:16 +08:00
if err != nil {
return err
}
}
return nil
2025-08-05 10:51:35 +08:00
}
2025-09-11 14:40:11 +08:00
func CreateConfigs(tx *gorm.DB, configs []model.ConfigCreate) error {
if len(configs) == 0 {
return nil
}
err := tx.CreateInBatches(&configs, 500).Error
if err != nil {
return err
}
return nil
}