Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
3e0d97ffb3
|
@ -4,8 +4,12 @@ import (
|
|||
"context"
|
||||
)
|
||||
|
||||
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp *FsProductModel3d, err error) {
|
||||
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).First(&resp).Error
|
||||
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductModel3d, err error) {
|
||||
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id)
|
||||
if len(fields) > 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, orderBy string, fields ...string) (resp []FsProductModel3d, err error) {
|
||||
|
|
|
@ -4,8 +4,12 @@ import (
|
|||
"context"
|
||||
)
|
||||
|
||||
func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64) (resp *FsProductSize, err error) {
|
||||
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id).Take(&resp).Error
|
||||
func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductSize, err error) {
|
||||
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id)
|
||||
if len(fields) > 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) {
|
||||
|
|
|
@ -116,7 +116,7 @@ func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Co
|
|||
// 获取开启云渲染模板
|
||||
func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdModelIdTemplateTag(ctx context.Context, productId, modelId int64, templateTag string) (resp *FsProductTemplateV2, err error) {
|
||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
||||
Where("product_id = ? and model_id = ? and template_tag = ? ", productId, modelId, templateTag).
|
||||
Where("product_id = ? and model_id = ? and template_tag = ? ", productId, modelId, templateTag).
|
||||
Where("status = ? and is_del = ?", 1, 0).
|
||||
Order("sort ASC").
|
||||
Take(&resp).Error
|
||||
|
@ -124,12 +124,17 @@ func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdModelIdTemplateT
|
|||
}
|
||||
|
||||
// 获取开启云渲染模板2
|
||||
func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdTemplateTag(ctx context.Context, productId int64, templateTag string) (resp *FsProductTemplateV2, err error) {
|
||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
||||
func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdTemplateTag(ctx context.Context, productId int64, templateTag string, sort string, fields ...string) (resp *FsProductTemplateV2, err error) {
|
||||
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
||||
Where("product_id = ? and template_tag = ? and element_model_id > ? ", productId, templateTag, 0).
|
||||
Where("status = ? and is_del = ?", 1, 0).
|
||||
Order("sort ASC").
|
||||
Take(&resp).Error
|
||||
Where("status = ? and is_del = ?", 1, 0)
|
||||
if sort != "" {
|
||||
db = db.Order(sort)
|
||||
}
|
||||
if len(fields) > 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Context, modelIds []int64, templateTag string, orderBy string, fields ...string) (resp []FsProductTemplateV2, err error) {
|
||||
|
|
|
@ -38,6 +38,9 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||
if req.Pid == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
|
||||
}
|
||||
if req.TemplateTag == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:template_tag is empty")
|
||||
}
|
||||
//获取产品信息(只是获取id)
|
||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
||||
if err != nil {
|
||||
|
@ -47,6 +50,21 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||
}
|
||||
//获取跟列表页云渲染一样的默认渲染尺寸(模板->尺寸)
|
||||
defaultSizeId := int64(0)
|
||||
defaultTemplate, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(l.ctx, productInfo.Id, req.TemplateTag, "sort ASC", "model_id")
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default template ")
|
||||
} else {
|
||||
//根据模板找到模型sizeId
|
||||
defaultModel3d, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, *defaultTemplate.ModelId, "size_id")
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default model ")
|
||||
}
|
||||
defaultSizeId = *defaultModel3d.SizeId
|
||||
}
|
||||
//获取产品尺寸列表(需要正序排序)
|
||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_hot DESC,sort ASC")
|
||||
if err != nil {
|
||||
|
@ -55,9 +73,13 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||
}
|
||||
sizeIds := make([]int64, 0, len(sizeList))
|
||||
productIds := make([]int64, 0, len(sizeList))
|
||||
for _, v := range sizeList {
|
||||
for k, v := range sizeList {
|
||||
sizeIds = append(sizeIds, v.Id)
|
||||
productIds = append(productIds, *v.ProductId)
|
||||
//把默认的排第一
|
||||
if v.Id == defaultSizeId {
|
||||
sizeList[0], sizeList[k] = sizeList[k], sizeList[0]
|
||||
}
|
||||
}
|
||||
//获取产品价格列表
|
||||
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||
|
|
|
@ -92,9 +92,6 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
|||
rsp := make(map[string]interface{})
|
||||
for _, templateInfo := range templateList {
|
||||
//没有设置模板据不要
|
||||
if templateInfo.TemplateInfo == nil || *templateInfo.TemplateInfo == "" {
|
||||
continue
|
||||
}
|
||||
modelIndex, ok := mapModel[*templateInfo.ModelId]
|
||||
if !ok {
|
||||
continue
|
||||
|
|
|
@ -332,7 +332,8 @@ type PriceItem struct {
|
|||
}
|
||||
|
||||
type GetSizeByPidReq struct {
|
||||
Pid string `form:"pid"`
|
||||
Pid string `form:"pid"`
|
||||
TemplateTag string `form:"template_tag"`
|
||||
}
|
||||
|
||||
type GetSizeByPidRsp struct {
|
||||
|
|
|
@ -140,7 +140,11 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
productSize *gmodel.FsProductSize
|
||||
)
|
||||
//获取信息
|
||||
productSize, productTemplate, model3dInfo, err = w.getProductRelateionInfo(&renderImageData)
|
||||
if renderImageData.RenderData.ProductSizeId > 0 {
|
||||
productSize, productTemplate, model3dInfo, err = w.getProductRelateionInfoWithSizeId(&renderImageData)
|
||||
} else {
|
||||
productSize, productTemplate, model3dInfo, err = w.getProductRelateionInfoWithNoSizeId(&renderImageData)
|
||||
}
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
|
@ -247,37 +251,19 @@ func (w *wsConnectItem) renderImage(data []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
// 获取模板相关信息(指定尺寸)
|
||||
func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
||||
//指定尺寸
|
||||
if renderImageData.RenderData.ProductSizeId > 0 {
|
||||
productSize, err = w.logic.svcCtx.AllModels.FsProductSize.FindOneByIdProductId(w.logic.ctx, renderImageData.RenderData.ProductSizeId, renderImageData.RenderData.ProductId)
|
||||
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, renderImageData.RenderData.ProductSizeId, 0)
|
||||
logx.Error("product size is not found")
|
||||
return
|
||||
}
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品的指定尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
|
||||
logx.Error("failed to get product size:", err)
|
||||
return nil, nil, nil, err
|
||||
// 获取模板相关信息(指定尺寸)(尺寸 -> 模型 ->模板)
|
||||
func (w *wsConnectItem) getProductRelateionInfoWithSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
||||
productSize, err = w.logic.svcCtx.AllModels.FsProductSize.FindOneByIdProductId(w.logic.ctx, renderImageData.RenderData.ProductSizeId, renderImageData.RenderData.ProductId)
|
||||
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, renderImageData.RenderData.ProductSizeId, 0)
|
||||
logx.Error("product size is not found")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
//没有指定尺寸则获取产品第一个尺寸
|
||||
productSize, err = w.logic.svcCtx.AllModels.FsProductSize.GetProductFirstSize(w.logic.ctx, renderImageData.RenderData.ProductId)
|
||||
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)
|
||||
logx.Error("product size is not found")
|
||||
return
|
||||
}
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品的第一个尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
logx.Error("failed to get product size:", err)
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
renderImageData.RenderData.ProductSizeId = productSize.Id
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取产品的指定尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, renderImageData.RenderData.ProductSizeId, 0)
|
||||
logx.Error("failed to get product size:", err)
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
//获取模型
|
||||
model3d, err = w.logic.svcCtx.AllModels.FsProductModel3d.GetOneBySizeIdTag(w.logic.ctx, productSize.Id, constants.TAG_MODEL)
|
||||
if err != nil {
|
||||
|
@ -295,11 +281,11 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.
|
|||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应的模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0)
|
||||
logx.Error("template info is not found")
|
||||
logx.Error("找不到对应的模板")
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0)
|
||||
logx.Error("failed to get template info:", err)
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应的模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, model3d.Id, productSize.Id, 0)
|
||||
logx.Error("获取对应的模板失败:", err)
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if *productTemplate.ElementModelId <= 0 {
|
||||
|
@ -313,6 +299,46 @@ func (w *wsConnectItem) getProductRelateionInfo(renderImageData *websocket_data.
|
|||
return
|
||||
}
|
||||
|
||||
// 获取模板相关信息(不指定尺寸)
|
||||
func (w *wsConnectItem) getProductRelateionInfoWithNoSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
|
||||
//指定尺寸(尺寸 -> 模型 ->模板)
|
||||
//获取模板
|
||||
productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag, "sort ASC")
|
||||
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)
|
||||
return nil, nil, nil, errors.New("找不到对应开启云渲染模板")
|
||||
}
|
||||
logx.Error(err)
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应开启云渲染模板失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)
|
||||
return nil, nil, nil, errors.New("获取对应开启云渲染模板失败")
|
||||
}
|
||||
//根据模板找到模型
|
||||
model3d, err = w.logic.svcCtx.AllModels.FsProductModel3d.FindOne(w.logic.ctx, *productTemplate.ModelId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应模型", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, 0, 0, 0)
|
||||
return nil, nil, nil, errors.New("找不到对应模型")
|
||||
}
|
||||
logx.Error(err)
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应模型失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, 0, 0, 0)
|
||||
return nil, nil, nil, errors.New("获取对应模型失败")
|
||||
}
|
||||
//根据模型id获取尺寸信息
|
||||
productSize, err = w.logic.svcCtx.AllModels.FsProductSize.FindOne(w.logic.ctx, *model3d.SizeId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应尺寸", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, 0, 0)
|
||||
return nil, nil, nil, errors.New("找不到对应尺寸")
|
||||
}
|
||||
logx.Error(err)
|
||||
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "获取对应尺寸失败", renderImageData.RenderData.ProductId, w.userId, w.guestId, productTemplate.Id, model3d.Id, 0, 0)
|
||||
return nil, nil, nil, errors.New("获取对应尺寸失败")
|
||||
}
|
||||
renderImageData.RenderData.ProductSizeId = productSize.Id
|
||||
return
|
||||
}
|
||||
|
||||
// 组装数据发送给unity
|
||||
func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage string, info websocket_data.RenderImageReqMsg, productTemplate *gmodel.FsProductTemplateV2, model3dInfo *gmodel.FsProductModel3d, element *gmodel.FsProductTemplateElement, productSize *gmodel.FsProductSize) (err error) {
|
||||
//组装数据
|
||||
|
|
|
@ -378,7 +378,8 @@ type PriceItem {
|
|||
}
|
||||
//获取产品尺寸列表
|
||||
type GetSizeByPidReq {
|
||||
Pid string `form:"pid"`
|
||||
Pid string `form:"pid"`
|
||||
TemplateTag string `form:"template_tag"`
|
||||
}
|
||||
type GetSizeByPidRsp {
|
||||
Id int64 `json:"id"` //尺寸id
|
||||
|
|
|
@ -62,7 +62,15 @@ type MaterialItem struct {
|
|||
// 获取模板开关信息(目前写死,以后后台做好了功能再更新变动)
|
||||
func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMaterialImg string) (resp GetTemplateSwitchInfoRsp, err error) {
|
||||
if templateJsonStr == nil || *templateJsonStr == "" {
|
||||
return GetTemplateSwitchInfoRsp{}, nil
|
||||
return GetTemplateSwitchInfoRsp{
|
||||
Id: templateId,
|
||||
Material: templateMaterialImg,
|
||||
MaterialData: MaterialData{
|
||||
Logo: Logo{
|
||||
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
var templateJsonInfo TemplateSimpleParseInfo
|
||||
if err = json.Unmarshal([]byte(*templateJsonStr), &templateJsonInfo); err != nil {
|
||||
|
@ -81,6 +89,8 @@ func GetTemplateSwitchInfo(templateId int64, templateJsonStr *string, templateMa
|
|||
for _, v := range templateJsonInfo.MaterialList {
|
||||
if v.Type == "combine" && !v.Visible {
|
||||
return GetTemplateSwitchInfoRsp{
|
||||
Id: templateId,
|
||||
Material: templateMaterialImg,
|
||||
MaterialData: MaterialData{
|
||||
Logo: Logo{
|
||||
Material: "/image/logo/aHnT1_rzubdwax_scale.png",
|
||||
|
|
Loading…
Reference in New Issue
Block a user