From d2c8fa902077b3f048190d3b90453eb6358187e8 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 17 Aug 2023 11:49:31 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_template_tags_logic.go | 8 ++++++-- .../internal/logic/gettemplatevdetaillogic.go | 11 ++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/model/gmodel/fs_product_template_tags_logic.go b/model/gmodel/fs_product_template_tags_logic.go index efa20ad8..53e76130 100755 --- a/model/gmodel/fs_product_template_tags_logic.go +++ b/model/gmodel/fs_product_template_tags_logic.go @@ -43,7 +43,11 @@ func (pt *FsProductTemplateTagsModel) GetListByTagNames(ctx context.Context, tag err = db.Limit(limit).Find(&resp).Error return resp, err } -func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string) (resp *FsProductTemplateTags, err error) { - err = pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1).Take(&resp).Error +func (pt *FsProductTemplateTagsModel) FindOneByTagName(ctx context.Context, tagName string, fields ...string) (resp *FsProductTemplateTags, err error) { + db := pt.db.WithContext(ctx).Model(&FsProductTemplateTags{}).Where("`template_tag` = ? and `status` = ?", tagName, 1) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error return resp, err } diff --git a/server/product-template/internal/logic/gettemplatevdetaillogic.go b/server/product-template/internal/logic/gettemplatevdetaillogic.go index 12324f50..7ef73a14 100644 --- a/server/product-template/internal/logic/gettemplatevdetaillogic.go +++ b/server/product-template/internal/logic/gettemplatevdetaillogic.go @@ -8,7 +8,6 @@ import ( "fusenapi/utils/basic" "fusenapi/utils/format" "gorm.io/gorm" - "strconv" "strings" "context" @@ -62,13 +61,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template info") } //获取模板标签 - templateTagModel := gmodel.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn) - tagId, err := strconv.ParseInt(*templatev2Info.Tag, 10, 64) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "parse int tag id err") - } - templateTagInfo, err := templateTagModel.FindOne(l.ctx, tagId, "id,title") + templateTagInfo, err := l.svcCtx.AllModels.FsProductTemplateTags.FindOneByTagName(l.ctx, *templatev2Info.TemplateTag, "id,title") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template tag info is not exists") @@ -125,7 +118,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta } templateInfoRsp["tag"] = map[string]interface{}{ "id": templateTagInfo.Id, - "title": *templateTagInfo.Title, + "title": *templateTagInfo.TemplateTag, } response := types.GetTemplatevDetailRsp{ ProductModelInfo: productModelInfoRsp,