diff --git a/configmanage/server/internal/configinfo.go b/configmanage/server/internal/configinfo.go index b08ca97ad16df76d0c7b987f9529b73747fe6bac..b0ef046b62be3c0523701b071360dab41ae7c154 100644 --- a/configmanage/server/internal/configinfo.go +++ b/configmanage/server/internal/configinfo.go @@ -15,7 +15,7 @@ func (cm *ConfigInfo) Add() error { func GetInfoByUUID(uuid string) (ConfigInfo, error) { var ci ConfigInfo - err := db.MySQL().Where("uuid=?", uuid).Find(&ci).Error + err := db.MySQL().Model(&ConfigInfo{}).Where("uuid=?", uuid).Find(&ci).Error return ci, err } @@ -26,6 +26,6 @@ func GetInfos(offset, size int) (int, []*ConfigInfo, error) { if err != nil { return 0, infos, err } - err = db.MySQL().Limit(size).Offset(offset).Find(&infos).Error + err = db.MySQL().Model(&ConfigInfo{}).Limit(size).Offset(offset).Find(&infos).Error return int(count), infos, err } diff --git a/configmanage/server/internal/hostfile.go b/configmanage/server/internal/hostfile.go index c6ea6dd357026f2995a96c29f67393e25b1767f4..24645a8f85b1638be67237444e1279c05aec8176 100644 --- a/configmanage/server/internal/hostfile.go +++ b/configmanage/server/internal/hostfile.go @@ -35,3 +35,19 @@ func GetHostFileByInfoUUID(uuid string, isindex interface{}) (HostFile, error) { err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error return file, err } + +func GetHostFileByUUID(uuid string) (HostFile, error) { + var file HostFile + err := db.MySQL().Model(&HostFile{}).Where("uuid=?", uuid).Find(&file).Error + return file, err +} + +func (hf *HostFile) UpdateByuuid() error { + // 将同类配置的所有标志修改为未使用 + err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=?", hf.ConfigInfoUUID).Update("is_index", 0).Error + if err != nil { + return err + } + // 将成功下发的具体某一个配置状态修改为已使用 + return db.MySQL().Model(&HostFile{}).Where("uuid=?", hf.UUID).Update("is_index", 1).Error +} diff --git a/configmanage/server/internal/repofile.go b/configmanage/server/internal/repofile.go index 20ec36f5ed9098cf1eeffdd01d81900c34dd34d7..d1b05c62cad9f7f6b0ed3107fa33ee9191352d08 100644 --- a/configmanage/server/internal/repofile.go +++ b/configmanage/server/internal/repofile.go @@ -29,32 +29,32 @@ func (rf *RepoFile) Add() error { func GetRepoFileByInfoUUID(uuid string, isindex interface{}) (RepoFile, error) { var file RepoFile if isindex != nil { - err := db.MySQL().Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error return file, err } - err := db.MySQL().Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error return file, err } func GetRepoFileByUUID(uuid string) (RepoFile, error) { var file RepoFile - err := db.MySQL().Where("uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("uuid=?", uuid).Find(&file).Error return file, err } func (rf *RepoFile) UpdateByuuid() error { // 将同类配置的所有标志修改为未使用 - err := db.MySQL().Table("repo_file").Where("config_info_uuid=?", rf.ConfigInfoUUID).Update("is_index", 0).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=?", rf.ConfigInfoUUID).Update("is_index", 0).Error if err != nil { return err } // 将成功下发的具体某一个配置状态修改为已使用 - return db.MySQL().Table("repo_file").Where("uuid=?", rf.UUID).Update("is_index", 1).Error + return db.MySQL().Model(&RepoFile{}).Where("uuid=?", rf.UUID).Update("is_index", 1).Error } // 根据配置uuid获取所有配置文件 func GetRopeFilesByCinfigUUID(uuid string) ([]RepoFile, error) { var files []RepoFile - err := db.MySQL().Where("config_info_uuid=?", uuid).Find(&files).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=?", uuid).Find(&files).Error return files, err } diff --git a/configmanage/server/service/host_test.go b/configmanage/server/service/host_test.go index 8350b775c3f0943e0b235a7d759ea272d6c36599..9a861a104fbac6f4ba5363c8419bfba518f47d7f 100644 --- a/configmanage/server/service/host_test.go +++ b/configmanage/server/service/host_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/google/uuid" + "openeuler.org/PilotGo/configmanage-plugin/internal" ) func TestHostConfig_Record(t *testing.T) { @@ -40,3 +41,13 @@ func TestHostConfig_Load(t *testing.T) { } fmt.Printf("hc: %v\n", hc) } + +func TestGetHostFileByUUID(t *testing.T) { + uuid := "4254b485-8e8a-427c-bed1-5da05e363657" + hf, err := internal.GetHostFileByUUID(uuid) + if err != nil { + fmt.Printf("get host file error: %s\n", err) + os.Exit(-1) + } + fmt.Printf("hc: %v\n", hf) +}