From d6c43e3e94ee6631a1ef212e2ca061f5147bf432 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 14:23:34 +0800 Subject: [PATCH 1/3] fix --- .../internal/logic/ws_render_image.go | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 26976272..167d3831 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -110,29 +110,21 @@ func (w *wsConnectItem) renderImage(data []byte) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不可定制", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) return } - //获取上传最近的logo - userMaterial, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindLatestOne(w.logic.ctx, w.userId, w.guestId) + //获取用户需要渲染logo + logoInfo, err := w.logic.svcCtx.Repositories.ImageHandle.LogoInfo(w.logic.ctx, &repositories.LogoInfoReq{ + UserId: w.userId, + GuestId: w.guestId, + }) if err != nil { - if !errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户上传logo素材失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - logx.Error("failed to get user logo") - return - } - //使用默认logo(id=0) - userMaterialDefault, err := w.logic.svcCtx.AllModels.FsUserMaterial.FindOneById(w.logic.ctx, 0) - if err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "默认logo不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - return - } - w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取默认logo失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) - logx.Error("default logo is not exists") - return - } - renderImageData.RenderData.Logo = *userMaterialDefault.ResourceUrl - } else { - renderImageData.RenderData.Logo = *userMaterial.ResourceUrl + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取用户logo素材错误", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + logx.Error(err) + return } + if logoInfo == nil || logoInfo.LogoUrl == nil { + w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "用户logo素材url是空的", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) + return + } + renderImageData.RenderData.Logo = *logoInfo.LogoUrl //用户id赋值 renderImageData.RenderData.UserId = w.userId renderImageData.RenderData.GuestId = w.guestId From b7882ef06f450f2431215b03b512e58aa9a98936 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 14:25:47 +0800 Subject: [PATCH 2/3] fix --- model/gmodel/fs_product_logic.go | 8 ++++++-- server/websocket/internal/logic/ws_render_image.go | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/model/gmodel/fs_product_logic.go b/model/gmodel/fs_product_logic.go index 95c301ce..8e7cca3c 100755 --- a/model/gmodel/fs_product_logic.go +++ b/model/gmodel/fs_product_logic.go @@ -2,8 +2,12 @@ package gmodel import "context" -func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct, err error) { - err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id).First(&resp).Error +func (p *FsProductModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProduct, err error) { + db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Take(&resp).Error return resp, err } func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...string) (resp *FsProduct, err error) { diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 167d3831..84f858df 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -94,8 +94,8 @@ func (w *wsConnectItem) renderImage(data []byte) { logx.Error("invalid format of websocket render image message", err) return } - //获取产品信息 - productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId) + //获取产品信息(部分字段) + productInfo, err := w.logic.svcCtx.AllModels.FsProduct.FindOne(w.logic.ctx, renderImageData.RenderData.ProductId, "id,is_customization") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "该产品不存在", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0) From 62256cdde99fb94cf31987627adfc01a91d4c79d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 16:57:32 +0800 Subject: [PATCH 3/3] fix --- server/websocket/internal/logic/datatransferlogic.go | 1 + server/websocket/internal/logic/ws_render_image.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index a01a9970..19f3704d 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -195,6 +195,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use renderImageTask: make(map[string]*renderTask), renderImageTaskCtlChan: make(chan renderImageControlChanItem, renderImageTaskCtlChanLen), renderChan: make(chan []byte, renderChanLen), + renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度 }, } //保存连接 diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index 84f858df..d1cc0405 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -35,6 +35,7 @@ type extendRenderProperty struct { renderImageTask map[string]*renderTask //需要渲染的图片任务 key是taskId val 是renderId renderImageTaskCtlChan chan renderImageControlChanItem //渲染任务新增/回调结果移除任务/更新渲染耗时属性的控制通道(由于任务map无法读写并发) renderChan chan []byte //渲染消息入口的缓冲队列 + renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制 } // 渲染任务新增移除的控制通道的数据 @@ -74,15 +75,15 @@ func (w *wsConnectItem) consumeRenderImageData() { logx.Error("func renderImage err:", err) } }() + tick := time.Tick(w.extendRenderProperty.renderConsumeTickTime) for { select { case <-w.closeChan: //已关闭 return - case data := <-w.extendRenderProperty.renderChan: - w.renderImage(data) + case <-tick: //消费数据 + w.renderImage(<-w.extendRenderProperty.renderChan) } } - } // 执行渲染任务