From eef4bb35c9cfef64005ae843f73df2dd142cbe06 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 19 Jun 2023 10:34:21 +0800 Subject: [PATCH 1/4] 1 --- .../handler/getproductdesignhandler.go | 66 +++++++++++++++++++ server/product/internal/handler/routes.go | 5 ++ .../internal/logic/getproductdesignlogic.go | 34 ++++++++++ server/product/internal/svc/servicecontext.go | 2 +- server_api/product.api | 7 +- 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 server/product/internal/handler/getproductdesignhandler.go create mode 100644 server/product/internal/logic/getproductdesignlogic.go diff --git a/server/product/internal/handler/getproductdesignhandler.go b/server/product/internal/handler/getproductdesignhandler.go new file mode 100644 index 00000000..b6f3ae2d --- /dev/null +++ b/server/product/internal/handler/getproductdesignhandler.go @@ -0,0 +1,66 @@ +package handler + +import ( + "errors" + "net/http" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/rest/httpx" + + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "fusenapi/server/product/internal/logic" + "fusenapi/server/product/internal/svc" +) + +func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var ( + // 定义错误变量 + err error + // 定义用户信息变量 + userinfo *auth.UserInfo + ) + // 解析JWT token,并对空用户进行判断 + claims, err := svcCtx.ParseJwtToken(r) + // 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, // 返回401状态码,表示未授权 + Message: "unauthorized", // 返回未授权信息 + }) + logx.Info("unauthorized:", err.Error()) // 记录错误日志 + return + } + + if claims != nil { + // 从token中获取对应的用户信息 + userinfo, err = auth.GetUserInfoFormMapClaims(claims) + // 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息 + if err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 401, + Message: "unauthorized", + }) + logx.Info("unauthorized:", err.Error()) + return + } + } else { + // 如果claims为nil,则认为用户身份为白板用户 + userinfo = &auth.UserInfo{UserId: 0, GuestId: 0} + } + + l := logic.NewGetProductDesignLogic(r.Context(), svcCtx) + resp := l.GetProductDesign(userinfo) + // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; + if resp != nil { + httpx.OkJsonCtx(r.Context(), w, resp) + } else { + err := errors.New("server logic is error, resp must not be nil") + httpx.ErrorCtx(r.Context(), w, err) + logx.Error(err) + } + } +} diff --git a/server/product/internal/handler/routes.go b/server/product/internal/handler/routes.go index 0599e7f7..847df645 100644 --- a/server/product/internal/handler/routes.go +++ b/server/product/internal/handler/routes.go @@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/product/get-size-by-product", Handler: GetSizeByProductHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/product/design", + Handler: GetProductDesignHandler(serverCtx), + }, }, ) } diff --git a/server/product/internal/logic/getproductdesignlogic.go b/server/product/internal/logic/getproductdesignlogic.go new file mode 100644 index 00000000..1b72836f --- /dev/null +++ b/server/product/internal/logic/getproductdesignlogic.go @@ -0,0 +1,34 @@ +package logic + +import ( + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetProductDesignLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetProductDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductDesignLogic { + return &GetProductDesignLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetProductDesignLogic) GetProductDesign(, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + + return resp.SetStatus(basic.CodeOK) +} diff --git a/server/product/internal/svc/servicecontext.go b/server/product/internal/svc/servicecontext.go index 0a60e492..e262fa80 100644 --- a/server/product/internal/svc/servicecontext.go +++ b/server/product/internal/svc/servicecontext.go @@ -20,7 +20,7 @@ func NewServiceContext(c config.Config) *ServiceContext { return &ServiceContext{ Config: c, - MysqlConn: initalize.InitMysql(c.DataSource), + MysqlConn: initalize.InitMysql(c.SourceMysql), } } diff --git a/server_api/product.api b/server_api/product.api index fd3f2e7e..69af0dad 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -12,11 +12,14 @@ service product { @handler GetProductListHandler get /product/list(GetProductListReq) returns (response); //获取成功后的推荐产品 - @handler GetSuccessRecommand + @handler GetSuccessRecommandHandler get /product/success-recommand (GetSuccessRecommandReq) returns (response); //获取分类下的产品以及尺寸 - @handler GetSizeByProduct + @handler GetSizeByProductHandler get /product/get-size-by-product returns (response); + //获取保存的设计 + @handler GetProductDesignHandler + get /product/design returns (response); } //获取产品列表 From bbb1a845ad2c9df7668fd7454ab5a94507c805d5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 19 Jun 2023 12:23:02 +0800 Subject: [PATCH 2/4] fix --- model/gmodel/fs_product_design_logic.go | 4 +- model/gmodel/fs_product_size_logic.go | 9 +++ model/gmodel/fs_product_template_v2_logic.go | 22 +++++- server/product/internal/config/config.go | 4 +- .../handler/getproductdesignhandler.go | 14 +++- .../internal/logic/getproductdesignlogic.go | 51 +++++++++++-- server/product/internal/types/types.go | 76 +++++++++++++++++++ .../internal/logic/cartaddlogic.go | 2 +- .../internal/logic/cartlistlogic.go | 2 +- server_api/product.api | 75 +++++++++++++++++- 10 files changed, 244 insertions(+), 15 deletions(-) diff --git a/model/gmodel/fs_product_design_logic.go b/model/gmodel/fs_product_design_logic.go index a428e14a..980b0ba3 100755 --- a/model/gmodel/fs_product_design_logic.go +++ b/model/gmodel/fs_product_design_logic.go @@ -7,8 +7,8 @@ import ( "gorm.io/gorm" ) -func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string) (resp FsProductDesign, err error) { - err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`sn` = ? and `status` = ?", sn, 1).First(&resp).Error +func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string, userId int64) (resp FsProductDesign, err error) { + err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`sn` = ? and `user_id` = ? and `status` = ?", sn, userId, 1).First(&resp).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return FsProductDesign{}, err } diff --git a/model/gmodel/fs_product_size_logic.go b/model/gmodel/fs_product_size_logic.go index a48d46bf..4988094e 100755 --- a/model/gmodel/fs_product_size_logic.go +++ b/model/gmodel/fs_product_size_logic.go @@ -2,8 +2,17 @@ package gmodel import ( "context" + "errors" + "gorm.io/gorm" ) +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 + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return FsProductSize{}, err + } + return resp, nil +} func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) { if len(ids) == 0 { return diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index e31f35fe..57614e56 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -2,15 +2,35 @@ package gmodel import ( "context" + "errors" + "gorm.io/gorm" ) func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64) (resp []FsProductTemplateV2, err error) { if len(productIds) == 0 { return } - err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error + err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error if err != nil { return nil, err } return } +func (t *FsProductTemplateV2Model) FindAllByIds(ctx context.Context, ids []int64) (resp []FsProductTemplateV2, err error) { + if len(ids) == 0 { + return + } + err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", ids, 0, 1).Find(&resp).Error + if err != nil { + return nil, err + } + return +} +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 + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + return FsProductTemplateV2{}, err + } + return resp, nil +} diff --git a/server/product/internal/config/config.go b/server/product/internal/config/config.go index 926fad3e..e8559019 100644 --- a/server/product/internal/config/config.go +++ b/server/product/internal/config/config.go @@ -7,6 +7,6 @@ import ( type Config struct { rest.RestConf - DataSource string - Auth types.Auth + SourceMysql string + Auth types.Auth } diff --git a/server/product/internal/handler/getproductdesignhandler.go b/server/product/internal/handler/getproductdesignhandler.go index b6f3ae2d..53bcbfe0 100644 --- a/server/product/internal/handler/getproductdesignhandler.go +++ b/server/product/internal/handler/getproductdesignhandler.go @@ -12,6 +12,7 @@ import ( "fusenapi/server/product/internal/logic" "fusenapi/server/product/internal/svc" + "fusenapi/server/product/internal/types" ) func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -52,8 +53,19 @@ func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { userinfo = &auth.UserInfo{UserId: 0, GuestId: 0} } + var req types.GetProductDesignReq + // 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据 + if err := httpx.Parse(r, &req); err != nil { + httpx.OkJsonCtx(r.Context(), w, &basic.Response{ + Code: 510, + Message: "parameter error", + }) + logx.Info(err) + return + } + // 创建一个业务逻辑层实例 l := logic.NewGetProductDesignLogic(r.Context(), svcCtx) - resp := l.GetProductDesign(userinfo) + resp := l.GetProductDesign(&req, userinfo) // 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应; if resp != nil { httpx.OkJsonCtx(r.Context(), w, resp) diff --git a/server/product/internal/logic/getproductdesignlogic.go b/server/product/internal/logic/getproductdesignlogic.go index 1b72836f..cf345334 100644 --- a/server/product/internal/logic/getproductdesignlogic.go +++ b/server/product/internal/logic/getproductdesignlogic.go @@ -1,6 +1,8 @@ package logic import ( + "encoding/json" + "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -26,9 +28,48 @@ func NewGetProductDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) * } } -func (l *GetProductDesignLogic) GetProductDesign(, userinfo *auth.UserInfo) (resp *basic.Response) { - // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) - // userinfo 传入值时, 一定不为null - - return resp.SetStatus(basic.CodeOK) +func (l *GetProductDesignLogic) GetProductDesign(req *types.GetProductDesignReq, userinfo *auth.UserInfo) (resp *basic.Response) { + if userinfo.GetIdType() != auth.IDTYPE_User { + return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first") + } + if req.Sn == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required") + } + //获取设计数据 + productDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn) + designInfo, err := productDesignModel.FindOneBySn(l.ctx, req.Sn, userinfo.UserId) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get design info") + } + if designInfo.Id == 0 { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "design info is not exists") + } + //获取产品尺寸信息 + productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn) + sizeInfo, err := productSizeModel.FindOne(l.ctx, *designInfo.SizeId) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size info") + } + if sizeInfo.Id == 0 { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "product size info is not exists") + } + //获取模板信息 + productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) + productTemplateV2Info, err := productTemplateV2Model.FindOne(l.ctx, *designInfo.TemplateId) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get template info") + } + 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 { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse design info") + } + return resp.SetStatus(basic.CodeOK) } diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 1b74bab6..ba4a4496 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -96,6 +96,82 @@ type PriceObj struct { Price float64 `json:"price"` } +type GetProductDesignReq struct { + Sn string `json:"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"` +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go b/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go index c4114978..74bb23ba 100644 --- a/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go +++ b/server/shopping-cart-confirmation/internal/logic/cartaddlogic.go @@ -46,7 +46,7 @@ func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) ( } //查询是否有此设计 productDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn) - productDesignInfo, err := productDesignModel.FindOneBySn(l.ctx, req.DesignId) + productDesignInfo, err := productDesignModel.FindOneBySn(l.ctx, req.DesignId, userinfo.UserId) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product design info") diff --git a/server/shopping-cart-confirmation/internal/logic/cartlistlogic.go b/server/shopping-cart-confirmation/internal/logic/cartlistlogic.go index ba4cb95c..8e57a5aa 100644 --- a/server/shopping-cart-confirmation/internal/logic/cartlistlogic.go +++ b/server/shopping-cart-confirmation/internal/logic/cartlistlogic.go @@ -244,7 +244,7 @@ func (l *CartListLogic) getUserCartRelativeList(ctx context.Context, userId int6 go func() { defer wait.Done() productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) - templateV2List, err := productTemplateModel.FindAllByProductIds(ctx, templateIds) + templateV2List, err := productTemplateModel.FindAllByIds(ctx, templateIds) if err != nil { errChan <- err } diff --git a/server_api/product.api b/server_api/product.api index 69af0dad..f7beab16 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -17,9 +17,9 @@ service product { //获取分类下的产品以及尺寸 @handler GetSizeByProductHandler get /product/get-size-by-product returns (response); - //获取保存的设计 + //获取保存的设计信息 @handler GetProductDesignHandler - get /product/design returns (response); + get /product/design(GetProductDesignReq) returns (response); } //获取产品列表 @@ -103,4 +103,75 @@ type ChildrenObj { type PriceObj { Num int `json:"num"` Price float64 `json:"price"` +} + +//获取保存的设计信息 +type GetProductDesignReq { + Sn string `json:"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"` } \ No newline at end of file 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 3/4] 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 From 7a19292ae2c49b19248195ddea329f00eceeb793 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 19 Jun 2023 14:53:21 +0800 Subject: [PATCH 4/4] fix --- .../internal/logic/getmaplibrarylistlogic.go | 9 +-- server/map-library/internal/types/types.go | 68 ++----------------- server_api/map-library.api | 63 ++--------------- 3 files changed, 9 insertions(+), 131 deletions(-) diff --git a/server/map-library/internal/logic/getmaplibrarylistlogic.go b/server/map-library/internal/logic/getmaplibrarylistlogic.go index 762a5451..97eb8193 100644 --- a/server/map-library/internal/logic/getmaplibrarylistlogic.go +++ b/server/map-library/internal/logic/getmaplibrarylistlogic.go @@ -1,7 +1,6 @@ package logic import ( - "encoding/json" "fusenapi/model/gmodel" "fusenapi/server/map-library/internal/svc" "fusenapi/server/map-library/internal/types" @@ -60,6 +59,7 @@ func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (res data := types.GetMapLibraryListRsp{ Mid: v.Id, Ctime: time.Unix(*v.Ctime, 0).Format("2006-01-02 15:04:05"), + Info: *v.Info, } //tag拼装 if tagIndex, ok := mapTag[*v.TagId]; ok { @@ -68,13 +68,6 @@ func (l *GetMapLibraryListLogic) GetMapLibraryList(userinfo *auth.UserInfo) (res Title: *templateTagList[tagIndex].Title, } } - //解析info - var info types.MapLibraryListInfo - if err = json.Unmarshal([]byte(*v.Info), &info); err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "json parse info err") - } - data.Info = info list = append(list, data) } return resp.SetStatusWithMessage(basic.CodeOK, "success", list) diff --git a/server/map-library/internal/types/types.go b/server/map-library/internal/types/types.go index 75af6051..6ea4f440 100644 --- a/server/map-library/internal/types/types.go +++ b/server/map-library/internal/types/types.go @@ -6,70 +6,10 @@ import ( ) type GetMapLibraryListRsp struct { - Mid int64 `json:"mid"` - Ctime string `json:"ctime"` - Tag MapLibraryListTag `json:"tag"` - Info MapLibraryListInfo `json:"info"` -} - -type MapLibraryListInfo 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 int64 `json:"QRcodeType"` - Width float64 `json:"width"` - Height float64 `json:"height"` - X float64 `json:"x"` - Y float64 `json:"y"` - Opacity float64 `json:"opacity"` - OptionalColor []MapLibraryListOptionalColorItem `json:"optionalColor"` - ZIndex int64 `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow MapLibraryListFollow `json:"follow"` - Group []MapLibraryListGroup `json:"group"` - CameraStand MapLibraryListCameraStand `json:"cameraStand"` - MaterialTime string `json:"materialTime"` - MaterialName string `json:"materialName"` -} - -type MapLibraryListCameraStand struct { - X int64 `json:"x"` - Y int64 `json:"y"` - Z int64 `json:"z"` -} - -type MapLibraryListGroup struct { - Tag string `json:"tag"` - Text string `json:"text"` - Title string `json:"title"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - MaxNum int64 `json:"maxNum"` -} - -type MapLibraryListFollow struct { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} - -type MapLibraryListOptionalColorItem struct { - Color string `json:"color"` - Name string `json:"name"` - Default bool `json:"default"` + Mid int64 `json:"mid"` + Ctime string `json:"ctime"` + Tag MapLibraryListTag `json:"tag"` + Info string `json:"info"` } type MapLibraryListTag struct { diff --git a/server_api/map-library.api b/server_api/map-library.api index db3a3436..d182e68c 100644 --- a/server_api/map-library.api +++ b/server_api/map-library.api @@ -16,65 +16,10 @@ service map-library { //获取贴图库列表 type GetMapLibraryListRsp { - Mid int64 `json:"mid"` - Ctime string `json:"ctime"` - Tag MapLibraryListTag `json:"tag"` - Info MapLibraryListInfo `json:"info"` -} -type MapLibraryListInfo { - 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 int64 `json:"QRcodeType"` - Width float64 `json:"width"` - Height float64 `json:"height"` - X float64 `json:"x"` - Y float64 `json:"y"` - Opacity float64 `json:"opacity"` - OptionalColor []MapLibraryListOptionalColorItem `json:"optionalColor"` - ZIndex int64 `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow MapLibraryListFollow `json:"follow"` - Group []MapLibraryListGroup `json:"group"` - CameraStand MapLibraryListCameraStand `json:"cameraStand"` - MaterialTime string `json:"materialTime"` - MaterialName string `json:"materialName"` -} -type MapLibraryListCameraStand { - X int64 `json:"x"` - Y int64 `json:"y"` - Z int64 `json:"z"` -} -type MapLibraryListGroup { - Tag string `json:"tag"` - Text string `json:"text"` - Title string `json:"title"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - MaxNum int64 `json:"maxNum"` -} -type MapLibraryListFollow { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} -type MapLibraryListOptionalColorItem { - Color string `json:"color"` - Name string `json:"name"` - Default bool `json:"default"` + Mid int64 `json:"mid"` + Ctime string `json:"ctime"` + Tag MapLibraryListTag `json:"tag"` + Info string `json:"info"` } type MapLibraryListTag { Id int64 `json:"id"`