Files
jh-zz/actions/configs.go

42 lines
755 B
Go
Raw Normal View History

2025-08-05 10:51:35 +08:00
package actions
import (
"zzman/model"
"gorm.io/gorm"
2025-08-05 10:51:35 +08:00
)
func FindConfigsByGateway(tx *gorm.DB, macaddr string) ([]model.Config, error) {
var configs []model.Config
err := tx.Find(&configs, "macaddr = ?", macaddr).Error
if err != nil {
return nil, err
}
return configs, nil
}
func CreateConfigs(tx *gorm.DB, configs []model.Config) error {
if len(configs) == 0 {
return nil
}
// 使用事务批量插入配置
return tx.Omit("createtime", "updatetime").Create(&configs).Error
2025-08-05 10:51:35 +08:00
}
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 {
err := tx.Updates(&config).Error
if err != nil {
return err
}
}
return nil
2025-08-05 10:51:35 +08:00
}