From 0001ea89f210acd32fcf817184b3fa6aa3afa709 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 22 Aug 2023 17:12:30 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_size_logic.go | 10 +++++++ model/gmodel/fs_product_template_v2_logic.go | 13 ++++---- .../internal/logic/ws_render_image_logic.go | 30 +++++++++++++++++-- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/model/gmodel/fs_product_size_logic.go b/model/gmodel/fs_product_size_logic.go index 351fa22e..d0a71343 100755 --- a/model/gmodel/fs_product_size_logic.go +++ b/model/gmodel/fs_product_size_logic.go @@ -99,3 +99,13 @@ func (s *FsProductSizeModel) GetAllByStatus(ctx context.Context, status int64, s err = db.Find(&resp).Error return resp, err } + +// 获取第一个尺寸 +func (s *FsProductSizeModel) GetProductFirstSize(ctx context.Context, productId int64) (resp *FsProductTemplateV2, err error) { + err = s.db.WithContext(ctx).Model(&FsProductSize{}). + Select("product_id,count(*) as num"). + Where("`product_id` = ? and `status` = ?", productId, 1). + Order("sort ASC"). + Take(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 40e8a6bc..40067f96 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -114,14 +114,11 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co } // 获取第一个尺寸下的模板 -func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx context.Context, productId int64, templateTag string) (resp *FsProductTemplateV2, err error) { - err = t.db.WithContext(ctx).Table(t.name+" as t"). - Joins("inner join fs_product_size as s on t.product_id = s.product_id"). - Select("t.*"). - Where("t.product_id = ? and t.template_tag = ? ", productId, templateTag). - Where("t.status = ? and t.is_del = ?", 1, 0). - Where("s.status = ?", 1). - Order("t.sort ASC,s.sort ASC"). +func (t *FsProductTemplateV2Model) FindFirstOneByProductIdModelIdTemplateTag(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 = ?", 1, 0). + Order("sort ASC"). Take(&resp).Error return resp, err } diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index d36afa37..39829dd6 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -169,13 +169,39 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re logx.Error("assembleRenderData panic:", err) } }() - //获取模板 - productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.logic.ctx, info.RenderData.ProductId, info.RenderData.TemplateTag) + //获取产品第一个尺寸 + productFirstSize, err := w.logic.svcCtx.AllModels.FsProductSize.GetProductFirstSize(w.logic.ctx, info.RenderData.ProductId) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, fmt.Sprintf("没有尺寸 product_id:%d ", info.RenderData.ProductId))) + logx.Error("product first size is not found") + return err + } + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, fmt.Sprintf("获取尺寸错误 product_id:%d ", info.RenderData.ProductId))) + logx.Error("failed to get product first size:", err) + return err + } + //获取模型(只是获取id) + model3dInfo, err := w.logic.svcCtx.AllModels.FsProductModel3d.GetOneBySizeIdTag(w.logic.ctx, productFirstSize.Id, constants.TAG_MODEL, "id") + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, fmt.Sprintf("没有模型 product_id:%d , size_id:%d ", info.RenderData.ProductId, model3dInfo.Id))) + logx.Error("product model is not found") + return err + } + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, fmt.Sprintf("获取模型错误 product_id:%d , size_id:%d ", info.RenderData.ProductId, model3dInfo.Id))) + logx.Error("failed to get product model:", err) + return err + } + //获取模板 + productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindFirstOneByProductIdModelIdTemplateTag(w.logic.ctx, info.RenderData.ProductId, model3dInfo.Id, info.RenderData.TemplateTag) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, fmt.Sprintf("模板未找到 product_id:%d , model_id:%d ,template_tag:%s", info.RenderData.ProductId, model3dInfo.Id, info.RenderData.TemplateTag))) logx.Error("template info is not found") return err } + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, fmt.Sprintf("获取模板错误 product_id:%d , model_id:%d ,template_tag:%s", info.RenderData.ProductId, model3dInfo.Id, info.RenderData.TemplateTag))) logx.Error("failed to get template info:", err) return err }