This commit is contained in:
laodaming 2023-11-13 10:35:51 +08:00
parent 7004812acf
commit 8c09cf7635
6 changed files with 21 additions and 17 deletions

View File

@ -1,10 +1,6 @@
package handler package handler
import ( import (
"encoding/json"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"io"
"net/http" "net/http"
"reflect" "reflect"
@ -17,11 +13,6 @@ import (
func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func RenderNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
b,_ := io.ReadAll(r.Body)
var c map[string]interface{}
_ = json.Unmarshal(b,&c)
c["image"] = nil
logx.Info(fmt.Sprintf("回调渲染数据:%+v",c))
var req types.RenderNotifyReq var req types.RenderNotifyReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req) userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil { if err != nil {

View File

@ -94,6 +94,14 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image") return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "failed to upload render resource image")
} }
uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime uploadUnityRenderImageTakesTime := time.Now().UTC().UnixMilli() - unityRenderEndTime
//转换unity真实处理时间
duration, err := time.Parse("15:04:05.9999999", req.CostTime)
if err != nil {
fmt.Println("解析时间错误:", err)
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "转换unity时间错误")
}
// 将时间对象转换为毫秒数
unityRealTakesTime := duration.Nanosecond() / 1e6 + duration.Second()*1000 + duration.Minute() * 6000 + duration.Hour()*3600000
if ws.conn != nil { if ws.conn != nil {
//发送到出口 //发送到出口
ws.sendRenderResultData(websocket_data.RenderImageRspMsg{ ws.sendRenderResultData(websocket_data.RenderImageRspMsg{
@ -102,6 +110,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
RenderProcessTime: &websocket_data.RenderProcessTime{ RenderProcessTime: &websocket_data.RenderProcessTime{
UnityRenderTakesTime: fmt.Sprintf("%dms", unityRenderEndTime-unityRenderBeginTime), UnityRenderTakesTime: fmt.Sprintf("%dms", unityRenderEndTime-unityRenderBeginTime),
UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime), UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime),
UnityTakesTime: fmt.Sprintf("%dms",unityRealTakesTime),
}, },
}) })
logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl) logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl)

View File

@ -273,6 +273,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
RenderProcessTime: &websocket_data.RenderProcessTime{ RenderProcessTime: &websocket_data.RenderProcessTime{
UnityRenderTakesTime: "cache", UnityRenderTakesTime: "cache",
UploadUnityRenderImageTakesTime: "cache", UploadUnityRenderImageTakesTime: "cache",
UnityTakesTime: "cache",
}, },
}) })
return return

View File

@ -14,6 +14,7 @@ type RenderNotifyReq struct {
Image string `json:"image"` Image string `json:"image"`
Code int `json:"code,optional"` Code int `json:"code,optional"`
Msg string `json:"msg,optional"` Msg string `json:"msg,optional"`
CostTime string `json:"cost_time"` //unity处理时间
} }
type CommonNotifyReq struct { type CommonNotifyReq struct {

View File

@ -33,6 +33,7 @@ type RenderNotifyReq {
Image string `json:"image"` Image string `json:"image"`
Code int `json:"code,optional"` Code int `json:"code,optional"`
Msg string `json:"msg,optional"` Msg string `json:"msg,optional"`
CostTime string `json:"cost_time"` //unity处理时间
} }
//通用回调接口 //通用回调接口
type CommonNotifyReq { type CommonNotifyReq {

View File

@ -35,6 +35,7 @@ type RenderImageRspMsg struct {
type RenderProcessTime struct { type RenderProcessTime struct {
UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时 UnityRenderTakesTime string `json:"unity_render_takes_time"` //unity渲染用时
UploadUnityRenderImageTakesTime string `json:"upload_unity_render_image_takes_time"` //上传unity渲染结果图时间 UploadUnityRenderImageTakesTime string `json:"upload_unity_render_image_takes_time"` //上传unity渲染结果图时间
UnityTakesTime string `json:"unity_takes_time"` //unity真实处理时间
} }
// 合图返回数据 // 合图返回数据