From 757a7fb0b4976cfb508dc1535085c7866ae10fd3 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 17 Aug 2023 11:09:59 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_template_tags_gen.go | 12 ++++++------ model/gmodel/fs_product_template_tags_logic.go | 4 ++-- model/gmodel/fs_product_template_v2_gen.go | 2 +- model/gmodel/fs_product_template_v2_logic.go | 6 +++--- .../product/internal/logic/gettemplatebypidlogic.go | 11 ++++++++++- .../internal/logic/ws_render_image_logic.go | 4 ++-- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/model/gmodel/fs_product_template_tags_gen.go b/model/gmodel/fs_product_template_tags_gen.go index a5505bbb..a940bced 100644 --- a/model/gmodel/fs_product_template_tags_gen.go +++ b/model/gmodel/fs_product_template_tags_gen.go @@ -6,12 +6,12 @@ import ( // fs_product_template_tags 模板标签表 type FsProductTemplateTags struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID - Title *string `gorm:"unique_key;default:'';" json:"title"` // 标题 - Cover *string `gorm:"default:'';" json:"cover"` // 封面图 - Status *int64 `gorm:"default:0;" json:"status"` // 状态 1:可用 - CreateAt *int64 `gorm:"default:0;" json:"create_at"` // 创建时间 - Groups *string `gorm:"default:'';" json:"groups"` // 分组信息 + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID + TemplateTag *string `gorm:"unique_key;default:'';" json:"template_tag"` // 标题 + Cover *string `gorm:"default:'';" json:"cover"` // 封面图 + Status *int64 `gorm:"default:0;" json:"status"` // 状态 1:可用 + CreateAt *int64 `gorm:"default:0;" json:"create_at"` // 创建时间 + Groups *string `gorm:"default:'';" json:"groups"` // 分组信息 } type FsProductTemplateTagsModel struct { db *gorm.DB diff --git a/model/gmodel/fs_product_template_tags_logic.go b/model/gmodel/fs_product_template_tags_logic.go index 96d4cca2..efa20ad8 100755 --- a/model/gmodel/fs_product_template_tags_logic.go +++ b/model/gmodel/fs_product_template_tags_logic.go @@ -36,7 +36,7 @@ func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tag if len(tagNames) == 0 { return nil, nil } - db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`title` in (?) and `status` = ?", tagNames, 1) + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` in (?) and `status` = ?", tagNames, 1) if orderBy != "" { db = db.Order(orderBy) } @@ -44,6 +44,6 @@ func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tag return resp, err } func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string) (resp *FsProductTemplateTags, err error) { - err = pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`title` = ? and `status` = ?", tagName, 1).Take(&resp).Error + err = pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1).Take(&resp).Error return resp, err } diff --git a/model/gmodel/fs_product_template_v2_gen.go b/model/gmodel/fs_product_template_v2_gen.go index 68c91ed5..e1c1780f 100644 --- a/model/gmodel/fs_product_template_v2_gen.go +++ b/model/gmodel/fs_product_template_v2_gen.go @@ -20,7 +20,7 @@ type FsProductTemplateV2 struct { IsPublic *int64 `gorm:"default:0;" json:"is_public"` // 是否可公用(1:可以,0:不可以) Status *int64 `gorm:"default:0;" json:"status"` // 状态1正常 2异常 Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 - Tag *string `gorm:"default:'';" json:"tag"` // + TemplateTag *string `gorm:"default:'';" json:"template_tag"` // IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除 SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // GroupOptions *string `gorm:"default:'';" json:"group_options"` // diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index a4945096..8ae2897d 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -115,7 +115,7 @@ func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx cont err = t.db.WithContext(ctx).Table(t.name+" as t"). Joins("left join fs_product_size as s on t.product_id = s.product_id"). Select("t.*"). - Where("t.product_id = ? and t.tag = ? ", productId, templateTag). + Where("t.product_id = ? and t.template_tag = ? ", productId, templateTag). Where("t.status = ? and t.is_del = ?", 1, 0). Where("s.status = ?", 1). Order("s.sort ASC"). @@ -126,7 +126,7 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont if len(modelIds) == 0 { return } - db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `tag` = ? and `is_del` = ? and `status` = ?", modelIds, templateTag, 0, 1) + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ?", modelIds, templateTag, 0, 1) if len(fields) != 0 { db = db.Select(fields[0]) } @@ -143,7 +143,7 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont // 获取产品在指定模板标签下的所有模板 func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Context, templateTagId string, productId int64, fields ...string) (resp []FsProductTemplateV2, err error) { db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}). - Where("tag = ? and product_id = ? and status = ? and is_del = ?", templateTagId, productId, 1, 0) + Where("template_tag = ? and product_id = ? and status = ? and is_del = ?", templateTagId, productId, 1, 0) if len(fields) > 0 { db = db.Select(fields[0]) } diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index 9e1b66d1..7612c61c 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -67,6 +67,15 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, } else { //指定物料 sizeIds = append(sizeIds, req.ProductSizeId) } + //获取templatetag信息 + templateTagInfo, err := l.svcCtx.AllModels.FsProductTemplateTags.FindOne(l.ctx, req.ProductTemplateTagId) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template tag is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "failed to get template tag") + } //根据尺寸id获取模型 modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL) if err != nil { @@ -83,7 +92,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, mapModel[v.Id] = k } //查询模型ids下对应tag标签的模板 - templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "") + templateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, *templateTagInfo.TemplateTag, "") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get template list") diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 76133a46..6d8601c1 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -154,8 +154,8 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re logx.Error("assembleRenderData panic:", err) } }() - // todo 获取模板(模板标签下的对一个物料的的模板)目前写死参数 - productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.logic.ctx, info.RenderData.ProductId, "16") + //获取模板 + productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.logic.ctx, info.RenderData.ProductId, info.RenderData.TemplateTag) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("template info is not found")