From 25b7334c308a0ba1cf8ded6a88c06eb792537d2b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 19 Sep 2023 14:39:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6develop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/logic/ws_render_image.go | 15 ++++++++- service/repositories/image_handle.go | 32 ++++++++++++------- utils/websocket_data/render_data.go | 27 +++++++++------- 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index a8f86d2f..5a20f57d 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -100,6 +100,15 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } + lenColor := len(renderImageData.RenderData.TemplateTagColor.Color) + if lenColor == 0 { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "请传入模板标签选择的颜色", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } + if renderImageData.RenderData.TemplateTagColor.SelectedIndex >= lenColor || renderImageData.RenderData.TemplateTagColor.SelectedIndex < 0 { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "选择的模板标签颜色索引越界", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } //获取产品信息(部分字段) productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") if err != nil { @@ -192,6 +201,10 @@ func (w *wsConnectItem) renderImage(data []byte) { Phone: renderImageData.RenderData.Phone, Qrcode: renderImageData.RenderData.Qrcode, LogoUrl: renderImageData.RenderData.Logo, + TemplateTagColor: repositories.TemplateTagColor{ + Color: renderImageData.RenderData.TemplateTagColor.Color, + Index: renderImageData.RenderData.TemplateTagColor.SelectedIndex, + }, } res, err := w.logic.svcCtx.Repositories.ImageHandle.LogoCombine(w.logic.ctx, &combineReq) if err != nil { @@ -216,7 +229,7 @@ func (w *wsConnectItem) renderImage(data []byte) { } //获取唯一id taskId := w.genRenderTaskId(combineImage, renderImageData, model3dInfo, productTemplate, element) - //查询有没有缓存的资源,有就返回###################### + //查询有没有缓存的资源,有就返回 resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 642f590d..540292fa 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -187,16 +187,17 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq /* logo合图 */ type ( LogoCombineReq struct { - UserId int64 `json:"user_id"` - GuestId int64 `json:"guest_id"` - TemplateId int64 `json:"template_id"` - TemplateTag string `json:"template_tag"` - Website string `json:"website"` // 合图参数 - Slogan string `json:"slogan"` // 合图参数 - Address string `json:"address"` // 合图参数 - Phone string `json:"phone"` // 合图参数 - Qrcode string `json:"qrcode"` // 合图参数 - LogoUrl string `json:"logo_url"` // 合图参数 + UserId int64 `json:"user_id"` + GuestId int64 `json:"guest_id"` + TemplateId int64 `json:"template_id"` + TemplateTag string `json:"template_tag"` + Website string `json:"website"` // 合图参数 + Slogan string `json:"slogan"` // 合图参数 + Address string `json:"address"` // 合图参数 + Phone string `json:"phone"` // 合图参数 + Qrcode string `json:"qrcode"` // 合图参数 + LogoUrl string `json:"logo_url"` // 合图参数 + TemplateTagColor TemplateTagColor `json:"template_tag_color"` } LogoCombineRes struct { ResourceId string @@ -206,6 +207,10 @@ type ( DiffTimeUploadFile int64 } ) +type TemplateTagColor struct { + Color [][]string `json:"color"` + Index int `json:"index"` +} func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { // 查询logo最新基础信息 @@ -308,8 +313,11 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq combineParam["phone"] = in.Phone combineParam["address"] = in.Address combineParam["qrcode"] = in.Qrcode - //combineParam["template_tag_selected"] = - + combineParam["template_tag_selected"] = map[string]interface{}{ + "template_tag": in.TemplateTag, + "color": in.TemplateTagColor.Color, + "index": in.TemplateTagColor.Index, + } var postMap = make(map[string]interface{}, 2) postMap["module_data"] = moduleDataMap postMap["tag_data"] = tagDataMap diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 16f3326b..d79032d5 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -15,17 +15,22 @@ type RenderImageReqMsg struct { RenderData RenderData `json:"render_data"` } type RenderData struct { - TemplateTag string `json:"template_tag"` //模板标签(必须) - ProductId int64 `json:"product_id"` //产品id(必须) - Website string `json:"website"` //网站(可选) - Slogan string `json:"slogan"` //slogan(可选) - Address string `json:"address"` //地址(可选) - Phone string `json:"phone"` //电话(可选) - Qrcode string `json:"qrcode"` //二维码(可选) - ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) - UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) - GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) - Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) + TemplateTag string `json:"template_tag"` //模板标签(必须) + TemplateTagColor TemplateTagColor `json:"template_tag_color"` //模板标签组合颜色 + ProductId int64 `json:"product_id"` //产品id(必须) + Website string `json:"website"` //网站(可选) + Slogan string `json:"slogan"` //slogan(可选) + Address string `json:"address"` //地址(可选) + Phone string `json:"phone"` //电话(可选) + Qrcode string `json:"qrcode"` //二维码(可选) + ProductSizeId int64 `json:"product_size_id"` //尺寸id(可选) + UserId int64 `json:"user_id"` //用户id(websocket连接建立再赋值) + GuestId int64 `json:"guest_id"` //游客id(websocket连接建立再赋值) + Logo string `json:"logo"` //log资源地址(websocket连接建立再赋值) +} +type TemplateTagColor struct { + Color [][]string `json:"color"` //颜色组合 + SelectedIndex int `json:"selected_index"` //主色的下标索引 } // websocket发送渲染完的数据