Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/check"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
@@ -100,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
|
||||
}
|
||||
|
||||
@@ -203,10 +214,9 @@ 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 {
|
||||
@@ -220,11 +230,50 @@ func (l *InfoLogic) Info(req *types.UserInfoRequest, userinfo *auth.UserInfo) (r
|
||||
info := QueryDefault(l.svcCtx.MysqlConn, "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(l.svcCtx.MysqlConn, "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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, metadict)
|
||||
}
|
||||
|
||||
func GetMapValueByKey(info map[string]interface{}, keys []string) (interface{}, error) {
|
||||
// keys := strings.Split(key, ".")[2:]
|
||||
|
||||
for _, k := range keys {
|
||||
if cur, ok := info[k]; ok {
|
||||
if curMap, ok := cur.(map[string]interface{}); ok {
|
||||
info = curMap
|
||||
} else {
|
||||
// logx.Error(cur)
|
||||
return cur, nil
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("info keys is not exists %#v", keys)
|
||||
}
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *InfoLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
|
||||
@@ -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,37 +131,33 @@ 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{
|
||||
FirstName: "FirstName",
|
||||
LastName: "LastName",
|
||||
Resetaurant: "Resetaurant",
|
||||
}
|
||||
userProfile := &gmodel.UserProfile{}
|
||||
metadata, err := json.Marshal(userProfile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -67,9 +67,9 @@ var (
|
||||
//websocket连接存储
|
||||
mapConnPool = sync.Map{}
|
||||
//每个websocket连接入口缓冲队列长度默认值
|
||||
websocketInChanLen = 1000
|
||||
websocketInChanLen = 2000
|
||||
//每个websocket连接出口缓冲队列长度默认值
|
||||
websocketOutChanLen = 1000
|
||||
websocketOutChanLen = 2000
|
||||
//是否开启debug
|
||||
openDebug = true
|
||||
//允许跨域的origin
|
||||
|
||||
@@ -23,7 +23,7 @@ var (
|
||||
//每个websocket渲染任务缓冲队列长度默认值
|
||||
renderChanLen = 500
|
||||
//每个websocket渲染并发数
|
||||
renderChanConcurrency = 100
|
||||
renderChanConcurrency = 1
|
||||
)
|
||||
|
||||
// 渲染处理器
|
||||
@@ -37,7 +37,7 @@ type extendRenderProperty struct {
|
||||
|
||||
// 处理分发到这里的数据
|
||||
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||
//logx.Info("开始处理渲染任务消息:", string(data))
|
||||
logx.Info("收到渲染任务消息")
|
||||
var renderImageData websocket_data.RenderImageReqMsg
|
||||
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "数据格式错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
@@ -49,6 +49,9 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||
return
|
||||
case w.extendRenderProperty.renderChan <- renderImageData: //发入到缓冲队列
|
||||
return
|
||||
case <-time.After(time.Millisecond * 50): //超过50毫秒丢弃
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染队列溢出,请稍后再发", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +59,7 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||
func (w *wsConnectItem) consumeRenderImageData() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("func consumeRenderImageData err:", err)
|
||||
logx.Error("func consumeRenderImageData panic:", err)
|
||||
}
|
||||
}()
|
||||
//限制并发
|
||||
@@ -67,11 +70,13 @@ func (w *wsConnectItem) consumeRenderImageData() {
|
||||
case <-w.closeChan: //已关闭
|
||||
return
|
||||
case data := <-w.extendRenderProperty.renderChan: //消费数据
|
||||
logx.Info("准备执行任务。。。。。")
|
||||
limitChan <- struct{}{}
|
||||
logx.Info("执行任务中。。。。。")
|
||||
go func(d websocket_data.RenderImageReqMsg) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logx.Error("func renderImage err:", err)
|
||||
logx.Error("func renderImage panic:", err)
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
@@ -202,6 +207,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
||||
logx.Error("failed to find render resource:", err)
|
||||
return
|
||||
}
|
||||
logx.Info("无缓存的渲染图,需要unity")
|
||||
} else {
|
||||
//返回给客户端
|
||||
w.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
||||
|
||||
Reference in New Issue
Block a user