From 37d824a7d9e3f5f605535ca469b062e1373ac2c3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 30 Aug 2023 14:32:44 +0800 Subject: [PATCH] 1 --- .../internal/logic/ws_err_response.go | 3 +- .../internal/logic/ws_render_image.go | 34 +++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/server/websocket/internal/logic/ws_err_response.go b/server/websocket/internal/logic/ws_err_response.go index 2523aada..51db1b1b 100644 --- a/server/websocket/internal/logic/ws_err_response.go +++ b/server/websocket/internal/logic/ws_err_response.go @@ -8,11 +8,12 @@ func (w *wsConnectItem) incomeDataFormatErrResponse(data interface{}) { } // 渲染错误通知 -func (w *wsConnectItem) renderErrResponse(renderId, templateTag, taskId, description string, userId, guestId, templateId, modelId, sizeId, elementModelId int64) { +func (w *wsConnectItem) renderErrResponse(renderId, templateTag, taskId, description string, productId, userId, guestId, templateId, modelId, sizeId, elementModelId int64) { data := make(map[string]interface{}) data["render_id"] = renderId data["description"] = description data["template_tag"] = templateTag + data["product_id"] = productId if taskId != "" { data["task_id"] = taskId } diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 47923597..887dc2e7 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -87,7 +87,7 @@ func (w *wsConnectItem) renderImage(data []byte) { userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.ctx, w.userId, w.guestId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get user logo", w.userId, w.guestId, 0, 0, 0, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get user logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) logx.Error("failed to get user logo") return } @@ -95,10 +95,10 @@ func (w *wsConnectItem) renderImage(data []byte) { userMaterialDefault, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindOneById(w.logic.ctx, 0) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "default logo is not exists", w.userId, w.guestId, 0, 0, 0, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "default logo is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get default logo", w.userId, w.guestId, 0, 0, 0, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get default logo", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) logx.Error("default logo is not exists") return } @@ -118,11 +118,11 @@ func (w *wsConnectItem) renderImage(data []byte) { } if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product first size is not exists", w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product first size is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0) logx.Error("product size is not found") return } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product first size", w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product first size", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0) logx.Error("failed to get product size:", err) return } @@ -130,11 +130,11 @@ func (w *wsConnectItem) renderImage(data []byte) { model3dInfo, err := w.logic.svcCtx.AllModels.FsProductModel3d.GetOneBySizeIdTag(w.logic.ctx, productSize.Id, constants.TAG_MODEL, "id") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product model is not exists", w.userId, w.guestId, 0, 0, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product model is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0) logx.Error("product model is not found") return } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product model", w.userId, w.guestId, 0, 0, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product model", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0) logx.Error("failed to get product model:", err) return } @@ -142,11 +142,11 @@ func (w *wsConnectItem) renderImage(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, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "product template is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3dInfo.Id, productSize.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, productSize.Id, 0) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get product template", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3dInfo.Id, productSize.Id, 0) logx.Error("failed to get template info:", err) return } @@ -154,11 +154,11 @@ func (w *wsConnectItem) renderImage(data []byte) { element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ElementModelId) 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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "render element is not exists", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) 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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to get render element", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) logx.Error("failed to get element ,", err) return } @@ -177,7 +177,7 @@ func (w *wsConnectItem) renderImage(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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "failed to combine image:"+err.Error(), renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) logx.Error("合成刀版图失败,合成请求数据:", combineReq, "错误信息:", err) return } @@ -185,7 +185,7 @@ func (w *wsConnectItem) renderImage(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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "combine image is empty", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) logx.Error("合成刀版图失败,合成的刀版图是空指针:", err) return } @@ -209,7 +209,7 @@ func (w *wsConnectItem) renderImage(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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, taskId, "failed to get render cache", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) logx.Error("failed to find render resource:", err) return } @@ -260,7 +260,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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Refletion from string to number err", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) return err } } @@ -269,7 +269,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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "parse element.Mode err", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) return err } } @@ -342,7 +342,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, productSize.Id, *productTemplate.ElementModelId) + w.renderErrResponse(info.RenderId, info.RenderData.TemplateTag, taskId, "request unity api err", info.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3dInfo.Id, productSize.Id, *productTemplate.ElementModelId) logx.Error("failed to send data to unity") return err }