From 1bb2e190a2b71037d74e27f83d26dcaa8e1395dd Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 27 Nov 2023 11:18:47 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_template_v2_logic.go | 16 ++++++++++++ .../internal/logic/getproductmodelslogic.go | 25 +++++++++++++++++-- server/product/internal/types/types.go | 3 ++- server_api/product.api | 3 ++- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 46e73745..5506950f 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -185,6 +185,22 @@ func (t *FsProductTemplateV2Model) FindAllByProductIdsTemplateTag(ctx context.Co err = db.Find(&resp).Error return resp, err } + +// 获取开启云渲染的模板列表 +func (t *FsProductTemplateV2Model) FindAllCloudRenderTemplateByProductIdsTemplateTag(ctx context.Context, productIds []int64, templateTag string, sort string, fields ...string) (resp []FsProductTemplateV2, err error) { + if len(productIds) == 0 { + return + } + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ? and `element_model_id` > ? ", productIds, templateTag, 0, 1, 0) + if sort != "" { + db = db.Order(sort) + } + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Find(&resp).Error + return resp, err +} func (t *FsProductTemplateV2Model) FindAllByFittingIds(ctx context.Context, fittingIds []int64, fields ...string) (resp []FsProductTemplateV2, err error) { db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in(?) and `status` = ? and `is_del` = ? ", fittingIds, 1, 0) if len(fields) != 0 { diff --git a/server/product/internal/logic/getproductmodelslogic.go b/server/product/internal/logic/getproductmodelslogic.go index 9c6ef437..eca954e3 100644 --- a/server/product/internal/logic/getproductmodelslogic.go +++ b/server/product/internal/logic/getproductmodelslogic.go @@ -57,12 +57,33 @@ func (l *GetProductModelsLogic) GetProductModels(req *types.GetProductModelsReq, if len(productList) != len(productIds) { return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "some one product is invalid") } - //获取产品所有的模型以及配件 - modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}) + //根据模板标签获取开启了云渲染的模板列表 + templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllCloudRenderTemplateByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "", "id,product_id,model_id") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list") + } + modelIds := make([]int64, 0, len(templateList)) + for _, v := range templateList { + modelIds = append(modelIds, *v.ModelId) + } + //获取模型列表 + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, modelIds, "") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list") } + partIds := make([]int64, 0, len(modelList)) + for _, v := range modelList { + if *v.PartId == 0 { + continue + } + partIds = append(partIds, *v.PartId) + } + //获取配件列表 + partList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "") + //合并模型和配件 + modelList = append(modelList, partList...) mapProductModels := make(map[int64][]types.ModelItem) lightIds := make([]int64, 0, len(modelList)) for _, v := range modelList { diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 8a87d03e..ce203d35 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -172,7 +172,8 @@ type TemplateTagColorInfo struct { } type GetProductModelsReq struct { - ProductIds string `form:"product_ids"` + ProductIds string `form:"product_ids"` + TemplateTag string `form:"template_tag"` } type ProductItem struct { diff --git a/server_api/product.api b/server_api/product.api index 49858ec6..0d5955c9 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -190,7 +190,8 @@ type TemplateTagColorInfo { } //根据产品获取模型配件列表 type GetProductModelsReq { - ProductIds string `form:"product_ids"` + ProductIds string `form:"product_ids"` + TemplateTag string `form:"template_tag"` } type ProductItem { ModelList []ModelItem `json:"model_list"`