From 173fa23e80fe96483a520ffc8369e6a446829f3b Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 22 Sep 2023 13:35:05 +0800 Subject: [PATCH] info --- server/info/internal/logic/infologic.go | 12 ++++++ server/info/internal/logic/infologic_test.go | 42 ++++++++++---------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/server/info/internal/logic/infologic.go b/server/info/internal/logic/infologic.go index 69c175ae..6b168b06 100644 --- a/server/info/internal/logic/infologic.go +++ b/server/info/internal/logic/infologic.go @@ -99,6 +99,18 @@ func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string if err == gorm.ErrRecordNotFound { logx.Error(err) } + + if v, ok := info[queryAsName]; ok { + var qinfo map[string]any + err := json.Unmarshal([]byte(v.(string)), &qinfo) + if err != nil { + logx.Error(err) + } else { + info[queryAsName] = qinfo + } + + } + return info } diff --git a/server/info/internal/logic/infologic_test.go b/server/info/internal/logic/infologic_test.go index ec0e1d05..040b4c7f 100644 --- a/server/info/internal/logic/infologic_test.go +++ b/server/info/internal/logic/infologic_test.go @@ -115,9 +115,9 @@ func TestMain(t *testing.T) { if v, ok := metadict["userinfo.profile"]; ok { if v == nil { + info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info") metadict["userinfo.profile"] = info - // log.Println(metadict) } else { profileDict := v.(map[string]any) if _, ok := profileDict["logo_selected"]; !ok { @@ -131,30 +131,30 @@ func TestMain(t *testing.T) { info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info") metadict["userinfo.profile.logo_selected"] = info } + } else { + var info map[string]any + for k, v := range metadict { + if v == nil { + if strings.HasPrefix(k, "userinfo.profile.logo_selected") { + if info == nil { + info = QueryDefault(conn, "profile", "logo_selected", "fs_user_info") + } + + curValue, err := GetMapValueByKey(info, strings.Split(k, ".")[2:]) + if err != nil { + logx.Error(err, info) + continue + // return resp.SetStatus(basic.CodeOK, metadict) + } + metadict[k] = curValue + // curValue + } + } + } } } -func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any { - - qname := strings.Split(moduleQuery, ".") - queryAsName := qname[len(qname)-1] - sqlstr := fmt.Sprintf( - "select JSON_EXTRACT(metadata,'$.%s') as %s from %s where module = '%s' and user_id = 0 and guest_id = 0 order by ctime DESC limit 1", - moduleQuery, // logo_selected - queryAsName, // logo_selected - tname, // fs_user_info - module, // profile - ) - raw := conn.Raw(sqlstr) - var info map[string]any - err := raw.Scan(&info).Error - if err == gorm.ErrRecordNotFound { - logx.Error(err) - } - return info -} - func TestCaseJSON_EXTRACT(t *testing.T) { userProfile := &gmodel.UserProfile{