This commit is contained in:
laodaming 2023-10-08 17:04:37 +08:00
parent d2f24772ca
commit 4dce0d7087
5 changed files with 61 additions and 43 deletions

View File

@ -59,15 +59,13 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "failed to parse param taskId !!!!") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "failed to parse param taskId !!!!")
} }
//重新赋值(很重要) //重新赋值(很重要)
req.TaskId = info.TaskId
wid := info.Wid wid := info.Wid
renderId := info.RenderId renderId := info.RenderId
unityRenderBeginTime := info.RenderBeginTime unityRenderBeginTime := info.RenderBeginTime
//存base64打印测试 //获取连接
/* f, _ := os.Create("b.txt") value, wsConnectOk := mapConnPool.Load(wid)
defer f.Close() if req.Code == 0 { //渲染成功
f.WriteString(req.Image)*/ //上传文件
// 上传文件
var upload = file.Upload{ var upload = file.Upload{
Ctx: l.ctx, Ctx: l.ctx,
MysqlConn: l.svcCtx.MysqlConn, MysqlConn: l.svcCtx.MysqlConn,
@ -75,7 +73,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
} }
uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{ uploadRes, err := upload.UploadFileByBase64(&file.UploadBaseReq{
Source: "unity cloud render", Source: "unity cloud render",
FileHash: req.TaskId, FileHash: info.TaskId,
FileData: req.Image, FileData: req.Image,
Metadata: "", Metadata: "",
UploadBucket: 1, UploadBucket: 1,
@ -89,7 +87,7 @@ 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
if value, ok := mapConnPool.Load(wid); ok { if wsConnectOk {
//断言连接 //断言连接
ws, ok := value.(wsConnectItem) ws, ok := value.(wsConnectItem)
if !ok { if !ok {
@ -105,7 +103,21 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime), UploadUnityRenderImageTakesTime: fmt.Sprintf("%dms", uploadUnityRenderImageTakesTime),
}, },
}) })
}
logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl) logx.Info("渲染回调成功,渲染结果图片为:", uploadRes.ResourceUrl)
return resp.SetStatusWithMessage(basic.CodeOK, "success") return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
return resp.SetStatusWithMessage(basic.CodeOK, "successbut websocket connect not found")
}
//渲染失败走下面
if wsConnectOk {
//断言连接
ws, ok := value.(wsConnectItem)
if !ok {
logx.Error("渲染回调断言websocket连接失败")
return resp.SetStatusWithMessage(basic.CodeFileUploadErr, "渲染回调断言websocket连接失败")
}
//发送错误信息给前端
ws.renderErrResponse(renderId, info.TemplateTag, info.TaskId, "unity错误:"+req.Msg, 0, 0, 0, 0, 0, 0, 0)
}
return resp.SetStatusWithMessage(basic.CodeOK, "success")
} }

View File

@ -372,6 +372,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
Wid: w.uniqueId, Wid: w.uniqueId,
RenderId: info.RenderId, RenderId: info.RenderId,
RenderBeginTime: time.Now().UTC().UnixMilli(), RenderBeginTime: time.Now().UTC().UnixMilli(),
TemplateTag: info.RenderData.TemplateTag,
} }
temIdBytes, _ := json.Marshal(temId) temIdBytes, _ := json.Marshal(temId)
sendData := map[string]interface{}{ sendData := map[string]interface{}{

View File

@ -6,14 +6,16 @@ import (
) )
type RenderNotifyReq struct { type RenderNotifyReq struct {
TaskId string `json:"task_id"` //任务id + " " + wid的结合字符串 TaskId string `json:"task_id"`
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"` GuestId int64 `json:"guest_id"`
Image string `json:"image"` Image string `json:"image"`
Code int `json:"code,optional"`
Msg string `json:"msg,optional"`
} }
type CommonNotifyReq struct { type CommonNotifyReq struct {
Wid string `json:"wid,optional"` //websocket连接标识 Wid string `json:"wid,optional"` //websocket连接标识(找ws连接优先级高于user_id和guestid)
UserId int64 `json:"user_id,optional"` //用户id UserId int64 `json:"user_id,optional"` //用户id
GuestId int64 `json:"guest_id,optional"` //游客id GuestId int64 `json:"guest_id,optional"` //游客id
Data map[string]interface{} `json:"data"` //后端与前端约定好的数据 Data map[string]interface{} `json:"data"` //后端与前端约定好的数据
@ -42,10 +44,10 @@ type File struct {
} }
type Meta struct { type Meta struct {
TotalCount int64 `json:"totalCount"` TotalCount int64 `json:"total_count"`
PageCount int64 `json:"pageCount"` PageCount int64 `json:"page_count"`
CurrentPage int `json:"currentPage"` CurrentPage int `json:"current_page"`
PerPage int `json:"perPage"` PerPage int `json:"per_page"`
} }
// Set 设置Response的Code和Message值 // Set 设置Response的Code和Message值

View File

@ -26,6 +26,8 @@ type RenderNotifyReq {
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
GuestId int64 `json:"guest_id"` GuestId int64 `json:"guest_id"`
Image string `json:"image"` Image string `json:"image"`
Code int `json:"code,optional"`
Msg string `json:"msg,optional"`
} }
//通用回调接口 //通用回调接口
type CommonNotifyReq { type CommonNotifyReq {

View File

@ -74,4 +74,5 @@ type ToUnityIdStruct struct {
Wid string `json:"wid"` Wid string `json:"wid"`
RenderId string `json:"render_id"` RenderId string `json:"render_id"`
RenderBeginTime int64 `json:"render_begin_time"` RenderBeginTime int64 `json:"render_begin_time"`
TemplateTag string `json:"template_tag"`
} }