diff --git a/configmanage/server/internal/hostfile.go b/configmanage/server/internal/hostfile.go index 41adec526fb6cdc64b268463be84879bc1d405d0..5c0c1bb66c07040db4ce383790856651b520a1ff 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 c9f8a478b7cc2c779665a2326cd9f49bfa745c85..67e378ed645942602af2d437546d31b3b5658f55 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() }