diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index f8484ecd..da3f384f 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -110,17 +110,8 @@ func (w *wsConnectItem) renderImage(data []byte) { //用户id赋值 renderImageData.RenderData.UserId = w.userId renderImageData.RenderData.GuestId = w.guestId - var ( - model3dInfo *gmodel.FsProductModel3d - productTemplate *gmodel.FsProductTemplateV2 - productSize *gmodel.FsProductSize - ) //获取信息 - if renderImageData.RenderData.ProductSizeId > 0 { - productSize, productTemplate, model3dInfo, err = w.getProductRelateionInfoWithSizeId(&renderImageData) - } else { - productSize, productTemplate, model3dInfo, err = w.getProductRelateionInfoWithNoSizeId(&renderImageData) - } + productSize, productTemplate, model3dInfo, err := w.getProductRelateionInfo(&renderImageData) if err != nil { logx.Error(err) return @@ -190,11 +181,6 @@ func (w *wsConnectItem) renderImage(data []byte) { } //发送合图完毕阶段消息 w.sendCombineImageStepResponseMessage(renderImageData.RenderId, combineImage, productSize.Id, model3dInfo.Id, productTemplate.Id, res.DiffTimeLogoCombine, res.DiffTimeUploadFile) - //如果指定指定只返回刀版图 - if renderImageData.OnlyReturnCombineImage { - logx.Info("云渲染传入only_return_combine_image = true则不走unity云渲染,只返回刀版图,render_id:", renderImageData.RenderId) - return - } //获取唯一id taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element) //查询有没有缓存的资源,有就返回 @@ -224,57 +210,8 @@ func (w *wsConnectItem) renderImage(data []byte) { } } -// 获取模板相关信息(指定尺寸)(尺寸 -> 模型 ->模板) -func (w *wsConnectItem) getProductRelateionInfoWithSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) { - productSize, err = w.logic.svcCtx.AllModels.FsProductSize.FindOneByIdProductId(w.logic.ctx, renderImageData.RenderData.ProductSizeId, renderImageData.RenderData.ProductId) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到产品的指定尺寸", 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, "", "获取产品的指定尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0) - logx.Error("failed to get product size:", err) - return nil, nil, nil, err - } - //获取模型 - model3d, err = w.logic.svcCtx.AllModels.FsProductModel3d.GetOneBySizeIdTag(w.logic.ctx, productSize.Id, constants.TAG_MODEL) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "产品尺寸对应的模型不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0) - logx.Error("product model is not found") - return nil, nil, nil, err - } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品尺寸对应的模型失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, productSize.Id, 0) - logx.Error("failed to get product model:", err) - return nil, nil, nil, err - } - //获取模板 - productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdModelIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, model3d.Id, renderImageData.RenderData.TemplateTag) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) - logx.Error("找不到对应的模板") - return nil, nil, nil, err - } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应的模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0) - logx.Error("获取对应的模板失败:", err) - return nil, nil, nil, err - } - if *productTemplate.ElementModelId <= 0 { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "模板未开启云渲染", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) - return nil, nil, nil, errors.New("模板未开启云渲染") - } - if productTemplate.TemplateInfo == nil || *productTemplate.TemplateInfo == "" { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "渲染模板的设计信息是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, productSize.Id, 0) - return nil, nil, nil, errors.New("渲染模板的设计信息是空的") - } - return -} - -// 获取模板相关信息(不指定尺寸) -func (w *wsConnectItem) getProductRelateionInfoWithNoSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) { - //指定尺寸(尺寸 -> 模型 ->模板) +// 获取模板相关信息 +func (w *wsConnectItem) getProductRelateionInfo(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 { @@ -308,7 +245,6 @@ func (w *wsConnectItem) getProductRelateionInfoWithNoSizeId(renderImageData *web w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, 0, 0) return nil, nil, nil, errors.New("获取对应尺寸失败") } - renderImageData.RenderData.ProductSizeId = productSize.Id return } diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index c65b2eda..a99774a0 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -10,9 +10,8 @@ type DataTransferData struct { // websocket接受要云渲染处理的数据 type RenderImageReqMsg struct { - RenderId string `json:"render_id"` //渲染id - OnlyReturnCombineImage bool `json:"only_return_combine_image"` //是否只返回刀版图 - RenderData RenderData `json:"render_data"` + RenderId string `json:"render_id"` //渲染id + RenderData RenderData `json:"render_data"` //渲染主要参数 } type RenderData struct { TemplateTag string `json:"template_tag"` //模板标签(必须) @@ -25,7 +24,6 @@ type RenderData struct { Address string `json:"address"` //地址(可选) Phone string `json:"phone"` //电话(可选) Qrcode string `json:"qrcode"` //二维码(可选) - ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) }