修复配置更新错误问题
This commit is contained in:
@@ -56,10 +56,7 @@ func DisableEdgesByMacs(tx *gorm.DB, macs []string) error {
|
||||
|
||||
// 分批处理MAC地址列表
|
||||
for i := 0; i < len(macs); i += batchSize {
|
||||
end := i + batchSize
|
||||
if end > len(macs) {
|
||||
end = len(macs)
|
||||
}
|
||||
end := min(i+batchSize, len(macs))
|
||||
|
||||
batch := macs[i:end]
|
||||
err := tx.Model(&model.Edge{}).Where("macaddr IN ?", batch).Update("active", false).Error
|
||||
|
||||
@@ -141,9 +141,9 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
|
||||
GatewayMac: gateway.Macaddr,
|
||||
Macaddr: newConfig.Macaddr,
|
||||
Table: strconv.Itoa(iCity + 1),
|
||||
User: fmt.Sprintf("jdzz%ddt%d", iGateway+1, iCity+1),
|
||||
User: fmt.Sprintf("jdzz%ddt%d", gateway.Id, iCity+1),
|
||||
Network: fmt.Sprintf("172.30.168.%d", iCity+2),
|
||||
InnerIp: fmt.Sprintf("172.16.%d.%d", iGateway+1, iCity+2),
|
||||
InnerIp: fmt.Sprintf("172.16.%d.%d", gateway.Id, iCity+2),
|
||||
})
|
||||
|
||||
newConfigs[gateway][iCity] = ConfigInfo{
|
||||
@@ -187,9 +187,7 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
|
||||
slog.Info(fmt.Sprintf("提交网关配置,网关:%s,变更数:%d,新增数:%d", gateway.Macaddr, change, setup))
|
||||
|
||||
// 提交配置到云端:配置版本 gateway.ConfigVersion
|
||||
if arg.Mock {
|
||||
slog.Info(fmt.Sprintf("[MOCK] 配置网关,网关:%s,配置:%v", gateway.Macaddr, edges))
|
||||
} else {
|
||||
if !arg.Mock {
|
||||
err := jd.GatewayConfigSet(gateway.ConfigVersion, gateway.Macaddr, edges)
|
||||
if err != nil {
|
||||
return fmt.Errorf("配置网关 %s 失败:%w", gateway.Macaddr, err)
|
||||
|
||||
32
cmd/test.go
Normal file
32
cmd/test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"zzman/actions"
|
||||
"zzman/clients"
|
||||
"zzman/model"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 初始化环境
|
||||
slog.Debug("初始化环境变量")
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
slog.Error(fmt.Errorf("初始化变量失败:%w", err).Error())
|
||||
}
|
||||
|
||||
// 初始化数据库和 Redis
|
||||
model.Init()
|
||||
defer model.Close()
|
||||
|
||||
clients.InitRedis()
|
||||
defer clients.CloseRedis()
|
||||
|
||||
// 测试功能
|
||||
actions.Update(actions.UpdateArgs{
|
||||
Mock: true,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user