Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
9573286e7f
|
@ -1,35 +0,0 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/websocket/internal/logic"
|
||||
"fusenapi/server/websocket/internal/svc"
|
||||
"fusenapi/server/websocket/internal/types"
|
||||
)
|
||||
|
||||
func CloseWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.CloseWebsocketReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewCloseWebsocketLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.CloseWebsocket(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,11 +27,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/websocket/common_notify",
|
||||
Handler: CommonNotifyHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/websocket/close_websocket",
|
||||
Handler: CloseWebsocketHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/websocket/get_stat",
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/websocket/internal/svc"
|
||||
"fusenapi/server/websocket/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CloseWebsocketLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCloseWebsocketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CloseWebsocketLogic {
|
||||
return &CloseWebsocketLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *CloseWebsocketLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *CloseWebsocketLogic) CloseWebsocket(req *types.CloseWebsocketReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
//获取连接
|
||||
value, ok := mapConnPool.Load(req.Wid)
|
||||
if !ok {
|
||||
return resp.SetStatusAddMessage(basic.CodeRequestParamsErr, "wid connection is not exists")
|
||||
}
|
||||
ws, ok := value.(wsConnectItem)
|
||||
if !ok {
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "渲染回调断言websocket连接失败")
|
||||
}
|
||||
ws.close()
|
||||
return resp.SetStatus(basic.CodeOK, "断开成功")
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *CloseWebsocketLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -51,8 +51,14 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) (
|
|||
}
|
||||
}
|
||||
} else { //不指定用户
|
||||
i := 0
|
||||
mapUserWsStat.Range(func(key, value any) bool {
|
||||
//不指定最多获取1000个用户
|
||||
if i > 1000 {
|
||||
return false
|
||||
}
|
||||
userStat[key.(string)] = value
|
||||
i++
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ func NewRenderNotifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Rend
|
|||
// }
|
||||
func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
unityRenderEndTime := time.Now().UTC().UnixMilli()
|
||||
logx.Info("收到unity返回的渲染消息")
|
||||
//解析数据
|
||||
var info websocket_data.ToUnityIdStruct
|
||||
if err := json.Unmarshal([]byte(req.TaskId), &info); err != nil {
|
||||
|
@ -62,6 +63,10 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
|||
unityRenderBeginTime := info.RenderBeginTime
|
||||
//获取连接
|
||||
value, wsConnectOk := mapConnPool.Load(wid)
|
||||
var ws wsConnectItem
|
||||
if wsConnectOk {
|
||||
ws = value.(wsConnectItem)
|
||||
}
|
||||
if req.Code == 0 { //渲染成功
|
||||
//上传文件
|
||||
var upload = file.Upload{
|
||||
|
@ -82,16 +87,14 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
|||
})
|
||||
if err != nil {
|
||||
logx.Error("渲染回调上传文件失败:", err)
|
||||
if ws.conn != nil {
|
||||
//发送错误信息给前端
|
||||
ws.renderErrResponse(requestId, info.TemplateTag, info.TaskId, "unity图片上传错误", 0, 0, 0, 0, 0, 0, 0)
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
|
||||
}
|
||||
uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime
|
||||
if wsConnectOk {
|
||||
//断言连接
|
||||
ws, ok := value.(wsConnectItem)
|
||||
if !ok {
|
||||
logx.Error("渲染回调断言websocket连接失败")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "渲染回调断言websocket连接失败")
|
||||
}
|
||||
if ws.conn != nil {
|
||||
//发送到出口
|
||||
ws.sendRenderResultData(websocket_data.RenderImageRspMsg{
|
||||
RequestId: requestId,
|
||||
|
@ -108,16 +111,10 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
|
|||
return resp.SetStatusWithMessage(basic.CodeOK, "success:but websocket connect not found")
|
||||
}
|
||||
//渲染失败走下面
|
||||
if wsConnectOk {
|
||||
//断言连接
|
||||
ws, ok := value.(wsConnectItem)
|
||||
if !ok {
|
||||
logx.Error("渲染回调断言websocket连接失败")
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "渲染回调断言websocket连接失败")
|
||||
}
|
||||
if ws.conn != nil {
|
||||
//发送错误信息给前端
|
||||
ws.renderErrResponse(requestId, info.TemplateTag, info.TaskId, "unity云渲染错误:"+req.Msg, 0, 0, 0, 0, 0, 0, 0)
|
||||
logx.Info("渲染失败且发送了失败信息")
|
||||
logx.Info("渲染失败且发送了失败信息:", req.Msg)
|
||||
} else {
|
||||
logx.Info("渲染失败且找不到ws连接")
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func ConsumeCancelUnityChanMessage(conn *net.UDPConn) {
|
|||
d, _ := json.Marshal(data)
|
||||
_, err := conn.Write(d)
|
||||
if err != nil {
|
||||
logx.Error("发送udp包通知Unity失败:", err)
|
||||
//logx.Error("发送udp包通知Unity失败:", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
renderImageData.RenderData.UserId = w.userId
|
||||
renderImageData.RenderData.GuestId = w.guestId
|
||||
//获取信息
|
||||
productSize, productTemplate, model3dInfo, err := w.getProductRelateionInfo(&renderImageData)
|
||||
productSize, productTemplate, model3dInfo, err := w.getProductRelationInfo(&renderImageData)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
|
@ -281,7 +281,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
|||
}
|
||||
|
||||
// 获取模板相关信息
|
||||
func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
||||
func (w *wsConnectItem) getProductRelationInfo(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
||||
//获取模板
|
||||
productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag, "sort ASC")
|
||||
if err != nil {
|
||||
|
@ -421,7 +421,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, resolution int,
|
|||
header["content-type"] = "application/json"
|
||||
postData := map[string]interface{}{
|
||||
"group": "unity3d",
|
||||
"source": "home page",
|
||||
"source": "product list",
|
||||
"priority": 1,
|
||||
"create_at": time.Now().UTC(),
|
||||
"resolution": resolution,
|
||||
|
|
|
@ -23,10 +23,6 @@ type CommonNotifyReq struct {
|
|||
Data map[string]interface{} `json:"data"` //后端与前端约定好的数据
|
||||
}
|
||||
|
||||
type CloseWebsocketReq struct {
|
||||
Wid string `json:"wid"`
|
||||
}
|
||||
|
||||
type GetStatReq struct {
|
||||
Password string `form:"password"`
|
||||
UserKeys string `form:"user_keys,optional"`
|
||||
|
|
|
@ -18,9 +18,6 @@ service websocket {
|
|||
//通用回调接口
|
||||
@handler CommonNotifyHandler
|
||||
post /api/websocket/common_notify(CommonNotifyReq) returns (response);
|
||||
//关闭某个连接
|
||||
@handler CloseWebsocketHandler
|
||||
post /api/websocket/close_websocket(CloseWebsocketReq) returns (response);
|
||||
//获取ws统计信息
|
||||
@handler GetStatHandler
|
||||
get /api/websocket/get_stat(GetStatReq) returns (response);
|
||||
|
@ -44,10 +41,6 @@ type CommonNotifyReq {
|
|||
GuestId int64 `json:"guest_id,optional"` //游客id
|
||||
Data map[string]interface{} `json:"data"` //后端与前端约定好的数据
|
||||
}
|
||||
//关闭连接
|
||||
type CloseWebsocketReq {
|
||||
Wid string `json:"wid"`
|
||||
}
|
||||
//获取ws统计信息
|
||||
type GetStatReq {
|
||||
Password string `form:"password"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user