From c5ef6cfa14ff085f1dee12bc364326fe6df04a60 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 15 Aug 2023 11:18:22 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_template_tags_gen.go | 2 +- model/gmodel/fs_product_template_v2_gen.go | 2 +- model/gmodel/fs_product_template_v2_logic.go | 4 +- .../logic/getproducttemplatetagslogic.go | 6 +-- .../internal/types/types.go | 6 +-- .../render/consumer/assemble_render_data.go | 37 +++++-------------- .../internal/logic/ws_render_image_logic.go | 6 +-- server_api/product-template-tag.api | 6 +-- utils/websocket_data/render_data.go | 10 ++--- 9 files changed, 30 insertions(+), 49 deletions(-) diff --git a/model/gmodel/fs_product_template_tags_gen.go b/model/gmodel/fs_product_template_tags_gen.go index 07d86482..a5505bbb 100644 --- a/model/gmodel/fs_product_template_tags_gen.go +++ b/model/gmodel/fs_product_template_tags_gen.go @@ -7,7 +7,7 @@ import ( // fs_product_template_tags 模板标签表 type FsProductTemplateTags struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID - Title *string `gorm:"default:'';" json:"title"` // 标题 + 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"` // 创建时间 diff --git a/model/gmodel/fs_product_template_v2_gen.go b/model/gmodel/fs_product_template_v2_gen.go index 07ad37fc..68c91ed5 100644 --- a/model/gmodel/fs_product_template_v2_gen.go +++ b/model/gmodel/fs_product_template_v2_gen.go @@ -24,7 +24,7 @@ type FsProductTemplateV2 struct { IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除 SwitchInfo *string `gorm:"default:'';" json:"switch_info"` // GroupOptions *string `gorm:"default:'';" json:"group_options"` // - Version *int64 `gorm:"default:0;" json:"version"` // + Version *int64 `gorm:"index;default:0;" json:"version"` // 默认1 } type FsProductTemplateV2Model struct { db *gorm.DB diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 57109ca8..a4945096 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -111,11 +111,11 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co } // 获取第一个尺寸下的模板 -func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx context.Context, productId int64, tagId string) (resp *FsProductTemplateV2, err error) { +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("left join fs_product_size as s on t.product_id = s.product_id"). Select("t.*"). - Where("t.product_id = ? and t.tag = ? ", productId, tagId). + Where("t.product_id = ? and t.tag = ? ", productId, templateTag). Where("t.status = ? and t.is_del = ?", 1, 0). Where("s.status = ?", 1). Order("s.sort ASC"). diff --git a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go index 21953ee1..de9d34da 100644 --- a/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go +++ b/server/product-template-tag/internal/logic/getproducttemplatetagslogic.go @@ -81,9 +81,9 @@ func (l *GetProductTemplateTagsLogic) GetProductTemplateTags(req *types.GetProdu list := make([]types.GetProductTemplateTagsRsp, 0, len(productTemplateTags)) for _, v := range productTemplateTags { list = append(list, types.GetProductTemplateTagsRsp{ - Id: v.Id, - Tag: *v.Title, - Cover: *v.Cover, + Id: v.Id, + TemplateTag: *v.Title, + Cover: *v.Cover, }) } return resp.SetStatusWithMessage(basic.CodeOK, "success", list) diff --git a/server/product-template-tag/internal/types/types.go b/server/product-template-tag/internal/types/types.go index a89ea882..60cb80ca 100644 --- a/server/product-template-tag/internal/types/types.go +++ b/server/product-template-tag/internal/types/types.go @@ -10,9 +10,9 @@ type GetProductTemplateTagsReq struct { } type GetProductTemplateTagsRsp struct { - Id int64 `json:"id"` - Tag string `json:"tag"` - Cover string `json:"cover"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` } type Request struct { diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index 85a32996..5fb67298 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -4,17 +4,14 @@ import ( "context" "encoding/json" "errors" - "fmt" "fusenapi/constants" "fusenapi/initalize" "fusenapi/server/render/internal/svc" "fusenapi/service/repositories" - "fusenapi/utils/hash" "fusenapi/utils/websocket_data" "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" "strconv" - "time" ) // 这里请求的py接口返回数据 @@ -52,7 +49,7 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { } rabbitmq := initalize.RabbitMqHandle{} //获取模板(模板标签下的对一个物料的的模板) - productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId)) + productTemplate, err := svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, parseInfo.RenderData.TemplateTag) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("template info is not found") @@ -61,33 +58,17 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { logx.Error("failed to get template info:", err) return nil //不返回错误就删除消息 } - time.Now().UTC() - resourceKey := hash.JsonHashKey(parseInfo) - combineParam := map[string]interface{}{ - "logo_url": parseInfo.RenderData.Logo, - "website": "", - "slogan": "", - "address": "", - "phone": "", - "colors": []string{}, - "template_tagid": "b1a", - "is_crop": false, - "shape": "rectangle", - "ratio": 0, - "line": "", - "other": "", - "other1": "", - } - combineParamBytes, _ := json.Marshal(combineParam) //获取刀版图 res, err := svcCtx.Repositories.ImageHandle.LogoCombine(ctx, &repositories.LogoCombineReq{ - ResourceKey: resourceKey, - TemplateId: productTemplate.Id, - CombineParam: string(combineParamBytes), - UserId: parseInfo.RenderData.UserId, - GuestId: parseInfo.RenderData.GuestId, + UserId: parseInfo.RenderData.UserId, + GuestId: parseInfo.RenderData.GuestId, + TemplateId: productTemplate.Id, + TemplateTag: parseInfo.RenderData.TemplateTag, + Website: parseInfo.RenderData.Website, + Slogan: parseInfo.RenderData.Slogan, + Address: parseInfo.RenderData.Address, + Phone: parseInfo.RenderData.Phone, }) - if err != nil { logx.Error("合成刀版图失败:", err) return nil diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 1aadd993..77240ce6 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -42,9 +42,9 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message:product_id") return } - if renderImageData.RenderData.TemplateTagId <= 0 { - w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:template_tag_id ") - logx.Error("invalid format of websocket render image message:template_tag_id") + if renderImageData.RenderData.TemplateTag == "" { + w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:template_tag ") + logx.Error("invalid format of websocket render image message:template_tag") return } //获取上传最近的logo diff --git a/server_api/product-template-tag.api b/server_api/product-template-tag.api index c8b1a2cc..a565ee01 100644 --- a/server_api/product-template-tag.api +++ b/server_api/product-template-tag.api @@ -20,7 +20,7 @@ type GetProductTemplateTagsReq { Limit int `form:"limit"` } type GetProductTemplateTagsRsp { - Id int64 `json:"id"` - Tag string `json:"tag"` - Cover string `json:"cover"` + Id int64 `json:"id"` + TemplateTag string `json:"template_tag"` + Cover string `json:"cover"` } \ No newline at end of file diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 3b004441..eaf44eac 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -12,16 +12,16 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTagId int64 `json:"template_tag_id"` //模板标签id + TemplateTag string `json:"template_tag"` //模板标签 ProductId int64 `json:"product_id"` //产品id UserMaterialId int64 `json:"user_material_id"` //用户素材id Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) - /*Website string `json:"website"` //网站 + Website string `json:"website"` //网站 Slogan string `json:"slogan"` //slogan Address string `json:"address"` //地址 - Phone string `json:"phone"` //电话*/ - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + Phone string `json:"phone"` //电话 + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) } // websocket发送渲染完的数据