建立仓库
This commit is contained in:
33
actions/configs.go
Normal file
33
actions/configs.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"zzman/model"
|
||||
)
|
||||
|
||||
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.Create(&configs).Error
|
||||
}
|
||||
|
||||
func UpdateConfigs(tx *gorm.DB, configs []model.ConfigUpdate) error {
|
||||
if len(configs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 使用事务批量更新配置
|
||||
return tx.Updates(&configs).Error
|
||||
}
|
||||
Reference in New Issue
Block a user