From a24bd1e50dd3cdc1a3ad8efb444372db051974bb Mon Sep 17 00:00:00 2001 From: wubijie Date: Tue, 12 Nov 2024 16:52:59 +0800 Subject: [PATCH] Modify the hostfile storage mode --- configmanage/server/internal/hostfile.go | 26 +++++++++++++++++++++++- configmanage/server/service/host.go | 6 ------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/configmanage/server/internal/hostfile.go b/configmanage/server/internal/hostfile.go index 41adec52..5c0c1bb6 100644 --- a/configmanage/server/internal/hostfile.go +++ b/configmanage/server/internal/hostfile.go @@ -23,7 +23,31 @@ type HostFile struct { } func (hf *HostFile) Add() error { - return db.MySQL().Save(&hf).Error + sql := ` + INSERT INTO host_file (uuid,config_info_uuid,path,name,content,version,is_active,is_from_host,hostuuid) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) + ON DUPLICATE KEY UPDATE + uuid = VALUES(uuid), + config_info_uuid = VALUES(config_info_uuid), + path = VALUES(path), + name = VALUES(name), + content = VALUES(content), + version = VALUES(version), + is_active = VALUES(is_active), + is_from_host = VALUES(is_from_host), + hostuuid = VALUES(hostuuid); + ` + return db.MySQL().Exec(sql, + hf.UUID, + hf.ConfigInfoUUID, + hf.Path, + hf.Name, + hf.Content, + hf.Version, + hf.IsActive, + hf.IsFromHost, + hf.Hostuuid, + ).Error } func GetHostFileByInfoUUID(uuid string, isindex interface{}) (HostFile, error) { diff --git a/configmanage/server/service/host.go b/configmanage/server/service/host.go index c9f8a478..67e378ed 100644 --- a/configmanage/server/service/host.go +++ b/configmanage/server/service/host.go @@ -63,12 +63,6 @@ func toHostConfig(hf *HostFile) HostConfig { } func (hc *HostConfig) Record() error { - //检查info的uuid是否存在 - ci, err := GetInfoByUUID(hc.ConfigInfoUUID) - if err != nil || ci.UUID == "" { - return errors.New("configinfo uuid not exist") - } - hf := hc.toHostFile() return hf.Add() } -- Gitee