info
This commit is contained in:
parent
b6e994844e
commit
173fa23e80
|
@ -99,6 +99,18 @@ func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string
|
||||||
if err == gorm.ErrRecordNotFound {
|
if err == gorm.ErrRecordNotFound {
|
||||||
logx.Error(err)
|
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
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,9 +115,9 @@ func TestMain(t *testing.T) {
|
||||||
if v, ok := metadict["userinfo.profile"]; ok {
|
if v, ok := metadict["userinfo.profile"]; ok {
|
||||||
|
|
||||||
if v == nil {
|
if v == nil {
|
||||||
|
|
||||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||||
metadict["userinfo.profile"] = info
|
metadict["userinfo.profile"] = info
|
||||||
// log.Println(metadict)
|
|
||||||
} else {
|
} else {
|
||||||
profileDict := v.(map[string]any)
|
profileDict := v.(map[string]any)
|
||||||
if _, ok := profileDict["logo_selected"]; !ok {
|
if _, ok := profileDict["logo_selected"]; !ok {
|
||||||
|
@ -131,30 +131,30 @@ func TestMain(t *testing.T) {
|
||||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||||
metadict["userinfo.profile.logo_selected"] = 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) {
|
func TestCaseJSON_EXTRACT(t *testing.T) {
|
||||||
|
|
||||||
userProfile := &gmodel.UserProfile{
|
userProfile := &gmodel.UserProfile{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user