From cf3a02ae7efcec664118684c99e126dce2a2f4a6 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 15:01:13 +0800 Subject: [PATCH] fix --- constants/product_model3d.go | 5 + ddl/fs_product_model3d_light.sql | 10 ++ model/fsproductmodel3dlightmodel.go | 24 ++++ model/fsproductmodel3dlightmodel_gen.go | 88 ++++++++++++ model/fsproducttemplatev2model_gen.go | 1 + model/self_fsproductmodel3dlightmodel.go | 18 +++ model/self_fsproducttemplatev2model.go | 17 +++ .../internal/handler/getproductinfohandler.go | 39 ------ product/internal/handler/routes.go | 5 - product/internal/logic/getproductinfologic.go | 127 ------------------ product/internal/types/types.go | 102 -------------- server_api/product.api | 96 ------------- 12 files changed, 163 insertions(+), 369 deletions(-) create mode 100644 constants/product_model3d.go create mode 100644 ddl/fs_product_model3d_light.sql create mode 100755 model/fsproductmodel3dlightmodel.go create mode 100755 model/fsproductmodel3dlightmodel_gen.go create mode 100755 model/self_fsproductmodel3dlightmodel.go delete mode 100644 product/internal/handler/getproductinfohandler.go delete mode 100644 product/internal/logic/getproductinfologic.go diff --git a/constants/product_model3d.go b/constants/product_model3d.go new file mode 100644 index 00000000..6f3dc937 --- /dev/null +++ b/constants/product_model3d.go @@ -0,0 +1,5 @@ +package constants + +const TAG_MODEL = 1 //模型 +const TAG_PARTS = 2 //配件 +const TAG_SCENE = 3 //场景 diff --git a/ddl/fs_product_model3d_light.sql b/ddl/fs_product_model3d_light.sql new file mode 100644 index 00000000..2f2f33e7 --- /dev/null +++ b/ddl/fs_product_model3d_light.sql @@ -0,0 +1,10 @@ +-- fusentest.fs_product_model3d_light definition + +CREATE TABLE `fs_product_model3d_light` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL COMMENT '灯光名称', + `info` text NOT NULL COMMENT '灯光数据(json格式)', + `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态值(1:显示,0:删除)', + `ctime` int(11) DEFAULT NULL COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='模型-灯光组表'; \ No newline at end of file diff --git a/model/fsproductmodel3dlightmodel.go b/model/fsproductmodel3dlightmodel.go new file mode 100755 index 00000000..9af5f0a5 --- /dev/null +++ b/model/fsproductmodel3dlightmodel.go @@ -0,0 +1,24 @@ +package model + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ FsProductModel3dLightModel = (*customFsProductModel3dLightModel)(nil) + +type ( + // FsProductModel3dLightModel is an interface to be customized, add more methods here, + // and implement the added methods in customFsProductModel3dLightModel. + FsProductModel3dLightModel interface { + fsProductModel3dLightModel + } + + customFsProductModel3dLightModel struct { + *defaultFsProductModel3dLightModel + } +) + +// NewFsProductModel3dLightModel returns a model for the database table. +func NewFsProductModel3dLightModel(conn sqlx.SqlConn) FsProductModel3dLightModel { + return &customFsProductModel3dLightModel{ + defaultFsProductModel3dLightModel: newFsProductModel3dLightModel(conn), + } +} diff --git a/model/fsproductmodel3dlightmodel_gen.go b/model/fsproductmodel3dlightmodel_gen.go new file mode 100755 index 00000000..89b35c5b --- /dev/null +++ b/model/fsproductmodel3dlightmodel_gen.go @@ -0,0 +1,88 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "database/sql" + "fmt" + "strings" + + "github.com/zeromicro/go-zero/core/stores/builder" + "github.com/zeromicro/go-zero/core/stores/sqlc" + "github.com/zeromicro/go-zero/core/stores/sqlx" + "github.com/zeromicro/go-zero/core/stringx" +) + +var ( + fsProductModel3dLightFieldNames = builder.RawFieldNames(&FsProductModel3dLight{}) + fsProductModel3dLightRows = strings.Join(fsProductModel3dLightFieldNames, ",") + fsProductModel3dLightRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductModel3dLightFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + fsProductModel3dLightRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductModel3dLightFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + fsProductModel3dLightModel interface { + Insert(ctx context.Context, data *FsProductModel3dLight) (sql.Result, error) + FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error) + Update(ctx context.Context, data *FsProductModel3dLight) error + Delete(ctx context.Context, id int64) error + ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error) + } + + defaultFsProductModel3dLightModel struct { + conn sqlx.SqlConn + table string + } + + FsProductModel3dLight struct { + Id int64 `db:"id"` + Name string `db:"name"` // 灯光名称 + Info string `db:"info"` // 灯光数据(json格式) + Status int64 `db:"status"` // 状态值(1:显示,0:删除) + Ctime sql.NullInt64 `db:"ctime"` // 创建时间 + } +) + +func newFsProductModel3dLightModel(conn sqlx.SqlConn) *defaultFsProductModel3dLightModel { + return &defaultFsProductModel3dLightModel{ + conn: conn, + table: "`fs_product_model3d_light`", + } +} + +func (m *defaultFsProductModel3dLightModel) Delete(ctx context.Context, id int64) error { + query := fmt.Sprintf("delete from %s where `id` = ?", m.table) + _, err := m.conn.ExecCtx(ctx, query, id) + return err +} + +func (m *defaultFsProductModel3dLightModel) FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductModel3dLightRows, m.table) + var resp FsProductModel3dLight + err := m.conn.QueryRowCtx(ctx, &resp, query, id) + switch err { + case nil: + return &resp, nil + case sqlc.ErrNotFound: + return nil, ErrNotFound + default: + return nil, err + } +} + +func (m *defaultFsProductModel3dLightModel) Insert(ctx context.Context, data *FsProductModel3dLight) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsProductModel3dLightRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Info, data.Status, data.Ctime) + return ret, err +} + +func (m *defaultFsProductModel3dLightModel) Update(ctx context.Context, data *FsProductModel3dLight) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductModel3dLightRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, data.Name, data.Info, data.Status, data.Ctime, data.Id) + return err +} + +func (m *defaultFsProductModel3dLightModel) tableName() string { + return m.table +} diff --git a/model/fsproducttemplatev2model_gen.go b/model/fsproducttemplatev2model_gen.go index d3cd0ef2..bfdb8cf0 100755 --- a/model/fsproducttemplatev2model_gen.go +++ b/model/fsproducttemplatev2model_gen.go @@ -29,6 +29,7 @@ type ( Delete(ctx context.Context, id int64) error FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) + FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error) } defaultFsProductTemplateV2Model struct { diff --git a/model/self_fsproductmodel3dlightmodel.go b/model/self_fsproductmodel3dlightmodel.go new file mode 100755 index 00000000..4d9a6ce9 --- /dev/null +++ b/model/self_fsproductmodel3dlightmodel.go @@ -0,0 +1,18 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" + "strings" +) + +func (m *defaultFsProductModel3dLightModel) ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error) { + query := fmt.Sprintf("select %s from %s where `id` in (?)", fsProductModel3dLightRows, m.table) + err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(ids, ",")) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproducttemplatev2model.go b/model/self_fsproducttemplatev2model.go index b5ac10d1..b7c23539 100755 --- a/model/self_fsproducttemplatev2model.go +++ b/model/self_fsproducttemplatev2model.go @@ -31,3 +31,20 @@ func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.C } return } + +func (m *defaultFsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error) { + if len(modelIds) == 0 { + return + } + query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table) + switch sort { + case 1: + query = fmt.Sprintf("%s order by `sort` ASC", query) + case 2: + query = fmt.Sprintf("%s order by `sort` DESC", query) + } + if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), 0, 1); err != nil { + return nil, err + } + return +} diff --git a/product/internal/handler/getproductinfohandler.go b/product/internal/handler/getproductinfohandler.go deleted file mode 100644 index 21acd4e9..00000000 --- a/product/internal/handler/getproductinfohandler.go +++ /dev/null @@ -1,39 +0,0 @@ -package handler - -import ( - "errors" - "fusenapi/utils/auth" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/product/internal/logic" - "fusenapi/product/internal/svc" - "fusenapi/product/internal/types" -) - -func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - //用户登录信息 - userInfo := auth.CheckAuth(r) - var req types.GetProductInfoReq - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - l := logic.NewGetProductInfoLogic(r.Context(), svcCtx) - resp := l.GetProductInfo(&req, userInfo) - 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/product/internal/handler/routes.go b/product/internal/handler/routes.go index 278cd1ef..18f67cbc 100644 --- a/product/internal/handler/routes.go +++ b/product/internal/handler/routes.go @@ -17,11 +17,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/product/list", Handler: GetProductListHandler(serverCtx), }, - { - Method: http.MethodGet, - Path: "/product/info", - Handler: GetProductInfoHandler(serverCtx), - }, }, ) } diff --git a/product/internal/logic/getproductinfologic.go b/product/internal/logic/getproductinfologic.go deleted file mode 100644 index e79e0c98..00000000 --- a/product/internal/logic/getproductinfologic.go +++ /dev/null @@ -1,127 +0,0 @@ -package logic - -import ( - "context" - "errors" - "fmt" - "fusenapi/model" - "fusenapi/product/internal/svc" - "fusenapi/product/internal/types" - "fusenapi/utils/auth" - "fusenapi/utils/image" - "github.com/zeromicro/go-zero/core/stores/sqlc" - "strings" - - "github.com/zeromicro/go-zero/core/logx" -) - -type GetProductInfoLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductInfoLogic { - return &GetProductInfoLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 获取产品详情 -func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response) { - loginInfo.UserId = 83 - //校验前台登录情况 - if loginInfo.UserId == 0 { - return &types.Response{Code: 402, Message: "please sign in"} - } - req.Pid = strings.Trim(req.Pid, " ") - req.ClientNo = strings.Trim(req.ClientNo, " ") - if req.Size > 0 { - req.Size = image.GetCurrentSize(req.Size) - } - //获取产品详情 - productModel := model.NewFsProductModel(l.svcCtx.MysqlConn) - productInfo, err := productModel.FindOneBySn(l.ctx, req.Pid) - if err != nil && !errors.Is(err, sqlc.ErrNotFound) { - logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get product info"} - } - if productInfo == nil { - return &types.Response{Code: 510, Message: "product not found"} - } - //获取产品标签 - /*tagModel := model.NewFsTagsModel(l.svcCtx.MysqlConn) - tagInfo, err := tagModel.FindOne(l.ctx, productInfo.Type) - if err != nil { - logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get product tag"} - }*/ - //获取产品尺寸列表 - productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn) - productSizeList, err := productSizeModel.FindAllByStatus(l.ctx, 1, 1) - if err != nil { - logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get product size list"} - } - sizeIds := make([]string, 0, len(productSizeList)) - for _, v := range productSizeList { - sizeIds = append(sizeIds, fmt.Sprintf("%d", v.Id)) - } - //获取这些尺寸下的模型数据 - productModel3dModel := model.NewFsProductModel3dModel(l.svcCtx.MysqlConn) - models, err := productModel3dModel.ListBySizeIdsTag(l.ctx, sizeIds, 1) - if err != nil { - logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get product models"} - } - modelIds := make([]string, 0, len(models)) - optionTemplateIds := make([]string, 0, len(models)) - for _, v := range models { - modelIds = append(modelIds, fmt.Sprintf("%d", v.Id)) - optionTemplateIds = append(optionTemplateIds, fmt.Sprintf("%d", v.OptionTemplate.Int64)) - } - //通过产品id和模型id获取模板信息 - productTemplateV2Model := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) - templateV2List, err := productTemplateV2Model.FindAllByModelIdsProduct(l.ctx, modelIds, productInfo.Id, 2) - if err != nil { - logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get templates"} - } - //获取模板包含的model_id - mapTemplateModelId := make(map[int64]struct{}) - tagIds := make([]string, 0, len(templateV2List)) - for _, v := range templateV2List { - mapTemplateModelId[v.ModelId] = struct{}{} - tagIds = append(tagIds, v.Tag) - } - /*//获取模板分类类表 - templateTagsModel := model.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn) - templateTags, err := templateTagsModel.ListByIds(l.ctx, tagIds) - if err != nil { - logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get template tags"} - } - //TODO 组装sizes - sizesRsp := make([]types.Sizes, 0, len(productSizeList)) - for _, v := range productSizeList { - //没有模型信息跳过 - if _, ok := mapTemplateModelId[v.Id]; !ok { - continue - } - var title types.SizeTitle - if err = json.Unmarshal([]byte(v.Title), &title); err != nil { - logx.Error(err) - return &types.Response{Code: 510, Message: "err title format"} - } - sizesRsp = append(sizesRsp, types.Sizes{ - Id: v.Id, - Title: title, - Capacity: v.Capacity, - Cover: v.Cover.String, - }) - }*/ - //组装材料 - return &types.Response{} -} diff --git a/product/internal/types/types.go b/product/internal/types/types.go index a272da22..0c24482f 100644 --- a/product/internal/types/types.go +++ b/product/internal/types/types.go @@ -56,108 +56,6 @@ type Items struct { CoverDefault string `json:"coverDefault"` } -type GetProductInfoReq struct { - Pid string `form:"pid"` //sn - Size uint32 `form:"size"` //图片尺寸 - ClientNo string `form:"clientNo"` //页面标识 - HaveCloudRendering bool `form:"haveCloudRendering"` //是否显示云渲染开关 -} - -type GetProductInfoRsp struct { - Id int64 `json:"id"` - Type int32 `json:"type"` - Title string `json:"title"` - IsEnv uint32 `json:"isEnv"` - IsMicro uint32 `json:"isMicro"` - Materials []Materials `json:"materials"` - Sizes []Sizes `json:"sizes"` - TypeName string `json:"typeName"` - Templates Templates `json:"templates"` -} - -type Materials struct { - Id int64 `json:"id"` - Title string `json:"title"` -} - -type Sizes struct { - Id int64 `json:"id"` - Title SizeTitle `json:"title"` - Capacity string `json:"capacity"` - Cover string `json:"cover"` -} - -type SizeTitle struct { - Cm string `json:"cm"` - Inth string `json:"inth"` -} - -type Templates struct { - Ob484 []Ob484 `json:"4_84"` -} - -type Ob484 struct { - Id int64 `json:"id"` - Title string `json:"title"` - TemplateData TemplateData `json:"templateData"` -} - -type TemplateData struct { - Id int64 `json:"id"` - Cover string `json:"cover"` - Material string `json:"material"` - MaterialList []Material `json:"materialList"` -} - -type Material struct { - Id int64 `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int `json:"maxNum"` - Rotation int `json:"rotation"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - QRcodeType string `json:"qRcodeType"` - Width int `json:"width"` - Height int `json:"height"` - X int `json:"x"` - Y int `json:"y"` - Opacity int `json:"opacity"` - OptionalColor []OptionalColor `json:"optionalColor"` - ZIndex int `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow Follow `json:"follow"` - Group []string `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} - -type CameraStand struct { - X int `json:"x"` - Y int `json:"y"` - Z int `json:"z"` -} - -type Follow 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 string `json:"default"` -} - type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server_api/product.api b/server_api/product.api index c223fda0..12fc635c 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -12,14 +12,10 @@ service product { //获取产品列表 @handler GetProductListHandler get /product/list(GetProductListReq) returns (response); - //获取产品详情信息 - @handler GetProductInfoHandler - get /product/info(GetProductInfoReq) returns (response); } //获取产品列表 type GetProductListReq { - // TODO: add members here and delete this comment Cid int64 `form:"cid"` Size uint32 `form:"size"` Page uint32 `form:"page"` @@ -62,96 +58,4 @@ type Items { SizeNum uint32 `json:"sizeNum"` MiniPrice float64 `json:"miniPrice"` CoverDefault string `json:"coverDefault"` -} -//获取产品详情 -type GetProductInfoReq { - Pid string `form:"pid"` //sn - Size uint32 `form:"size"` //图片尺寸 - ClientNo string `form:"clientNo"` //页面标识 - HaveCloudRendering bool `form:"haveCloudRendering"` //是否显示云渲染开关 -} -type GetProductInfoRsp { - Id int64 `json:"id"` - Type int32 `json:"type"` - Title string `json:"title"` - IsEnv uint32 `json:"isEnv"` - IsMicro uint32 `json:"isMicro"` - Materials []Materials `json:"materials"` - Sizes []Sizes `json:"sizes"` - TypeName string `json:"typeName"` - Templates Templates `json:"templates"` -} - -type Materials { - Id int64 `json:"id"` - Title string `json:"title"` -} -type Sizes { - Id int64 `json:"id"` - Title SizeTitle `json:"title"` - Capacity string `json:"capacity"` - Cover string `json:"cover"` -} -type SizeTitle { - Cm string `json:"cm"` - Inth string `json:"inth"` -} -type Templates { - Ob484 []Ob484 `json:"4_84"` -} -type Ob484 { - Id int64 `json:"id"` - Title string `json:"title"` - TemplateData TemplateData `json:"templateData"` -} -type TemplateData { - Id int64 `json:"id"` - Cover string `json:"cover"` - Material string `json:"material"` - MaterialList []Material `json:"materialList"` -} -type Material { - Id int64 `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int `json:"maxNum"` - Rotation int `json:"rotation"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - QRcodeType string `json:"qRcodeType"` - Width int `json:"width"` - Height int `json:"height"` - X int `json:"x"` - Y int `json:"y"` - Opacity int `json:"opacity"` - OptionalColor []OptionalColor `json:"optionalColor"` - ZIndex int `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow Follow `json:"follow"` - Group []string `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} -type CameraStand { - X int `json:"x"` - Y int `json:"y"` - Z int `json:"z"` -} -type Follow { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} -type OptionalColor { - Color string `json:"color"` - Name string `json:"name"` - Default string `json:"default"` } \ No newline at end of file