修复配置更新错误问题

This commit is contained in:
2025-08-19 17:25:01 +08:00
parent 95c1a34ea4
commit 261ee88a4b
3 changed files with 36 additions and 9 deletions

View File

@@ -56,10 +56,7 @@ func DisableEdgesByMacs(tx *gorm.DB, macs []string) error {
// 分批处理MAC地址列表 // 分批处理MAC地址列表
for i := 0; i < len(macs); i += batchSize { for i := 0; i < len(macs); i += batchSize {
end := i + batchSize end := min(i+batchSize, len(macs))
if end > len(macs) {
end = len(macs)
}
batch := macs[i:end] batch := macs[i:end]
err := tx.Model(&model.Edge{}).Where("macaddr IN ?", batch).Update("active", false).Error err := tx.Model(&model.Edge{}).Where("macaddr IN ?", batch).Update("active", false).Error

View File

@@ -141,9 +141,9 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
GatewayMac: gateway.Macaddr, GatewayMac: gateway.Macaddr,
Macaddr: newConfig.Macaddr, Macaddr: newConfig.Macaddr,
Table: strconv.Itoa(iCity + 1), 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), 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{ 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)) slog.Info(fmt.Sprintf("提交网关配置,网关:%s变更数%d新增数%d", gateway.Macaddr, change, setup))
// 提交配置到云端:配置版本 gateway.ConfigVersion // 提交配置到云端:配置版本 gateway.ConfigVersion
if arg.Mock { if !arg.Mock {
slog.Info(fmt.Sprintf("[MOCK] 配置网关,网关:%s配置%v", gateway.Macaddr, edges))
} else {
err := jd.GatewayConfigSet(gateway.ConfigVersion, gateway.Macaddr, edges) err := jd.GatewayConfigSet(gateway.ConfigVersion, gateway.Macaddr, edges)
if err != nil { if err != nil {
return fmt.Errorf("配置网关 %s 失败:%w", gateway.Macaddr, err) return fmt.Errorf("配置网关 %s 失败:%w", gateway.Macaddr, err)

32
cmd/test.go Normal file
View 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,
})
}