From 6a9650b9d1622c4b4af40ff6cfbb11fb1de1b246 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 19 Jun 2023 14:47:54 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_logic.go | 7 ++ model/gmodel/fs_product_model3d_logic.go | 9 +++ model/gmodel/fs_product_size_logic.go | 2 +- model/gmodel/fs_product_template_v2_logic.go | 2 +- .../internal/logic/getproductdesignlogic.go | 27 +++++-- server/product/internal/types/types.go | 78 ++----------------- server_api/product.api | 73 ++--------------- 7 files changed, 55 insertions(+), 143 deletions(-) diff --git a/model/gmodel/fs_product_logic.go b/model/gmodel/fs_product_logic.go index 5d5a9ed1..0352a538 100755 --- a/model/gmodel/fs_product_logic.go +++ b/model/gmodel/fs_product_logic.go @@ -2,6 +2,13 @@ package gmodel import "context" +func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp FsProduct, err error) { + err = p.db.Model(&FsProduct{}).Where("`id` = ? and `is_del` =? and `is_shelf` = ? and `status` =?", id, 0, 1, 1).First(&resp).Error + if err != nil { + return FsProduct{}, err + } + return resp, nil +} func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) { if len(productIds) == 0 { return diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 9e3e604b..38221264 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -2,8 +2,17 @@ package gmodel import ( "context" + "errors" + "gorm.io/gorm" ) +func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp FsProductModel3d, err error) { + err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).Find(&resp).Error + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return FsProductModel3d{}, err + } + return resp, nil +} func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3d, err error) { if len(ids) == 0 { return diff --git a/model/gmodel/fs_product_size_logic.go b/model/gmodel/fs_product_size_logic.go index 4988094e..68fe85e7 100755 --- a/model/gmodel/fs_product_size_logic.go +++ b/model/gmodel/fs_product_size_logic.go @@ -7,7 +7,7 @@ import ( ) func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64) (resp FsProductSize, err error) { - err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? and `status` = ?", id, 1).First(&resp).Error + err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id).First(&resp).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return FsProductSize{}, err } diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 57614e56..eb9492f7 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -28,7 +28,7 @@ func (t *FsProductTemplateV2Model) FindAllByIds(ctx context.Context, ids []int64 } func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp FsProductTemplateV2, err error) { - err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? and `is_del` = ? and `status` = ?", id, 0, 1).Find(&resp).Error + err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Find(&resp).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return FsProductTemplateV2{}, err } diff --git a/server/product/internal/logic/getproductdesignlogic.go b/server/product/internal/logic/getproductdesignlogic.go index cf345334..b1bf08d8 100644 --- a/server/product/internal/logic/getproductdesignlogic.go +++ b/server/product/internal/logic/getproductdesignlogic.go @@ -1,7 +1,6 @@ package logic import ( - "encoding/json" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -65,11 +64,27 @@ func (l *GetProductDesignLogic) GetProductDesign(req *types.GetProductDesignReq, if productTemplateV2Info.Id == 0 { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template info is not exists") } - //解析json - var info types.ProductDesignInfo - if err = json.Unmarshal([]byte(*designInfo.Info), &info); err != nil { + //获取产品模型信息 + productModel3dModel := gmodel.NewFsProductModel3dModel(l.svcCtx.MysqlConn) + model3dInfo, err := productModel3dModel.FindOne(l.ctx, *designInfo.OptionalId) + if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse design info") + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product 3D model info") } - return resp.SetStatus(basic.CodeOK) + if model3dInfo.Id == 0 { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product 3D model info is not exists") + } + optionalId := *designInfo.OptionalId + if *model3dInfo.Status == 0 && *sizeInfo.Status == 1 && *productTemplateV2Info.Status == 1 && *productTemplateV2Info.IsDel == 0 { + optionalId = 0 + } + return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductDesignRsp{ + ProductId: *designInfo.ProductId, + TemplateId: *designInfo.TemplateId, + MaterialId: *designInfo.MaterialId, + SizeId: *designInfo.SizeId, + OptionalId: optionalId, + Cover: *designInfo.Cover, + Info: *designInfo.Info, + }) } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index ba4a4496..6ad4ae2c 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -97,79 +97,17 @@ type PriceObj struct { } type GetProductDesignReq struct { - Sn string `json:"sn"` + Sn string `form:"sn"` } type GetProductDesignRsp struct { - ProductId int64 `json:"product_id"` - TemplateId int64 `json:"template_id"` - MaterialId int64 `json:"material_id"` - SizeId int64 `json:"size_id"` - OptionalId int64 `json:"optional_id"` - Cover string `json:"cover"` - Info []ProductDesignInfo `json:"info"` -} - -type ProductDesignInfo struct { - Id string `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int64 `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int64 `json:"maxNum"` - Rotation int64 `json:"rotation"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - QRcodeType string `json:"QRcodeType"` - Width int64 `json:"width"` - Height int64 `json:"height"` - X int64 `json:"x"` - Y int64 `json:"y"` - Opacity int64 `json:"opacity"` - OptionalColor []OptionalColor `json:"optionalColor"` - ZIndex int64 `json:"zIndex"` - SvgPath string `json:"svgPath"` - MaterialName string `json:"materialName"` - MaterialTime string `json:"materialTime"` - Follow DesignFollow `json:"follow"` - Group []DesignGroup `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} - -type CameraStand struct { - X int64 `json:"x"` - Y int64 `json:"y"` - Z int64 `json:"z"` -} - -type DesignGroup struct { - Tag string `json:"tag"` - Text string `json:"text"` - Title string `json:"title"` - IfBr bool `json:"ifBr"` - IfGroupNoBr bool `json:"ifGroupNoBr"` - IfShow bool `json:"ifShow"` - MaxNum int64 `json:"maxNum"` - PaddingNum int64 `json:"paddingNum"` -} - -type DesignFollow struct { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} - -type OptionalColor struct { - Color string `json:"color"` - Name string `json:"name"` - Default bool `json:"default"` + ProductId int64 `json:"product_id"` + TemplateId int64 `json:"template_id"` + MaterialId int64 `json:"material_id"` + SizeId int64 `json:"size_id"` + OptionalId int64 `json:"optional_id"` + Cover string `json:"cover"` + Info string `json:"info"` } type Response struct { diff --git a/server_api/product.api b/server_api/product.api index f7beab16..6d344547 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -107,71 +107,14 @@ type PriceObj { //获取保存的设计信息 type GetProductDesignReq { - Sn string `json:"sn"` + Sn string `form:"sn"` } type GetProductDesignRsp { - ProductId int64 `json:"product_id"` - TemplateId int64 `json:"template_id"` - MaterialId int64 `json:"material_id"` - SizeId int64 `json:"size_id"` - OptionalId int64 `json:"optional_id"` - Cover string `json:"cover"` - Info []ProductDesignInfo `json:"info"` -} -type ProductDesignInfo { - Id string `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int64 `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int64 `json:"maxNum"` - Rotation int64 `json:"rotation"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - QRcodeType string `json:"QRcodeType"` - Width int64 `json:"width"` - Height int64 `json:"height"` - X int64 `json:"x"` - Y int64 `json:"y"` - Opacity int64 `json:"opacity"` - OptionalColor []OptionalColor `json:"optionalColor"` - ZIndex int64 `json:"zIndex"` - SvgPath string `json:"svgPath"` - MaterialName string `json:"materialName"` - MaterialTime string `json:"materialTime"` - Follow DesignFollow `json:"follow"` - Group []DesignGroup `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} -type CameraStand { - X int64 `json:"x"` - Y int64 `json:"y"` - Z int64 `json:"z"` -} -type DesignGroup { - Tag string `json:"tag"` - Text string `json:"text"` - Title string `json:"title"` - IfBr bool `json:"ifBr"` - IfGroupNoBr bool `json:"ifGroupNoBr"` - IfShow bool `json:"ifShow"` - MaxNum int64 `json:"maxNum"` - PaddingNum int64 `json:"paddingNum"` -} -type DesignFollow { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} -type OptionalColor { - Color string `json:"color"` - Name string `json:"name"` - Default bool `json:"default"` + ProductId int64 `json:"product_id"` + TemplateId int64 `json:"template_id"` + MaterialId int64 `json:"material_id"` + SizeId int64 `json:"size_id"` + OptionalId int64 `json:"optional_id"` + Cover string `json:"cover"` + Info string `json:"info"` } \ No newline at end of file