From 330eda9f9b1d40a7b0adffd094c951c05a6b7544 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 18:43:36 +0800 Subject: [PATCH 1/3] fix --- server/websocket/internal/logic/ws_render_image.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index fdab6ff7..f1a9e67d 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -133,11 +133,11 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindFirstOneCloudRenderByProductIdModelIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, model3dInfo.Id, renderImageData.RenderData.TemplateTag) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product template is not exists", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product template is not exists", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, 0) logx.Error("template info is not found") return } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product template", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product template", w.userId, w.guestId, 0, model3dInfo.Id, productFirstSize.Id, 0) logx.Error("failed to get template info:", err) return } From 72a26c07f28163b483da31b120b005cb7a590af8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 28 Aug 2023 19:00:08 +0800 Subject: [PATCH 2/3] fix --- .../internal/logic/ws_render_image.go | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index f1a9e67d..d211228a 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -29,7 +29,6 @@ type extendRenderProperty struct { type renderImageControlChanItem struct { option int // 0删除 1添加 2修改耗时属性 taskId string //map的key(必须传) - combineImage string //刀版图地址(增加任务时候传) renderId string // map的val(增加任务时候传) renderNotifyImageUrl string //渲染回调数据(删除任务时候传) taskProperty renderTask //渲染任务的属性 @@ -37,7 +36,8 @@ type renderImageControlChanItem struct { // 渲染任务属性 type renderTask struct { - renderId string //渲染id(前端传的) + renderId string //渲染id(新增任务传) + combineImage string //刀版图(新增任务传) combineTakesTime int64 //合刀版图耗时 uploadCombineImageTakesTime int64 //上传刀版图耗时 unityRenderBeginTime int64 //发送给unity时间 @@ -218,10 +218,12 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { //########################################### //把需要渲染的图片任务加进去 w.createRenderTask(renderImageControlChanItem{ - option: 1, //0删除 1添加 2修改耗时属性 - taskId: taskId, - renderId: renderImageData.RenderId, - combineImage: combineImage, + option: 1, //0删除 1添加 2修改耗时属性 + taskId: taskId, + renderId: renderImageData.RenderId, + taskProperty: renderTask{ + combineImage: combineImage, + }, }) //组装数据 if err = w.assembleRenderData(taskId, combineImage, renderImageData, productTemplate, model3dInfo, element, productFirstSize); err != nil { @@ -448,7 +450,7 @@ func (w *wsConnectItem) operationRenderTask() { w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ RenderId: taskData.renderId, Image: data.renderNotifyImageUrl, - CombineImage: data.combineImage, + CombineImage: data.taskProperty.combineImage, RenderProcessTime: websocket_data.RenderProcessTime{ CombineTakesTime: CombineTakesTime, UnityRenderTakesTime: UnityRenderTakesTime, @@ -461,8 +463,10 @@ func (w *wsConnectItem) operationRenderTask() { delete(w.extendRenderProperty.renderImageTask, data.taskId) case 1: //新增任务 w.extendRenderProperty.renderImageTask[data.taskId] = &renderTask{ - renderId: data.renderId, + renderId: data.renderId, + combineImage: data.taskProperty.combineImage, } + case 2: //修改(耗时)属性 if taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]; ok { //合图耗时 From 458202ba6e6c634f2f9adbc152601517a777a11b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 29 Aug 2023 10:21:11 +0800 Subject: [PATCH 3/3] fix --- model/gmodel/fs_product_template_v2_logic.go | 2 +- .../internal/logic/ws_render_image.go | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 5a51fd2a..e7d32a40 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -117,7 +117,7 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co func (t *FsProductTemplateV2Model) FindFirstOneCloudRenderByProductIdModelIdTemplateTag(ctx context.Context, productId, modelId int64, templateTag string) (resp *FsProductTemplateV2, err error) { err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). Where("product_id = ? and model_id = ? and template_tag = ? ", productId, modelId, templateTag). - Where("status = ? and is_del = ? and element_model_id != ?", 1, 0, 0). + Where("status = ? and is_del = ? ", 1, 0). Order("sort ASC"). Take(&resp).Error return resp, err diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index d211228a..3d513aab 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -59,6 +59,11 @@ func (w *wsConnectItem) sendToRenderChan(data []byte) { // 渲染发送到组装数据组装数据(缓冲队列) func (w *wsConnectItem) renderImage() { + defer func() { + if err := recover(); err != nil { + logx.Error("func renderImage err:", err) + } + }() for { select { case <-w.closeChan: //已关闭 @@ -142,14 +147,14 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { return } //获取渲染设置信息 - element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ElementModelId) + element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ModelId) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "render element is not exists", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) - logx.Error("element info is not found,element_model_id = ", *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "render element is not exists", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) + logx.Error("element info is not found,element_model_id = ", 0) return } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get render element", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get render element", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) logx.Error("failed to get element ,", err) return } @@ -166,7 +171,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { } res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) if err != nil { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to combine image:"+err.Error(), w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to combine image:"+err.Error(), w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err) return } @@ -174,7 +179,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { if res != nil && res.ResourceUrl != nil { combineImage = *res.ResourceUrl } else { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "combine image is empty", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "combine image is empty", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) logx.Error("合成刀版图失败,合成的刀版图是空指针:", err) return } @@ -194,7 +199,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, taskId, "failed to get render cache", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, taskId, "failed to get render cache", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) logx.Error("failed to find render resource:", err) return } @@ -266,7 +271,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, i refletion, err = strconv.Atoi(*element.Refletion) if err != nil { logx.Error("err refletion:set default -1") - w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Refletion from string to number err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Refletion from string to number err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) return err } } @@ -275,7 +280,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, i if element.Mode != nil && *element.Mode != "" { if err = json.Unmarshal([]byte(*element.Mode), &mode); err != nil { logx.Error("faile to parse element mode json:", err) - w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Mode err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Mode err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) return err } } @@ -348,7 +353,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, combineImage string, i unityRenderBeginTime := time.Now().UTC().UnixMilli() _, err = curl.ApiCall(url, "POST", header, bytes.NewReader(postDataBytes), time.Second*10) if err != nil { - w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productFirstSize.Id, 0) logx.Error("failed to send data to unity") return err }