新节点默认无在线;提供 debug 配置项以控制是否启用保存配置记录

This commit is contained in:
2025-12-26 16:43:08 +08:00
parent 2c818576ef
commit 54c2903c75
15 changed files with 60 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
package actions
import (
"zzman/model"
"jhman/model"
"gorm.io/gorm"
)

View File

@@ -2,7 +2,7 @@ package actions
import (
"fmt"
"zzman/model"
"jhman/model"
"gorm.io/gorm"
)

View File

@@ -2,8 +2,8 @@ package actions
import (
"fmt"
"zzman/clients/jd"
"zzman/model"
"jhman/clients/jd"
"jhman/model"
)
func Clear() error {

View File

@@ -1,7 +1,7 @@
package actions
import (
"zzman/model"
"jhman/model"
"gorm.io/gorm"
)

View File

@@ -2,7 +2,7 @@ package actions
import (
"fmt"
"zzman/model"
"jhman/model"
"gorm.io/gorm"
)

View File

@@ -2,8 +2,8 @@ package actions
import (
"fmt"
"jhman/model"
"math"
"zzman/model"
"gorm.io/gorm"
)

View File

@@ -2,10 +2,10 @@ package actions
import (
"fmt"
"jhman/model"
"strconv"
"zzman/model"
u "zzman/util"
u "jhman/util"
"gorm.io/gorm"
)

View File

@@ -3,9 +3,9 @@ package actions
import (
"encoding/json"
"fmt"
"jhman/clients/jd"
"jhman/model"
"time"
"zzman/clients/jd"
"zzman/model"
)
func RecordSubmit(time time.Time, gatewat model.Gateway, edges []jd.EdgeInfo) error {

View File

@@ -2,9 +2,9 @@ package actions
import (
"fmt"
"jhman/clients/jd"
"jhman/model"
"log/slog"
"zzman/clients/jd"
"zzman/model"
"gorm.io/gorm"
)

View File

@@ -2,11 +2,12 @@ package actions
import (
"fmt"
"jhman/clients/jd"
"jhman/model"
u "jhman/util"
"log/slog"
"os"
"time"
"zzman/clients/jd"
"zzman/model"
u "zzman/util"
"gorm.io/gorm"
)
@@ -140,7 +141,7 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
Id: config.Id,
EdgeMac: u.P(edge.Macaddr),
IsChange: u.P(0),
IsOnline: u.P(1),
IsOnline: u.P(0),
},
}
changesCreate = append(changesCreate, model.Change{
@@ -166,10 +167,12 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
step = time.Now()
// 记录节点变更
if os.Getenv("DEBUG") == "true" {
err = RecordChanges(tx, changesCreate)
if err != nil {
return fmt.Errorf("记录节点变更失败:%w", err)
}
}
println(fmt.Sprintf("记录节点变更:%v", time.Since(step)))
step = time.Now()
@@ -203,10 +206,12 @@ func update(tx *gorm.DB, arg UpdateArgs) error {
}
// 记录提交配置
if os.Getenv("DEBUG") == "true" {
err = RecordSubmit(now, gateway, edges)
if err != nil {
return fmt.Errorf("记录网关 %s 提交配置失败:%w", gateway.Macaddr, err)
}
}
// 提交配置到云端:配置版本 gateway.ConfigVersion
if !arg.Mock {

View File

@@ -6,11 +6,12 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/redis/go-redis/v9"
"io"
"jhman/clients"
"net/http"
"time"
"zzman/clients"
"github.com/redis/go-redis/v9"
)
const base = "https://smart.jdbox.xyz:58001"

2
go.mod
View File

@@ -1,4 +1,4 @@
module zzman
module jhman
go 1.24.0

View File

@@ -2,14 +2,14 @@ package main
import (
"fmt"
"jhman/actions"
"jhman/clients"
"jhman/model"
"log/slog"
"os"
"path/filepath"
"slices"
"strings"
"zzman/actions"
"zzman/clients"
"zzman/model"
"github.com/joho/godotenv"
slogjournal "github.com/systemd/slog-journal"

12
rollback.sh Normal file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -e
# 此脚本应当运行在服务端,与 deploy.ps1 脚本上传到的位置配合,自动切换回退
cp cli cli.new
chmod -x cli.new
chmod +x cli.bak
mv cli.bak cli
echo 'done~'

12
update.sh Normal file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -e
# 此脚本应当运行在服务端,与 deploy.ps1 脚本上传到的位置配合,自动切换更新
cp cli cli.bak
chmod -x cli.bak
chmod +x cli.new
mv cli.new cli
echo 'done~'