zhangzengfei
2024-12-19 4e269daa939f3da316a0e079ca35b05e162adfcb
调整初始化
2个文件已修改
21 ■■■■ 已修改文件
db/db.go 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/gather_model.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/db.go
@@ -1,8 +1,6 @@
package db
import (
    "time"
    "github.com/elastic/go-elasticsearch/v6"
    "gorm.io/gorm"
@@ -59,25 +57,27 @@
// InitDefaultData 初始化数据
func InitDefaultData() error {
    var models = []Model{
    var models = []*Model{
        {
            BaseModel: BaseModel{
                ID:        ModelIdGather,
                CreatedAt: time.Time{},
                UpdatedAt: time.Time{},
                ID: ModelIdGather,
            },
            Name:        "疑似聚集",
            Description: "通用聚集模型",
            Version:     "v1.0.0",
            Version:     "v1.0.1",
            Enabled:     false,
        },
    }
    for i := range models {
        GetDB().Save(&models[i])
        if err := GetDB().Model(models[i]).First(models[i].ID).Error; err != nil {
            GetDB().Model(models[i]).Create(models[i])
        } else {
            GetDB().Model(models[i]).Update("version", models[i].Version)
        }
    }
    var rules = []ModelRule{
    var rules = []*ModelRule{
        {
            Id:      "bfbdba7f-ee39-41fb-b188-b4c114a51eaa",
            ModelId: ModelIdGather,
models/gather_model.go
@@ -81,9 +81,10 @@
        }
    }
    fmt.Printf("GatherModel init finish ...task id:%s, name:%s, rule:%+v\n", task.ID, task.Name, task.Rules)
    fmt.Printf("GatherModel init finish ...task id:%s, name:%s, rule:%+v\n", task.ID, task.Name, m)
    if m.GatherPersons == 0 || m.AppearInterval == 0 || m.DaysWindow == 0 || m.Threshold == 0 {
        fmt.Printf("invalid parameters. task id:%s, name:%s\n", task.ID, task.Name)
        return errors.New("invalid parameters")
    }