diff --git a/model/gmodel/fs_product_template_element_logic.go b/model/gmodel/fs_product_template_element_logic.go index 783f5480..f1f2afe4 100644 --- a/model/gmodel/fs_product_template_element_logic.go +++ b/model/gmodel/fs_product_template_element_logic.go @@ -11,3 +11,9 @@ func (e *FsProductTemplateElementModel) FindOneByModelId(ctx context.Context, mo Take(&resp).Error return resp, err } +func (e *FsProductTemplateElementModel) FindRandOne(ctx context.Context) (resp *FsProductTemplateElement, err error) { + err = e.db.WithContext(ctx).Model(&FsProductTemplateElement{}). + Order("RAND()"). + Take(&resp).Error + return resp, err +} diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index d078e0be..338d074b 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -61,6 +61,7 @@ func (w *wsConnectItem) renderImage() { // 消费渲染缓冲数据 func (w *wsConnectItem) consumeRenderCache(data []byte) { + logx.Info("消费渲染数据:", string(data)) var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))) @@ -154,7 +155,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re } }() // todo 获取模板(模板标签下的对一个物料的的模板)目前写死参数 - productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.logic.ctx, 31, "11" /*fmt.Sprintf("%d", templateTag.Id)*/) + productTemplate, err := w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(w.logic.ctx, info.RenderData.ProductId, "16") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { logx.Error("template info is not found") @@ -187,10 +188,10 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re } logx.Info("合成刀版图成功:", *res.ResourceUrl) //获取渲染设置信息 - element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindOneByModelId(w.logic.ctx, *productTemplate.ModelId) + element, err := w.logic.svcCtx.AllModels.FsProductTemplateElement.FindRandOne(w.logic.ctx /*, *productTemplate.ModelId*/) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - logx.Error("element info is not found,model_id = ?", *productTemplate.ModelId) + logx.Error("element info is not found,model_id = ", *productTemplate.ModelId) return err } logx.Error("failed to get element list,", err)