diff --git a/constants/recommend_product.go b/constants/recommend_product.go deleted file mode 100644 index 81496ee7..00000000 --- a/constants/recommend_product.go +++ /dev/null @@ -1,9 +0,0 @@ -package constants - -type recommend_product int64 - -// 产品详情页推荐产品 -const PRODUCT_DETAIL_RECOMMEND_CATEGORY recommend_product = 1 - -// 主页推荐产品 -const HOME_PAGE_RECOMMEND_CATEGORY recommend_product = 2 diff --git a/initalize/rabbitmq.go b/initalize/rabbitmq.go index 004524c0..da7f4e7f 100644 --- a/initalize/rabbitmq.go +++ b/initalize/rabbitmq.go @@ -123,7 +123,7 @@ func (h *RabbitMqHandle) Consume(ctx context.Context, queueName constants.RABBIT <-limit wait.Done() }() - if err = handle.Run(m.Body); err != nil { + if err = handle.Run(ctx, m.Body); err != nil { logx.Error("failed to deal with MQ message:", string(m.Body)) return } diff --git a/model/gmodel/fs_cloud_render_log_logic.go b/model/gmodel/fs_cloud_render_log_logic.go index 35237a04..92f12587 100644 --- a/model/gmodel/fs_cloud_render_log_logic.go +++ b/model/gmodel/fs_cloud_render_log_logic.go @@ -1,3 +1,9 @@ package gmodel +import "context" + // TODO: 使用model的属性做你想做的 + +func (r *FsCloudRenderLogModel) Create(ctx context.Context, data *FsCloudRenderLog) error { + return r.db.WithContext(ctx).Model(&FsCloudRenderLog{}).Create(data).Error +} diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 35270c57..9cb2fe91 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -93,3 +93,11 @@ func (d *FsProductModel3dModel) GetGroupPartListByProductIds(ctx context.Context Group("product_id").Find(&resp).Error return resp, err } +func (d *FsProductModel3dModel) FindOneJoinSize(ctx context.Context, productId int64) (resp FsProductModel3d, err error) { + err = d.db.WithContext(ctx).Table(d.name+"as m").Joins("left join fs_product_size as s on m.size_id = s.id"). + Select("m.*"). + Where("m.product_id = ?", productId). + Where("(s.status= ? and m.tag = ?)", 1, 1). + Order("s.sort ASC").Take(&resp).Error + return resp, err +} diff --git a/model/gmodel/fs_product_recommend_gen.go b/model/gmodel/fs_product_recommend_gen.go index 16988d7a..930a3da8 100644 --- a/model/gmodel/fs_product_recommend_gen.go +++ b/model/gmodel/fs_product_recommend_gen.go @@ -9,7 +9,6 @@ type FsProductRecommend struct { Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常 - Category *int64 `gorm:"default:1;" json:"category"` // 推荐类别1:详情推荐 2:列表页推荐 Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间 } type FsProductRecommendModel struct { diff --git a/model/gmodel/fs_product_recommend_logic.go b/model/gmodel/fs_product_recommend_logic.go index 71e9f4aa..02e33584 100644 --- a/model/gmodel/fs_product_recommend_logic.go +++ b/model/gmodel/fs_product_recommend_logic.go @@ -7,10 +7,9 @@ import ( ) type GetRecommendProductListReq struct { - Ctx context.Context - Page int - Limit int - Category int64 // 0是全部 + Ctx context.Context + Page int + Limit int } func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) { @@ -19,9 +18,6 @@ func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProduc Joins("inner join fs_product as p on r.product_id = p.id"). Where("r.status = ? ", 1). Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1) - if req.Category != 0 { - db = db.Where("r.category = ?", req.Category) - } if err = db.Limit(1).Count(&total).Error; err != nil { return nil, 0, err } @@ -30,24 +26,14 @@ func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProduc err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error return resp, total, err } -func (r *FsProductRecommendModel) GetIgnoreRandomRecommendProductList(ctx context.Context, limit int, category int64, idNotInt []int64) (resp []FsProduct, err error) { - err = r.db.WithContext(ctx).Debug().Select("p.*"). - Table("fs_product_recommend as r"). - Joins("inner join fs_product as p on r.product_id = p.id"). - Where("r.product_id not in (?)", idNotInt). - Where("r.status = ? ", 1). - Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1). - Where("r.category = ?", category).Order("RAND()").Limit(limit).Find(&resp).Error - return resp, err -} -func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, category int64, data *FsProductRecommend) error { +func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, data *FsProductRecommend) error { var info FsProductRecommend - err := r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ? and `category` = ?", productId, category).Take(&info).Error + err := r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Take(&info).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return err } if info.Id == 0 { return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Create(data).Error } - return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ? and `category` = ?", productId, category).Updates(data).Error + return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Updates(data).Error } diff --git a/model/gmodel/fs_product_tag_prop_gen.go b/model/gmodel/fs_product_tag_prop_gen.go new file mode 100644 index 00000000..078d6b4b --- /dev/null +++ b/model/gmodel/fs_product_tag_prop_gen.go @@ -0,0 +1,23 @@ +package gmodel + +import ( + "gorm.io/gorm" +) + +// fs_product_tag_prop 产品标签相关属性表 +type FsProductTagProp struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id + ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id + TagId *int64 `gorm:"default:0;" json:"tag_id"` // 模板标签id + Cover *string `gorm:"default:'';" json:"cover"` // + Status *int64 `gorm:"default:1;" json:"status"` // 状态 + Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间 +} +type FsProductTagPropModel struct { + db *gorm.DB + name string +} + +func NewFsProductTagPropModel(db *gorm.DB) *FsProductTagPropModel { + return &FsProductTagPropModel{db: db, name: "fs_product_tag_prop"} +} diff --git a/model/gmodel/fs_product_tag_prop_logic.go b/model/gmodel/fs_product_tag_prop_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_product_tag_prop_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 76bf7bf0..dc8a1b02 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -106,3 +106,16 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co err = db.Find(&resp).Error return resp, err } + +// 获取第一个尺寸下的模板 +func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx context.Context, productId int64, tagId 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.status = ? and t.is_del = ?", 1, 0). + Where("s.status = ?", 1). + Order("s.sort ASC"). + Take(&resp).Error + return resp, err +} diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index c2139293..46818f31 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -65,6 +65,7 @@ type AllModelsGen struct { FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表 FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表 + FsProductTagProp *FsProductTagPropModel // fs_product_tag_prop 产品标签相关属性表 FsProductTemplate *FsProductTemplateModel // fs_product_template 产品模板表(已废弃) FsProductTemplateBasemap *FsProductTemplateBasemapModel // fs_product_template_basemap 模板底图表 FsProductTemplateElement *FsProductTemplateElementModel // fs_product_template_element 云渲染配置表 @@ -159,6 +160,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen { FsProductRenderDesign: NewFsProductRenderDesignModel(gdb), FsProductScene: NewFsProductSceneModel(gdb), FsProductSize: NewFsProductSizeModel(gdb), + FsProductTagProp: NewFsProductTagPropModel(gdb), FsProductTemplate: NewFsProductTemplateModel(gdb), FsProductTemplateBasemap: NewFsProductTemplateBasemapModel(gdb), FsProductTemplateElement: NewFsProductTemplateElementModel(gdb), diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 103134a0..f3bf72be 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -2,7 +2,7 @@ package logic import ( "errors" - "fusenapi/constants" + "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" "fusenapi/utils/format" @@ -46,15 +46,23 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get detail product info") } - //随机取产品列表(不包含详情产品) - recommendProductList, err := l.svcCtx.AllModels.FsProductRecommend.GetIgnoreRandomRecommendProductList(l.ctx, int(req.Num), int64(constants.PRODUCT_DETAIL_RECOMMEND_CATEGORY), []int64{productInfo.Id}) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend list") + var ( + recommendProductList []gmodel.FsProduct + ) + if productInfo.RecommendProduct != nil && *productInfo.RecommendProduct != "" { + recommendProductIds, err := format.StrSlicToInt64Slice(strings.Split(*productInfo.RecommendProduct, ",")) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to split recommend product ids") + } + recommendProductList, err = l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, recommendProductIds, "") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get recommend product list") + } } //需要填充时需要忽略的id - ignoreProductIds := make([]int64, 0, len(recommendProductList)+1) - ignoreProductIds = append(ignoreProductIds, productInfo.Id) + ignoreProductIds := make([]int64, 0, len(recommendProductList)) productIds := make([]int64, 0, len(recommendProductList)) //在合并之前记住推荐的产品 mapRecommend := make(map[int64]struct{}) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 42e240e1..948c9799 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -363,7 +363,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL } image.ThousandFaceImageFormat(&r) item.Cover = r.Cover - item.CoverDefault = r.CoverDefault + item.CoverDefault = nil //加入分类产品切片 productListRsp = append(productListRsp, item) } diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 899de460..b41c7dd0 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -3,7 +3,6 @@ package logic import ( "errors" "fmt" - "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -55,10 +54,9 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty ) //获取列表推荐产品 recommendProductList, _, err = l.svcCtx.AllModels.FsProductRecommend.GetRecommendProductList(gmodel.GetRecommendProductListReq{ - Ctx: l.ctx, - Page: 1, - Limit: 500, //设置最大500 - Category: int64(constants.HOME_PAGE_RECOMMEND_CATEGORY), + Ctx: l.ctx, + Page: 1, + Limit: 500, //设置最大500 }) if len(recommendProductList) == 0 { return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{}) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index f2d27f0a..c1aaf641 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -268,15 +268,20 @@ type TagItem struct { } type TagProduct struct { - ProductId int64 `json:"product_id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - SizeNum uint32 `json:"size_num"` - MinPrice int64 `json:"min_price"` - CoverDefault string `json:"cover_default"` - HaveOptionalFitting bool `json:"have_optional_fitting"` - Recommended bool `json:"recommended"` + ProductId int64 `json:"product_id"` + Sn string `json:"sn"` + Title string `json:"title"` + Cover string `json:"cover"` + SizeNum uint32 `json:"size_num"` + MinPrice int64 `json:"min_price"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + HaveOptionalFitting bool `json:"have_optional_fitting"` + Recommended bool `json:"recommended"` +} + +type CoverDefaultItem struct { + Tag string `json:"tag"` + Cover string `json:"cover"` } type GetRenderDesignReq struct { diff --git a/server/render/consumer/assemble_render_data.go b/server/render/consumer/assemble_render_data.go index 6e6cc6a3..4a1c6f75 100644 --- a/server/render/consumer/assemble_render_data.go +++ b/server/render/consumer/assemble_render_data.go @@ -1,22 +1,238 @@ package consumer import ( + "bytes" + "context" "encoding/json" + "errors" + "fmt" + "fusenapi/model/gmodel" "fusenapi/utils/websocket_data" "github.com/zeromicro/go-zero/core/logx" + "gorm.io/gorm" + "io/ioutil" + "net/http" + "time" ) +// 这里请求的py接口返回数据 +type pythonApiRsp struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data []struct { + Tid int64 `json:"tid"` + Imgurl string `json:"imgurl"` + Costtime int64 `json:"costtime"` + } `json:"data"` +} + // 消费渲染需要组装的数据 type MqConsumerRenderAssemble struct { } -func (m *MqConsumerRenderAssemble) Run(data []byte) error { +func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error { logx.Info("收到需要组装的消息:", string(data)) var parseInfo websocket_data.AssembleRenderData if err := json.Unmarshal(data, &parseInfo); err != nil { logx.Error("MqConsumerRenderAssemble数据格式错误:", err) return nil //不返回错误就删除消息 } + val := ctx.Value("allmodels") + if val == nil { + return errors.New("allmodels is nil") + } + allmodels, ok := val.(*gmodel.AllModelsGen) + if !ok { + return errors.New("allmodels is nil!!") + } + timeSearchBegin := time.Now().UnixMilli() + //获取模板 + templateInfo, err := allmodels.FsProductTemplateV2.FindOneByProductIdTagIdWithSizeTable(ctx, parseInfo.RenderData.ProductId, fmt.Sprintf("%d", parseInfo.RenderData.TemplateTagId)) + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + logx.Error("template info is not found") + return nil + } + logx.Error("failed to get template info:", err) + return err + } + renderLogTime := time.Now().UnixMilli() - timeSearchBegin + now := time.Now().Unix() + title := "1-组装模板数据" + //云渲染日志 + err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{ + UserId: &parseInfo.RenderData.UserId, + Title: &title, + Time: &renderLogTime, + Tag: &parseInfo.RenderId, + Ctime: &now, + }) + if err != nil { + logx.Error(err) + } + pyapiBeginTime := time.Now().UnixMilli() + //这里curl post请求数据。获取处理好的贴图数据,用于贴model的贴图 + pythonPostData := map[string]interface{}{ + "tids": templateInfo.Id, + "data": parseInfo.RenderData.Data, + } + pyPostBytes, _ := json.Marshal(pythonPostData) + url := "http://110.41.19.98:8867/imgRender" + pyRsp, err := http.Post(url, "application/json;charset=UTF-8", bytes.NewReader(pyPostBytes)) + if err != nil { + logx.Error("request python render api err:", err) + return err + } + defer pyRsp.Body.Close() + pyRspBytes, err := ioutil.ReadAll(pyRsp.Body) + if err != nil { + logx.Error("failed to read python api rsp body,err=", err) + return err + } + var rspInfo pythonApiRsp + if err = json.Unmarshal(pyRspBytes, &rspInfo); err != nil { + logx.Error("failed to unmarshal python api rsp:", err) + return err + } + if rspInfo.Code != 200 { + logx.Error("python api 接口请求错误:", rspInfo.Msg) + return err + } + if len(rspInfo.Data) == 0 { + logx.Error("python api 接口没有数据:") + return err + } + //云渲染日志 + title = "2-请求->接收python合成刀版图接口" + now = time.Now().Unix() + pyRequestTime := time.Now().UnixMilli() - pyapiBeginTime + err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{ + UserId: &parseInfo.RenderData.UserId, + Title: &title, + Time: &pyRequestTime, + Tag: &parseInfo.RenderId, + Ctime: &now, + }) + if err != nil { + logx.Error(err) + } + incTime := int64(0) + mapCurlData := make(map[int64]int) + for k, v := range rspInfo.Data { + mapCurlData[v.Tid] = k + incTime += v.Costtime + } + //云渲染日志 + title = "3-python合成刀版图" + now = time.Now().Unix() + postData := string(pyPostBytes) + pyRspStr := string(pyRspBytes) + err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{ + UserId: &parseInfo.RenderData.UserId, + PostUrl: &url, + PostData: &postData, + Result: &pyRspStr, + Title: &title, + Time: &incTime, + Tag: &parseInfo.RenderId, + Ctime: &now, + }) + if err != nil { + logx.Error(err) + } + //获取渲染设置信息 + //element, err := allmodels.FsProductTemplateElement + /* + $element = ProductTemplateElement::find() + ->andFilterWhere(['in', 'product_template_id', $mids]) + ->asArray() + ->all(); + + $element = array_column($element, null, 'product_template_id'); + $elementTitles = array_column($element, 'title'); + + $result = []; + + $time_pinjie_begin = $render->getMillisecond(); + foreach ($templates as $key => $val) { + if(!isset($element[$val['model_id']]) || !isset($imageData[$val['id']])){ + continue; + } + //数据拼装 + $item = []; + + $item['light'] = $element[$val['model_id']]['light']; + $item['refletion'] = $element[$val['model_id']]['refletion'] == '' ? -1 : (int)$element[$val['model_id']]['refletion']; + $item['scale'] = $element[$val['model_id']]['scale']; + $item['sku_id'] = $val['product_id']; + $item['tid'] = $element[$val['model_id']]['title']; + $item['rotation'] = $element[$val['model_id']]['rotation']; + $item['filePath'] = '';//todo 文件路径,针对千人千面 + + //组装data数据 + $tempData = []; + //获取材质模式对应关系 + $mode = $element[$val['model_id']]['mode'] ? json_decode($element[$val['model_id']]['mode'], true) : []; + // $base_img = (new ImageService())->base64EncodeImageNoHeader(\Yii::$app->params['baseurl'].$imageData[$val['id']]['imgurl']); + $base_img = \Yii::$app->params['h5Url'].'/storage'.$imageData[$val['id']]['imgurl']; + //判断是否包含base数据 即对应建模那边的model + if($element[$val['model_id']]['base']){ + $tempData[] = [ + 'name' => 'model', + 'data' => '0,'.$base_img.','.$element[$val['model_id']]['base'], + 'type' => 'other', + 'layer' => '0', + 'is_update' => 1, + 'mode' => $mode['model'], + ]; + } + if($element[$val['model_id']]['shadow']){ + $tempData[] = [ + 'name' => 'shadow', + 'data' => $element[$val['model_id']]['shadow'], + 'type' => 'other', + 'layer' => '0', + 'is_update' => 0, + 'mode' => $mode['shadow'], + ]; + } + if($element[$val['model_id']]['model_p']){ + $tempData[] = [ + 'name' => 'model_P', + 'data' => '0,'.$element[$val['model_id']]['model_p'], + 'type' => 'other', + 'layer' => '0', + 'is_update' => 0, + 'mode' => $mode['model_P'], + ]; + } + $item['data'] = $tempData; + $result[] = $item; + + } + $log = new CloudRenderLog(); + $log->title = '接收到python刀版图 -> 3-组装MQ渲染任务队列'; + $log->time = $render->getMillisecond() - $time_pinjie_begin; + $log->user_id = $user_id; + $log->post_data = ''; + $log->post_url = ''; + $log->result = $res; + $log->tag = $inputData['id']; + $log->ctime = time(); + $log->save(false); + } + + $sendData = [ + 'id' => $inputData['id'], + 'order_id' => 0, + 'user_id' => \Yii::$app->user->id, + 'sku_ids' => $inputData['sku_ids'], + 'tids' => $elementTitles, + 'data' => $result, + 'is_thousand_face' => 0, + 'folder' => '',//todo 千人千面需要使用 + ]; + return $sendData;*/ return nil } diff --git a/server/render/render.go b/server/render/render.go index 1210715d..acb9d019 100644 --- a/server/render/render.go +++ b/server/render/render.go @@ -35,6 +35,7 @@ func main() { //消费渲染前组装数据队列 ctx1 := context.Background() ctx2, cancel := context.WithCancel(ctx1) + ctx2 = context.WithValue(ctx2, "allmodels", ctx.AllModels) defer cancel() go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA, &consumer.MqConsumerRenderAssemble{}) handler.RegisterHandlers(server, ctx) diff --git a/server/websocket/internal/logic/mq_consumer.go b/server/websocket/internal/logic/mq_consumer.go index c28ff2d6..7488e229 100644 --- a/server/websocket/internal/logic/mq_consumer.go +++ b/server/websocket/internal/logic/mq_consumer.go @@ -1,6 +1,7 @@ package logic import ( + "context" "encoding/json" "fusenapi/constants" "fusenapi/utils/websocket_data" @@ -11,7 +12,7 @@ import ( type MqConsumerRenderResult struct { } -func (m *MqConsumerRenderResult) Run(data []byte) error { +func (m *MqConsumerRenderResult) Run(ctx context.Context, data []byte) error { logx.Info("接收到MqConsumerRenderResult数据:", string(data)) var parseInfo websocket_data.RenderImageNotify if err := json.Unmarshal(data, &parseInfo); err != nil { diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index d4974870..978154d0 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -30,6 +30,7 @@ func (w *wsConnectItem) renderImage(data []byte) { return } logx.Info("收到请求云渲染图片数据:", renderImageData) + renderImageData.RenderData.UserId = w.userId //把需要渲染的图片任务加进去 taskId := hash.JsonHashKey(renderImageData.RenderData) w.renderProperty.renderImageTaskCtlChan <- renderImageControlChanItem{ @@ -39,7 +40,7 @@ func (w *wsConnectItem) renderImage(data []byte) { } tmpData := websocket_data.AssembleRenderData{ TaskId: taskId, - UserId: w.userId, + RenderId: renderImageData.RenderId, RenderData: renderImageData.RenderData, } d, _ := json.Marshal(tmpData) diff --git a/server/websocket/websocket.go b/server/websocket/websocket.go index 202e57fd..cfc775f7 100644 --- a/server/websocket/websocket.go +++ b/server/websocket/websocket.go @@ -33,6 +33,7 @@ func main() { //消费渲染结果队列 ctx1 := context.Background() ctx2, cancel := context.WithCancel(ctx1) + ctx2 = context.WithValue(ctx2, "allmodels", ctx.AllModels) defer cancel() go ctx.RabbitMq.Consume(ctx2, constants.RABBIT_MQ_RENDER_RESULT_DATA, &logic.MqConsumerRenderResult{}) handler.RegisterHandlers(server, ctx) diff --git a/server_api/product.api b/server_api/product.api index 48ac5a50..711ce0d4 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -317,15 +317,20 @@ type TagItem { ChildTagList []*TagItem `json:"child_tag_list"` } type TagProduct { - ProductId int64 `json:"product_id"` - Sn string `json:"sn"` - Title string `json:"title"` - Cover string `json:"cover"` - SizeNum uint32 `json:"size_num"` - MinPrice int64 `json:"min_price"` - CoverDefault string `json:"cover_default"` - HaveOptionalFitting bool `json:"have_optional_fitting"` - Recommended bool `json:"recommended"` + ProductId int64 `json:"product_id"` + Sn string `json:"sn"` + Title string `json:"title"` + Cover string `json:"cover"` + SizeNum uint32 `json:"size_num"` + MinPrice int64 `json:"min_price"` + //彩膜列表 + CoverDefault []CoverDefaultItem `json:"cover_default"` + HaveOptionalFitting bool `json:"have_optional_fitting"` + Recommended bool `json:"recommended"` +} +type CoverDefaultItem { + Tag string `json:"tag"` + Cover string `json:"cover"` } //获取云渲染设计方案信息 type GetRenderDesignReq { diff --git a/utils/mq_consumer_factory/mq.go b/utils/mq_consumer_factory/mq.go index 0f3bc97d..d2b7e1d8 100644 --- a/utils/mq_consumer_factory/mq.go +++ b/utils/mq_consumer_factory/mq.go @@ -1,6 +1,8 @@ package mq_consumer_factory +import "context" + // 消费mq消息要实现对应Run方法 type MqHandle interface { - Run(data []byte) error + Run(ctx context.Context, data []byte) error } diff --git a/utils/websocket_data/render_data.go b/utils/websocket_data/render_data.go index 09a203da..5ec90785 100644 --- a/utils/websocket_data/render_data.go +++ b/utils/websocket_data/render_data.go @@ -37,6 +37,6 @@ type ThirdPartyLoginRspMsg struct { // 发送到渲染组装的mq数据 type AssembleRenderData struct { TaskId string `json:"task_id"` - UserId int64 `json:"user_id"` + RenderId string `json:"render_id"` RenderData RenderData `json:"render_data"` }