fix
This commit is contained in:
parent
4d443e9cc3
commit
4ddf97b475
|
@ -42,15 +42,30 @@ var ModuleTable map[string]string = map[string]string{
|
|||
}
|
||||
|
||||
type InfoType struct {
|
||||
Id int64 `json:"id"`
|
||||
Module string `json:"module"`
|
||||
Metadata string `json:"metadata"`
|
||||
Id int64 `json:"id"`
|
||||
Module string `json:"module"`
|
||||
QueryData string `json:"querydata"`
|
||||
// CreateAt time.Time `json:"ctime"`
|
||||
}
|
||||
|
||||
type ModuleQuery struct {
|
||||
ModuleName string
|
||||
ModuleQuery string
|
||||
ModuleQuery map[string]struct{}
|
||||
}
|
||||
|
||||
func (mquery *ModuleQuery) EncodeQuery(field string) string {
|
||||
var qstr []byte = []byte("JSON_OBJECT(")
|
||||
|
||||
for query := range mquery.ModuleQuery {
|
||||
qstr = append(qstr, []byte(fmt.Sprintf("'%s.%s', %s ->> %s,", mquery.ModuleName, query, field, query))...)
|
||||
}
|
||||
if qstr[len(qstr)-1] == ',' {
|
||||
qstr[len(qstr)-1] = ')'
|
||||
} else {
|
||||
qstr = append(qstr, ')')
|
||||
}
|
||||
|
||||
return string(qstr)
|
||||
}
|
||||
|
||||
func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
|
@ -67,7 +82,7 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
|||
cond = "user_id = 0 and guest_id = 0"
|
||||
}
|
||||
|
||||
var mquerys []*ModuleQuery
|
||||
var mquerys map[string]*ModuleQuery = make(map[string]*ModuleQuery)
|
||||
var metadict map[string]any = make(map[string]any)
|
||||
|
||||
for _, module := range req.Module {
|
||||
|
@ -86,13 +101,20 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
|||
return resp.SetStatusWithMessage(basic.CodeApiErr, fmt.Sprintf("%s format error, table %s not found", module, tname))
|
||||
}
|
||||
|
||||
mquerys = append(mquerys, &ModuleQuery{ModuleName: mtable, ModuleQuery: strings.Join(mlist[1:], ",")})
|
||||
if mquery, ok := mquerys[mtable]; ok {
|
||||
mquery.ModuleQuery[strings.Join(mlist[1:], ",")] = struct{}{}
|
||||
} else {
|
||||
mquery := &ModuleQuery{
|
||||
ModuleName: mtable,
|
||||
ModuleQuery: map[string]struct{}{strings.Join(mlist[1:], ","): {}}}
|
||||
mquerys[mtable] = mquery
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, mquery := range mquerys {
|
||||
|
||||
sqlstr := fmt.Sprintf("select id, module, metadata from %s where %s ", mquery.ModuleName, cond)
|
||||
sqlstr := fmt.Sprintf("select id, module, %s as querydata from %s where %s ", mquery.EncodeQuery("metadata"), mquery.ModuleName, cond)
|
||||
var info InfoType
|
||||
err := l.svcCtx.MysqlConn.Raw(sqlstr).Scan(&info).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
|
@ -104,13 +126,16 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
|||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||
}
|
||||
|
||||
var metadata map[string]any = make(map[string]any)
|
||||
err = json.Unmarshal([]byte(info.Metadata), &metadata)
|
||||
var querydata map[string]any = make(map[string]any)
|
||||
err = json.Unmarshal([]byte(info.QueryData), &querydata)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
|
||||
}
|
||||
metadict[info.Module] = metadata
|
||||
|
||||
for k, v := range querydata {
|
||||
metadict[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, metadict)
|
||||
|
|
Loading…
Reference in New Issue
Block a user