info
This commit is contained in:
parent
65a7d530cc
commit
c163cfe234
|
@ -6,6 +6,7 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/check"
|
"fusenapi/utils/check"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
@ -82,6 +83,26 @@ func (mquery *ModuleQuery) EncodeEmpty() map[string]any {
|
||||||
return qstr
|
return qstr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
// userinfo 传入值时, 一定不为null
|
// userinfo 传入值时, 一定不为null
|
||||||
|
@ -178,6 +199,29 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 隐含白板用户逻辑
|
||||||
|
if v, ok := metadict["userinfo.profile"]; ok {
|
||||||
|
|
||||||
|
if v == nil {
|
||||||
|
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
|
||||||
|
log.Println(info)
|
||||||
|
metadict["userinfo.profile"] = info
|
||||||
|
// log.Println(metadict)
|
||||||
|
} else {
|
||||||
|
profileDict := v.(map[string]any)
|
||||||
|
if _, ok := profileDict["logo_selected"]; !ok {
|
||||||
|
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
|
||||||
|
profileDict["logo_selected"] = info["logo_selected"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
|
||||||
|
if v == nil {
|
||||||
|
info := QueryDefault(l.svcCtx.MysqlConn, "profile", "logo_selected", "fs_user_info")
|
||||||
|
metadict["userinfo.profile.logo_selected"] = info
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK, metadict)
|
return resp.SetStatus(basic.CodeOK, metadict)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,9 +115,7 @@ 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")
|
||||||
log.Println(info)
|
|
||||||
metadict["userinfo.profile"] = info
|
metadict["userinfo.profile"] = info
|
||||||
// log.Println(metadict)
|
// log.Println(metadict)
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,19 +124,15 @@ func TestMain(t *testing.T) {
|
||||||
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||||
profileDict["logo_selected"] = info["logo_selected"]
|
profileDict["logo_selected"] = info["logo_selected"]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
|
} else if v, ok := metadict["userinfo.profile.logo_selected"]; ok {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
|
info := QueryDefault(conn, "profile", "logo_selected", "fs_user_info")
|
||||||
|
metadict["userinfo.profile.logo_selected"] = info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(metadict)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {
|
func QueryDefault(conn *gorm.DB, module string, moduleQuery string, tname string) map[string]any {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user