From fcf7c909a368918d991e312019c7de24948b5006 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 9 Aug 2023 15:29:27 +0800 Subject: [PATCH] fix --- model/gmodel/fs_resource_logic.go | 14 +++--------- .../render/consumer/assemble_render_data.go | 22 ++++++++++++++++++- .../internal/logic/datatransferlogic.go | 8 +++---- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/model/gmodel/fs_resource_logic.go b/model/gmodel/fs_resource_logic.go index 6dab100f..19db19ad 100644 --- a/model/gmodel/fs_resource_logic.go +++ b/model/gmodel/fs_resource_logic.go @@ -2,7 +2,6 @@ package gmodel import ( "context" - "errors" "fusenapi/utils/handlers" "gorm.io/gorm" @@ -10,16 +9,9 @@ import ( // TODO: 使用model的属性做你想做的 -func (p *FsResourceModel) FindOneById(ctx context.Context, resourceId string) (*FsResource, error) { - var resp FsResource - result := p.db.Table(p.name).WithContext(ctx).Where("resource_id =?", resourceId).Take(&resp) - if result.Error != nil { - // 检查 ErrRecordNotFound 错误 - if !errors.Is(result.Error, gorm.ErrRecordNotFound) { - return nil, result.Error - } - } - return &resp, nil +func (p *FsResourceModel) FindOneById(ctx context.Context, resourceId string) (resp *FsResource, err error) { + err = p.db.Table(p.name).WithContext(ctx).Where("resource_id =?", resourceId).Take(&resp).Error + return resp, err } func (p *FsResourceModel) Create(ctx context.Context, req *FsResource) (resp *FsResource, err error) { diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index d5f79cbf..b00cc014 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -48,6 +48,27 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { if !ok { return errors.New("allmodels is nil!!") } + rabbitmq := initalize.RabbitMqHandle{} + //查询有没有缓存的资源 + resource, err := allmodels.FsResource.FindOneById(ctx, parseInfo.TaskId) + if err != nil { + if !errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error("failed to find render resource:", err) + return err + } + } else { + //有数据则直接返回 + cacheData := websocket_data.RenderImageNotify{ + TaskId: parseInfo.TaskId, + Image: *resource.ResourceUrl, + } + d, _ := json.Marshal(cacheData) + if err = rabbitmq.SendMsg(constants.RABBIT_MQ_RENDER_RESULT_DATA, d); err != nil { + logx.Error("failed to send cache render resource to queue:RABBIT_MQ_RENDER_RESULT_DATA") + return err + } + return nil + } timeSearchBegin := time.Now().UnixMilli() //获取模板 templateInfo, err := allmodels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId)) @@ -250,7 +271,6 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { "folder": "", //todo 千人千面需要使用 } b, _ := json.Marshal(sendData) - rabbitmq := initalize.RabbitMqHandle{} if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil { logx.Error("发送渲染组装数据到rabbitmq失败:", err) return err diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 52f25a61..c2d5fae0 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -85,7 +85,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp } defer conn.Close() //鉴权不成功10秒后断开 - var ( + /*var ( userInfo *auth.UserInfo isAuth bool ) @@ -102,10 +102,10 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp //发送关闭信息 _ = conn.WriteMessage(websocket.CloseMessage, nil) return - } + }*/ //测试的目前写死 39 - /*var userInfo auth.UserInfo - userInfo.UserId = 39*/ + var userInfo auth.UserInfo + userInfo.UserId = 39 //生成连接唯一标识 uniqueId := websocketIdGenerator.Get() ws := wsConnectItem{