From 213665eb599f77c7a20ea35ac7d38ca54b5ea292 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 13:07:39 +0800 Subject: [PATCH 1/8] fix --- ddl/fs_product_template_tags.sql | 9 ++ model/fsproductmodel3dmodel_gen.go | 9 +- model/fsproductmodel_gen.go | 18 ---- model/fsproductpricemodel_gen.go | 12 --- model/fsproductsizemodel_gen.go | 23 +---- model/fsproducttemplatetagsmodel.go | 24 +++++ model/fsproducttemplatetagsmodel_gen.go | 87 +++++++++++++++++++ model/fsproducttemplatev2model_gen.go | 20 ----- model/self_fsproductmodel.go | 26 ++++++ model/self_fsproductmodel3dmodel.go | 21 +++++ model/self_fsproductpricemodel.go | 26 ++++++ model/self_fsproductsizemodel.go | 31 +++++++ model/self_fsproducttemplatetagsmodel.go | 20 +++++ model/self_fsproducttemplatev2model.go | 33 +++++++ model/self_fstagsmodel.go | 3 + product/internal/logic/getproductinfologic.go | 51 +++++++++-- product/internal/types/types.go | 13 +-- server_api/product.api | 8 +- 18 files changed, 335 insertions(+), 99 deletions(-) create mode 100644 ddl/fs_product_template_tags.sql create mode 100755 model/fsproducttemplatetagsmodel.go create mode 100755 model/fsproducttemplatetagsmodel_gen.go create mode 100755 model/self_fsproductmodel.go create mode 100755 model/self_fsproductmodel3dmodel.go create mode 100755 model/self_fsproductpricemodel.go create mode 100755 model/self_fsproductsizemodel.go create mode 100755 model/self_fsproducttemplatetagsmodel.go create mode 100755 model/self_fsproducttemplatev2model.go create mode 100755 model/self_fstagsmodel.go diff --git a/ddl/fs_product_template_tags.sql b/ddl/fs_product_template_tags.sql new file mode 100644 index 00000000..f7971864 --- /dev/null +++ b/ddl/fs_product_template_tags.sql @@ -0,0 +1,9 @@ +-- fusentest.fs_product_template_tags definition + +CREATE TABLE `fs_product_template_tags` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', + `title` varchar(25) NOT NULL COMMENT '标题', + `status` tinyint(1) unsigned NOT NULL COMMENT '状态 1:可用', + `create_at` int(10) unsigned NOT NULL COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT=' 模板标签表'; \ No newline at end of file diff --git a/model/fsproductmodel3dmodel_gen.go b/model/fsproductmodel3dmodel_gen.go index 9e2c9c2b..1e0b4788 100755 --- a/model/fsproductmodel3dmodel_gen.go +++ b/model/fsproductmodel3dmodel_gen.go @@ -95,14 +95,7 @@ func (m *defaultFsProductModel3dModel) Update(ctx context.Context, data *FsProdu _, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.Tag, data.Title, data.Name, data.ModelInfo, data.MaterialId, data.SizeId, data.Sort, data.Light, data.LightList, data.PartId, data.PartList, data.Status, data.Ctime, data.OptionTemplate, data.Price, data.Sku, data.Id) return err } -func (m *defaultFsProductModel3dModel) ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error) { - query := fmt.Sprintf("select %s from %s where `size_id` in (?) and `tag` = ?", fsProductModel3dRows, m.table) - err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(sizeIds, ","), tag) - if err != nil { - return nil, err - } - return -} + func (m *defaultFsProductModel3dModel) tableName() string { return m.table } diff --git a/model/fsproductmodel_gen.go b/model/fsproductmodel_gen.go index 8f434238..86bc2bb1 100755 --- a/model/fsproductmodel_gen.go +++ b/model/fsproductmodel_gen.go @@ -122,24 +122,6 @@ func (m *defaultFsProductModel) Update(ctx context.Context, newData *FsProduct) return err } -func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, productType int, isDel int, isShelf int, sort string) (resp []FsProduct, err error) { - query := fmt.Sprintf("select %s from %s where `type` = ? and `is_del` =? and `is_shelf` = ?", - fsProductRows, m.table) - switch sort { - case "sort-asc": - query = fmt.Sprintf("%s order by sort ASC", query) - case "sort-desc": - query = fmt.Sprintf("%s order by sort DESC", query) - default: - query = fmt.Sprintf("%s order by sort DESC", query) - } - err = m.conn.QueryRowsCtx(ctx, &resp, query, productType, isDel, isShelf) - if err != nil { - return nil, err - } - return -} - func (m *defaultFsProductModel) tableName() string { return m.table } diff --git a/model/fsproductpricemodel_gen.go b/model/fsproductpricemodel_gen.go index f95facf8..7b5280d5 100755 --- a/model/fsproductpricemodel_gen.go +++ b/model/fsproductpricemodel_gen.go @@ -106,18 +106,6 @@ func (m *defaultFsProductPriceModel) Update(ctx context.Context, newData *FsProd return err } -type GetPriceListRsp struct { - ProductId int64 `json:"product_id"` - Price string `json:"price"` -} - -func (m *defaultFsProductPriceModel) GetPriceList(ctx context.Context, productIds []string) (resp []GetPriceListRsp, err error) { - query := fmt.Sprintf("select %s from %s where `product_id` in (?) and `status` = ? group by product_id", "product_id,group_concat(step_price) as price ", m.table) - if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 1); err != nil { - return nil, err - } - return -} func (m *defaultFsProductPriceModel) tableName() string { return m.table } diff --git a/model/fsproductsizemodel_gen.go b/model/fsproductsizemodel_gen.go index fcd125d0..9ff3a983 100755 --- a/model/fsproductsizemodel_gen.go +++ b/model/fsproductsizemodel_gen.go @@ -88,28 +88,7 @@ func (m *defaultFsProductSizeModel) Update(ctx context.Context, data *FsProductS _, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.Title, data.Cover, data.CoverImg, data.Capacity, data.Status, data.Sort, data.Remark, data.PartsCanDeleted, data.Id) return err } -func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) { - query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table) - err = m.conn.QueryRowCtx(ctx, &total, query, status) - if err != nil { - return 0, err - } - return -} -func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) { - query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, 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) - } - err = m.conn.QueryRowsCtx(ctx, &resp, query, status) - if err != nil { - return nil, err - } - return -} + func (m *defaultFsProductSizeModel) tableName() string { return m.table } diff --git a/model/fsproducttemplatetagsmodel.go b/model/fsproducttemplatetagsmodel.go new file mode 100755 index 00000000..7f162d97 --- /dev/null +++ b/model/fsproducttemplatetagsmodel.go @@ -0,0 +1,24 @@ +package model + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ FsProductTemplateTagsModel = (*customFsProductTemplateTagsModel)(nil) + +type ( + // FsProductTemplateTagsModel is an interface to be customized, add more methods here, + // and implement the added methods in customFsProductTemplateTagsModel. + FsProductTemplateTagsModel interface { + fsProductTemplateTagsModel + } + + customFsProductTemplateTagsModel struct { + *defaultFsProductTemplateTagsModel + } +) + +// NewFsProductTemplateTagsModel returns a model for the database table. +func NewFsProductTemplateTagsModel(conn sqlx.SqlConn) FsProductTemplateTagsModel { + return &customFsProductTemplateTagsModel{ + defaultFsProductTemplateTagsModel: newFsProductTemplateTagsModel(conn), + } +} diff --git a/model/fsproducttemplatetagsmodel_gen.go b/model/fsproducttemplatetagsmodel_gen.go new file mode 100755 index 00000000..0570b684 --- /dev/null +++ b/model/fsproducttemplatetagsmodel_gen.go @@ -0,0 +1,87 @@ +// 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 ( + fsProductTemplateTagsFieldNames = builder.RawFieldNames(&FsProductTemplateTags{}) + fsProductTemplateTagsRows = strings.Join(fsProductTemplateTagsFieldNames, ",") + fsProductTemplateTagsRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductTemplateTagsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + fsProductTemplateTagsRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductTemplateTagsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + fsProductTemplateTagsModel interface { + Insert(ctx context.Context, data *FsProductTemplateTags) (sql.Result, error) + FindOne(ctx context.Context, id int64) (*FsProductTemplateTags, error) + Update(ctx context.Context, data *FsProductTemplateTags) error + Delete(ctx context.Context, id int64) error + ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error) + } + + defaultFsProductTemplateTagsModel struct { + conn sqlx.SqlConn + table string + } + + FsProductTemplateTags struct { + Id int64 `db:"id"` // ID + Title string `db:"title"` // 标题 + Status int64 `db:"status"` // 状态 1:可用 + CreateAt int64 `db:"create_at"` // 创建时间 + } +) + +func newFsProductTemplateTagsModel(conn sqlx.SqlConn) *defaultFsProductTemplateTagsModel { + return &defaultFsProductTemplateTagsModel{ + conn: conn, + table: "`fs_product_template_tags`", + } +} + +func (m *defaultFsProductTemplateTagsModel) 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 *defaultFsProductTemplateTagsModel) FindOne(ctx context.Context, id int64) (*FsProductTemplateTags, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductTemplateTagsRows, m.table) + var resp FsProductTemplateTags + 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 *defaultFsProductTemplateTagsModel) Insert(ctx context.Context, data *FsProductTemplateTags) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, fsProductTemplateTagsRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.Status) + return ret, err +} + +func (m *defaultFsProductTemplateTagsModel) Update(ctx context.Context, data *FsProductTemplateTags) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductTemplateTagsRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, data.Title, data.Status, data.Id) + return err +} + +func (m *defaultFsProductTemplateTagsModel) tableName() string { + return m.table +} diff --git a/model/fsproducttemplatev2model_gen.go b/model/fsproducttemplatev2model_gen.go index c7e4ffac..d3cd0ef2 100755 --- a/model/fsproducttemplatev2model_gen.go +++ b/model/fsproducttemplatev2model_gen.go @@ -94,26 +94,6 @@ func (m *defaultFsProductTemplateV2Model) Update(ctx context.Context, data *FsPr _, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.ModelId, data.Title, data.Name, data.CoverImg, data.TemplateInfo, data.MaterialImg, data.Sort, data.LogoWidth, data.LogoHeight, data.IsPublic, data.Status, data.Ctime, data.Tag, data.IsDel, data.Id) return err } -func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) { - query := fmt.Sprintf("select %s from %s where `id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table) - if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 0, 1); err != nil { - return nil, err - } - return -} -func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) { - query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `product_id` = ? and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table) - switch sort { - case 1: - query = fmt.Sprintf("%s order by `sort` ASC") - case 2: - query = fmt.Sprintf("%s order by `sort` DESC") - } - if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), productId, 0, 1); err != nil { - return nil, err - } - return -} func (m *defaultFsProductTemplateV2Model) tableName() string { return m.table } diff --git a/model/self_fsproductmodel.go b/model/self_fsproductmodel.go new file mode 100755 index 00000000..9384d052 --- /dev/null +++ b/model/self_fsproductmodel.go @@ -0,0 +1,26 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" +) + +func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, productType int, isDel int, isShelf int, sort string) (resp []FsProduct, err error) { + query := fmt.Sprintf("select %s from %s where `type` = ? and `is_del` =? and `is_shelf` = ?", + fsProductRows, m.table) + switch sort { + case "sort-asc": + query = fmt.Sprintf("%s order by sort ASC", query) + case "sort-desc": + query = fmt.Sprintf("%s order by sort DESC", query) + default: + query = fmt.Sprintf("%s order by sort DESC", query) + } + err = m.conn.QueryRowsCtx(ctx, &resp, query, productType, isDel, isShelf) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproductmodel3dmodel.go b/model/self_fsproductmodel3dmodel.go new file mode 100755 index 00000000..6967e4ad --- /dev/null +++ b/model/self_fsproductmodel3dmodel.go @@ -0,0 +1,21 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" + "strings" +) + +func (m *defaultFsProductModel3dModel) ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error) { + if len(sizeIds) == 0 { + return nil, nil + } + query := fmt.Sprintf("select %s from %s where `size_id` in (?) and `tag` = ?", fsProductModel3dRows, m.table) + err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(sizeIds, ","), tag) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproductpricemodel.go b/model/self_fsproductpricemodel.go new file mode 100755 index 00000000..63478230 --- /dev/null +++ b/model/self_fsproductpricemodel.go @@ -0,0 +1,26 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + + "fmt" + "strings" +) + +type GetPriceListRsp struct { + ProductId int64 `json:"product_id"` + Price string `json:"price"` +} + +func (m *defaultFsProductPriceModel) GetPriceList(ctx context.Context, productIds []string) (resp []GetPriceListRsp, err error) { + if len(productIds) == 0 { + return nil, nil + } + query := fmt.Sprintf("select %s from %s where `product_id` in (?) and `status` = ? group by product_id", "product_id,group_concat(step_price) as price ", m.table) + if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 1); err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproductsizemodel.go b/model/self_fsproductsizemodel.go new file mode 100755 index 00000000..ea61699c --- /dev/null +++ b/model/self_fsproductsizemodel.go @@ -0,0 +1,31 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" +) + +func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) { + query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table) + err = m.conn.QueryRowCtx(ctx, &total, query, status) + if err != nil { + return 0, err + } + return +} +func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) { + query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, 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) + } + err = m.conn.QueryRowsCtx(ctx, &resp, query, status) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproducttemplatetagsmodel.go b/model/self_fsproducttemplatetagsmodel.go new file mode 100755 index 00000000..f8014603 --- /dev/null +++ b/model/self_fsproducttemplatetagsmodel.go @@ -0,0 +1,20 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" +) + +func (m *defaultFsProductTemplateTagsModel) ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error) { + if len(ids) == 0 { + return nil, nil + } + query := fmt.Sprintf("select %s from %s where `id` in (?) ", fsProductTemplateTagsRows, m.table) + err = m.conn.QueryRowsCtx(ctx, &resp, query, ids) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproducttemplatev2model.go b/model/self_fsproducttemplatev2model.go new file mode 100755 index 00000000..b5ac10d1 --- /dev/null +++ b/model/self_fsproducttemplatev2model.go @@ -0,0 +1,33 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" + "strings" +) + +func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) { + query := fmt.Sprintf("select %s from %s where `id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table) + if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 0, 1); err != nil { + return nil, err + } + return +} +func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) { + if len(modelIds) == 0 { + return + } + query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `product_id` = ? 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, ","), productId, 0, 1); err != nil { + return nil, err + } + return +} diff --git a/model/self_fstagsmodel.go b/model/self_fstagsmodel.go new file mode 100755 index 00000000..9695915d --- /dev/null +++ b/model/self_fstagsmodel.go @@ -0,0 +1,3 @@ +// Code generated by goctl. DO NOT EDIT. + +package model diff --git a/product/internal/logic/getproductinfologic.go b/product/internal/logic/getproductinfologic.go index 45c5a5ea..e79e0c98 100644 --- a/product/internal/logic/getproductinfologic.go +++ b/product/internal/logic/getproductinfologic.go @@ -2,9 +2,16 @@ 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" ) @@ -24,8 +31,9 @@ func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge // 获取产品详情 func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response) { + loginInfo.UserId = 83 //校验前台登录情况 - /*if loginInfo.UserId == 0 { + if loginInfo.UserId == 0 { return &types.Response{Code: 402, Message: "please sign in"} } req.Pid = strings.Trim(req.Pid, " ") @@ -44,12 +52,12 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login return &types.Response{Code: 510, Message: "product not found"} } //获取产品标签 - tagModel := model.NewFsTagsModel(l.svcCtx.MysqlConn) + /*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) @@ -69,8 +77,10 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login 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) @@ -80,9 +90,38 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login return &types.Response{Code: 510, Message: "failed to get templates"} } //获取模板包含的model_id - templateModelIds := make([]string, 0, len(templateV2List)) + mapTemplateModelId := make(map[int64]struct{}) + tagIds := make([]string, 0, len(templateV2List)) for _, v := range templateV2List { - templateModelIds = append(templateModelIds, fmt.Sprintf("%d", v.ModelId)) + 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 + //组装材料 + return &types.Response{} } diff --git a/product/internal/types/types.go b/product/internal/types/types.go index 9faf564b..a272da22 100644 --- a/product/internal/types/types.go +++ b/product/internal/types/types.go @@ -57,10 +57,10 @@ type Items struct { } type GetProductInfoReq struct { - Pid string `json:"pid"` //sn - Size uint32 `json:"size"` //图片尺寸 - ClientNo string `json:"clientNo"` //页面标识 - HaveCloudRendering bool `json:"haveCloudRendering"` //是否显示云渲染开关 + Pid string `form:"pid"` //sn + Size uint32 `form:"size"` //图片尺寸 + ClientNo string `form:"clientNo"` //页面标识 + HaveCloudRendering bool `form:"haveCloudRendering"` //是否显示云渲染开关 } type GetProductInfoRsp struct { @@ -164,11 +164,6 @@ type Response struct { Data interface{} `json:"data"` } -type Auth struct { - AccessSecret string `json:"AccessSecret"` - AccessExpire int `json:"AccessExpire"` -} - // Set 设置Response的Code和Message值 func (resp *Response) Set(Code int, Message string) { resp.Code = Code diff --git a/server_api/product.api b/server_api/product.api index 200e2c57..c223fda0 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -65,10 +65,10 @@ type Items { } //获取产品详情 type GetProductInfoReq { - Pid string `json:"pid"` //sn - Size uint32 `json:"size"` //图片尺寸 - ClientNo string `json:"clientNo"` //页面标识 - HaveCloudRendering bool `json:"haveCloudRendering"` //是否显示云渲染开关 + Pid string `form:"pid"` //sn + Size uint32 `form:"size"` //图片尺寸 + ClientNo string `form:"clientNo"` //页面标识 + HaveCloudRendering bool `form:"haveCloudRendering"` //是否显示云渲染开关 } type GetProductInfoRsp { Id int64 `json:"id"` 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 2/8] 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 From 045aa81899483b8f2565a226252bc350e56b6ab4 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 15:08:17 +0800 Subject: [PATCH 3/8] fix --- constants/product_list_demo.go | 271 ++++++++++++++++ product/internal/logic/getproductlistlogic.go | 289 +----------------- 2 files changed, 277 insertions(+), 283 deletions(-) create mode 100644 constants/product_list_demo.go diff --git a/constants/product_list_demo.go b/constants/product_list_demo.go new file mode 100644 index 00000000..eb638fac --- /dev/null +++ b/constants/product_list_demo.go @@ -0,0 +1,271 @@ +package constants + +// 产品列表demo +const PRODUCT_LIST_DEMO = `{ + "ob": { + "items": [ + { + "id": 25, + "sn": "P1ELZGHU", + "title": "Packing box", + "cover": "/icon/icon_25_800.png", + "intro": "打包盒卡纸", + "cover_img": "/uploads/ognhdc6q_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 28, + "sn": "P9KVYAUS", + "title": "Pizza box", + "cover": "/icon/9dmom0g7_800.png", + "intro": "披萨盒 瓦楞纸", + "cover_img": "/uploads/9xf1olkl_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 30, + "sn": "PZWDSROX", + "title": "Paper bag with handle", + "cover": "/icon/iz44vraw_800.png", + "intro": "有提手纸袋牛皮纸", + "cover_img": "/uploads/rpwntxcq_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 20, + "sn": "PNACHNUK", + "title": "Four cups of milk tea cup", + "cover": "/icon/plz43wpo_800.png", + "intro": "卡纸", + "cover_img": "/uploads/9tqgsjqi_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 2, + "miniPrice": 2 + }, + { + "id": 19, + "sn": "PHHVEXRW", + "title": "Milk tea cup holder double cup", + "cover": "/icon/ipohmmcj_800.png", + "intro": "奶茶杯托奶茶杯托两杯袋", + "cover_img": "/uploads/57ogzeq5_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 11, + "sn": "P7N4D0MK", + "title": "Cup double layer", + "cover": "/icon/nrmzz4du_800.png", + "intro": "牛皮纸双层", + "cover_img": "/uploads/oqjm5own_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 33, + "sn": "P0NFP19Y", + "title": "High paper bowl", + "cover": "/icon/cla4k6om_800.png", + "intro": "牛皮纸", + "cover_img": "/uploads/dt1qjkzg_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 32, + "sn": "PDZ3HIUL", + "title": "Flat paper bowl", + "cover": "/icon/jy14adqz_800.png", + "intro": "牛皮纸", + "cover_img": "/uploads/bzwbxduc_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 3, + "miniPrice": 2 + }, + { + "id": 31, + "sn": "PEVSMU7I", + "title": "Paper bag without handle", + "cover": "/icon/osdsegor_800.png", + "intro": "牛皮纸", + "cover_img": "/uploads/ouvayny7_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 2, + "miniPrice": 2 + }, + { + "id": 29, + "sn": "P58ZZOTI", + "title": "plastic bag", + "cover": "/icon/dvsvddks_800.png", + "intro": "塑料袋", + "cover_img": "/uploads/qvvuzkzx_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 24, + "sn": "PG7XIXII", + "title": "Hamburger box", + "cover": "/icon/icon_24_800.png", + "intro": "汉堡盒 卡纸", + "cover_img": "/uploads/fm1itgge_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 23, + "sn": "PIJ2OVUE", + "title": "Milk tea ring portable double cup", + "cover": "/icon/nxb6hjln_800.png", + "intro": "卡纸", + "cover_img": "/uploads/52fash1n_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 21, + "sn": "PMHXGUL6", + "title": "Milk tea ring portable single cup", + "cover": "/icon/qoaf5mtp_800.png", + "intro": "卡纸", + "cover_img": "/uploads/epvkzvyf_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 18, + "sn": "PFCM8KNF", + "title": "Tableware set chopsticks", + "cover": "/icon/tcspod4b_800.png", + "intro": "餐具套装筷子厚牛皮纸包装", + "cover_img": "/uploads/5jgrgzvh_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 3, + "miniPrice": 2 + }, + { + "id": 17, + "sn": "PQKIQMIK", + "title": "Tableware set four piece set", + "cover": "/icon/mdo0vu1u_800.png", + "intro": "牛皮纸包装", + "cover_img": "/uploads/szsekvbw_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 16, + "sn": "PBFOIOFH", + "title": "Tableware set four piece set", + "cover": "/icon/dzrf59cp_800.png", + "intro": "餐具套装", + "cover_img": "/uploads/svfoebf1_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 15, + "sn": "P02V10AB", + "title": " Hot drink cup holder", + "cover": "/icon/icon_15_800.png", + "intro": "杯托、瓦楞纸", + "cover_img": "/uploads/4qbdid7i_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 13, + "sn": "PER6WLAV", + "title": " Cup pet", + "cover": "/icon/icon_13_800.png", + "intro": "pet", + "cover_img": "/uploads/kfxehwjd_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 12, + "sn": "PGFWRMAU", + "title": " Cup PP", + "cover": "/icon/icon_12_800.png", + "intro": "pp", + "cover_img": "/uploads/azp8uwhz_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 2, + "miniPrice": 2 + }, + { + "id": 10, + "sn": "P4ZXDVHS", + "title": "Cup monolayer", + "cover": "/icon/icon_10_800.png", + "intro": "牛皮纸单层", + "cover_img": "/uploads/onuzax6l_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + } + ], + "_links": { + "self": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" + }, + "first": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" + }, + "last": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" + }, + "next": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" + } + }, + "_meta": { + "totalCount": 21, + "pageCount": 2, + "currentPage": 1, + "perPage": 20 + } + }, + "typeName": "Boxes", + "description": "" + }` diff --git a/product/internal/logic/getproductlistlogic.go b/product/internal/logic/getproductlistlogic.go index eb639d8c..95a18798 100644 --- a/product/internal/logic/getproductlistlogic.go +++ b/product/internal/logic/getproductlistlogic.go @@ -43,7 +43,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login //如果是demo if req.IsDemo == 1 { var demo types.GetProductListRsp - if err := json.Unmarshal([]byte(l.DemoProductList()), &demo); err != nil { + if err := json.Unmarshal([]byte(constants.PRODUCT_LIST_DEMO), &demo); err != nil { logx.Error(err) return &types.Response{Code: 510, Message: "demo data format err"} } @@ -176,287 +176,10 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login } itemList = append(itemList, item) } - return &types.Response{ - Code: 200, - Message: "success", - Data: types.GetProductListRsp{ - Ob: types.Ob{ - Items: itemList, - }, - TypeName: tagInfo.Title, - Description: tagInfo.Description, - }} + return &types.Response{Code: 200, Message: "success", Data: types.GetProductListRsp{ + Ob: types.Ob{ + Items: itemList, + }, TypeName: tagInfo.Title, Description: tagInfo.Description, + }} return } - -// 样本产品列表 -func (l *GetProductListLogic) DemoProductList() string { - return `{ - "ob": { - "items": [ - { - "id": 25, - "sn": "P1ELZGHU", - "title": "Packing box", - "cover": "/icon/icon_25_800.png", - "intro": "打包盒卡纸", - "cover_img": "/uploads/ognhdc6q_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 28, - "sn": "P9KVYAUS", - "title": "Pizza box", - "cover": "/icon/9dmom0g7_800.png", - "intro": "披萨盒 瓦楞纸", - "cover_img": "/uploads/9xf1olkl_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 30, - "sn": "PZWDSROX", - "title": "Paper bag with handle", - "cover": "/icon/iz44vraw_800.png", - "intro": "有提手纸袋牛皮纸", - "cover_img": "/uploads/rpwntxcq_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 20, - "sn": "PNACHNUK", - "title": "Four cups of milk tea cup", - "cover": "/icon/plz43wpo_800.png", - "intro": "卡纸", - "cover_img": "/uploads/9tqgsjqi_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 2, - "miniPrice": 2 - }, - { - "id": 19, - "sn": "PHHVEXRW", - "title": "Milk tea cup holder double cup", - "cover": "/icon/ipohmmcj_800.png", - "intro": "奶茶杯托奶茶杯托两杯袋", - "cover_img": "/uploads/57ogzeq5_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 11, - "sn": "P7N4D0MK", - "title": "Cup double layer", - "cover": "/icon/nrmzz4du_800.png", - "intro": "牛皮纸双层", - "cover_img": "/uploads/oqjm5own_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 33, - "sn": "P0NFP19Y", - "title": "High paper bowl", - "cover": "/icon/cla4k6om_800.png", - "intro": "牛皮纸", - "cover_img": "/uploads/dt1qjkzg_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 32, - "sn": "PDZ3HIUL", - "title": "Flat paper bowl", - "cover": "/icon/jy14adqz_800.png", - "intro": "牛皮纸", - "cover_img": "/uploads/bzwbxduc_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 3, - "miniPrice": 2 - }, - { - "id": 31, - "sn": "PEVSMU7I", - "title": "Paper bag without handle", - "cover": "/icon/osdsegor_800.png", - "intro": "牛皮纸", - "cover_img": "/uploads/ouvayny7_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 2, - "miniPrice": 2 - }, - { - "id": 29, - "sn": "P58ZZOTI", - "title": "plastic bag", - "cover": "/icon/dvsvddks_800.png", - "intro": "塑料袋", - "cover_img": "/uploads/qvvuzkzx_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 24, - "sn": "PG7XIXII", - "title": "Hamburger box", - "cover": "/icon/icon_24_800.png", - "intro": "汉堡盒 卡纸", - "cover_img": "/uploads/fm1itgge_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 23, - "sn": "PIJ2OVUE", - "title": "Milk tea ring portable double cup", - "cover": "/icon/nxb6hjln_800.png", - "intro": "卡纸", - "cover_img": "/uploads/52fash1n_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 21, - "sn": "PMHXGUL6", - "title": "Milk tea ring portable single cup", - "cover": "/icon/qoaf5mtp_800.png", - "intro": "卡纸", - "cover_img": "/uploads/epvkzvyf_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 18, - "sn": "PFCM8KNF", - "title": "Tableware set chopsticks", - "cover": "/icon/tcspod4b_800.png", - "intro": "餐具套装筷子厚牛皮纸包装", - "cover_img": "/uploads/5jgrgzvh_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 3, - "miniPrice": 2 - }, - { - "id": 17, - "sn": "PQKIQMIK", - "title": "Tableware set four piece set", - "cover": "/icon/mdo0vu1u_800.png", - "intro": "牛皮纸包装", - "cover_img": "/uploads/szsekvbw_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 16, - "sn": "PBFOIOFH", - "title": "Tableware set four piece set", - "cover": "/icon/dzrf59cp_800.png", - "intro": "餐具套装", - "cover_img": "/uploads/svfoebf1_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 15, - "sn": "P02V10AB", - "title": " Hot drink cup holder", - "cover": "/icon/icon_15_800.png", - "intro": "杯托、瓦楞纸", - "cover_img": "/uploads/4qbdid7i_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 13, - "sn": "PER6WLAV", - "title": " Cup pet", - "cover": "/icon/icon_13_800.png", - "intro": "pet", - "cover_img": "/uploads/kfxehwjd_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 12, - "sn": "PGFWRMAU", - "title": " Cup PP", - "cover": "/icon/icon_12_800.png", - "intro": "pp", - "cover_img": "/uploads/azp8uwhz_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 2, - "miniPrice": 2 - }, - { - "id": 10, - "sn": "P4ZXDVHS", - "title": "Cup monolayer", - "cover": "/icon/icon_10_800.png", - "intro": "牛皮纸单层", - "cover_img": "/uploads/onuzax6l_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - } - ], - "_links": { - "self": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" - }, - "first": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" - }, - "last": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" - }, - "next": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" - } - }, - "_meta": { - "totalCount": 21, - "pageCount": 2, - "currentPage": 1, - "perPage": 20 - } - }, - "typeName": "Boxes", - "description": "" - }` -} From e8aabdb3cf4d7f93b388d3bdc7cb03a7fd264a82 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 15:09:34 +0800 Subject: [PATCH 4/8] fix --- product/internal/logic/getproductlistlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product/internal/logic/getproductlistlogic.go b/product/internal/logic/getproductlistlogic.go index 95a18798..f3aa7d59 100644 --- a/product/internal/logic/getproductlistlogic.go +++ b/product/internal/logic/getproductlistlogic.go @@ -38,7 +38,7 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response) { //校验前台登录情况 if loginInfo.UserId == 0 { - return &types.Response{Code: 402, Message: "please sign in"} + return &types.Response{Code: 401, Message: "please sign in"} } //如果是demo if req.IsDemo == 1 { @@ -64,7 +64,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login return &types.Response{Code: 510, Message: "get user info err"} } if userInfo == nil { - return &types.Response{Code: 402, Message: "user not exists"} + return &types.Response{Code: 401, Message: "user not exists"} } //查询符合的产品列表 productModel := model.NewFsProductModel(l.svcCtx.MysqlConn) From d31f3a1e41873f6c848279a5f80386067eb1c6b7 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 15:30:12 +0800 Subject: [PATCH 5/8] fix --- product/internal/handler/routes.go | 5 +++++ product/internal/types/types.go | 16 ++++++++++++++++ server_api/product.api | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/product/internal/handler/routes.go b/product/internal/handler/routes.go index 18f67cbc..b0cca7a2 100644 --- a/product/internal/handler/routes.go +++ b/product/internal/handler/routes.go @@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/product/list", Handler: GetProductListHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/product/success-recommand", + Handler: GetSuccessRecommandHandler(serverCtx), + }, }, ) } diff --git a/product/internal/types/types.go b/product/internal/types/types.go index 0c24482f..46d0aefb 100644 --- a/product/internal/types/types.go +++ b/product/internal/types/types.go @@ -56,6 +56,22 @@ type Items struct { CoverDefault string `json:"coverDefault"` } +type GetSuccessRecommandReq struct { + Num uint32 `form:"num"` + Size uint32 `form:"size"` + Sn string `form:"sn"` +} + +type GetSuccessRecommandRsp struct { + Title string `json:"title"` + Cover string `json:"cover"` + CoverImg string `json:"coverImg"` + Sn string `json:"sn"` + Id int64 `json:"id"` + SkuId int64 `json:"skuId"` + CoverDefault string `json:"coverDefault"` +} + type Response struct { Code int `json:"code"` Message string `json:"msg"` diff --git a/server_api/product.api b/server_api/product.api index 12fc635c..32a96e38 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -12,6 +12,9 @@ service product { //获取产品列表 @handler GetProductListHandler get /product/list(GetProductListReq) returns (response); + //获取成功后的推荐产品 + @handler GetSuccessRecommand + get /product/success-recommand (GetSuccessRecommandReq) returns (response); } //获取产品列表 @@ -58,4 +61,19 @@ type Items { SizeNum uint32 `json:"sizeNum"` MiniPrice float64 `json:"miniPrice"` CoverDefault string `json:"coverDefault"` +} +//获取成功后的推荐产品 +type GetSuccessRecommandReq { + Num uint32 `form:"num"` + Size uint32 `form:"size"` + Sn string `form:"sn"` +} +type GetSuccessRecommandRsp { + Title string `json:"title"` + Cover string `json:"cover"` + CoverImg string `json:"coverImg"` + Sn string `json:"sn"` + Id int64 `json:"id"` + SkuId int64 `json:"skuId"` + CoverDefault string `json:"coverDefault"` } \ No newline at end of file From 245155d10e03ef70d4219738db66ed8b635b2761 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 15:52:41 +0800 Subject: [PATCH 6/8] fix --- goctl_template/api/types.tpl | 25 +++++++----- .../handler/getsuccessrecommandhandler.go | 40 +++++++++++++++++++ .../logic/getsuccessrecommandlogic.go | 31 ++++++++++++++ product/internal/types/types.go | 21 ++++++---- 4 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 product/internal/handler/getsuccessrecommandhandler.go create mode 100644 product/internal/logic/getsuccessrecommandlogic.go diff --git a/goctl_template/api/types.tpl b/goctl_template/api/types.tpl index 0875ec47..4cf86d10 100644 --- a/goctl_template/api/types.tpl +++ b/goctl_template/api/types.tpl @@ -8,48 +8,55 @@ import ( {{.types}} // Set 设置Response的Code和Message值 -func (resp *Response) Set(Code int, Message string) { +func (resp *Response) Set(Code int, Message string) *Response{ resp.Code = Code resp.Message = Message + return resp } // Set 设置整个Response -func (resp *Response) SetWithData(Code int, Message string, Data interface{}) { +func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response{ resp.Code = Code resp.Message = Message resp.Data = Data + return resp } // SetMessage 设置Response的Message -func (resp *Response) SetMessage(msg string) { +func (resp *Response) SetMessage(msg string) *Response{ resp.Message = msg + return resp } // SetWithData 设置Data -func (resp *Response) SetData(Data interface{}) { +func (resp *Response) SetData(Data interface{}) *Response{ resp.Data = Data + return resp } // SetWithData 设置Response的Code和Message值 带Data入参数 -func (resp *Response) SetCode(Code int) { +func (resp *Response) SetCode(Code int) *Response{ resp.Code = Code + return resp } // SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) { +func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response{ resp.Code = sr.Code resp.Message = sr.Message if len(data) == 1 { resp.Data = data[0] - } + } + return resp } // SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) { +func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response{ resp.Code = sr.Code resp.Message = msg if len(data) == 1 { resp.Data = data[0] - } + } + return resp } \ No newline at end of file diff --git a/product/internal/handler/getsuccessrecommandhandler.go b/product/internal/handler/getsuccessrecommandhandler.go new file mode 100644 index 00000000..7a067ca9 --- /dev/null +++ b/product/internal/handler/getsuccessrecommandhandler.go @@ -0,0 +1,40 @@ +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 GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + //用户登录信息 + userInfo := auth.CheckAuth(r) + var req types.GetSuccessRecommandReq + 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.NewGetSuccessRecommandLogic(r.Context(), svcCtx) + resp := l.GetSuccessRecommand(&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/logic/getsuccessrecommandlogic.go b/product/internal/logic/getsuccessrecommandlogic.go new file mode 100644 index 00000000..e72b4a39 --- /dev/null +++ b/product/internal/logic/getsuccessrecommandlogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + "fusenapi/utils/auth" + + "fusenapi/product/internal/svc" + "fusenapi/product/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetSuccessRecommandLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSuccessRecommandLogic { + return &GetSuccessRecommandLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo auth.UserInfo) (resp *types.Response) { + // 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error") + resp = &types.Response{} + return resp +} diff --git a/product/internal/types/types.go b/product/internal/types/types.go index 46d0aefb..7c5bdc57 100644 --- a/product/internal/types/types.go +++ b/product/internal/types/types.go @@ -79,47 +79,54 @@ type Response struct { } // Set 设置Response的Code和Message值 -func (resp *Response) Set(Code int, Message string) { +func (resp *Response) Set(Code int, Message string) *Response { resp.Code = Code resp.Message = Message + return resp } // Set 设置整个Response -func (resp *Response) SetWithData(Code int, Message string, Data interface{}) { +func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response { resp.Code = Code resp.Message = Message resp.Data = Data + return resp } // SetMessage 设置Response的Message -func (resp *Response) SetMessage(msg string) { +func (resp *Response) SetMessage(msg string) *Response { resp.Message = msg + return resp } // SetWithData 设置Data -func (resp *Response) SetData(Data interface{}) { +func (resp *Response) SetData(Data interface{}) *Response { resp.Data = Data + return resp } // SetWithData 设置Response的Code和Message值 带Data入参数 -func (resp *Response) SetCode(Code int) { +func (resp *Response) SetCode(Code int) *Response { resp.Code = Code + return resp } // SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) { +func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response { resp.Code = sr.Code resp.Message = sr.Message if len(data) == 1 { resp.Data = data[0] } + return resp } // SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) { +func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response { resp.Code = sr.Code resp.Message = msg if len(data) == 1 { resp.Data = data[0] } + return resp } From 29f6e2ddbfee702fccde7f2dc60481fc33c7fff4 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 16:14:02 +0800 Subject: [PATCH 7/8] fix --- constants/api_response_code.go | 8 ++++ goctl_template/api/types.tpl | 21 ++++------ product/internal/logic/getproductlistlogic.go | 42 ++++++++++++------- product/internal/types/types.go | 21 ++++------ 4 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 constants/api_response_code.go diff --git a/constants/api_response_code.go b/constants/api_response_code.go new file mode 100644 index 00000000..28cfa20b --- /dev/null +++ b/constants/api_response_code.go @@ -0,0 +1,8 @@ +package constants + +// api接口code响应码 +const ( + CODE_UNAUTH = 401 //未授权 + CODE_SERVICE_ERR = 510 //内部代码错误 + CODE_OK = 200 //ok +) diff --git a/goctl_template/api/types.tpl b/goctl_template/api/types.tpl index 4cf86d10..b340c33d 100644 --- a/goctl_template/api/types.tpl +++ b/goctl_template/api/types.tpl @@ -8,55 +8,48 @@ import ( {{.types}} // Set 设置Response的Code和Message值 -func (resp *Response) Set(Code int, Message string) *Response{ +func (resp *Response) Set(Code int, Message string) { resp.Code = Code resp.Message = Message - return resp } // Set 设置整个Response -func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response{ +func (resp *Response) SetWithData(Code int, Message string, Data interface{}) { resp.Code = Code resp.Message = Message resp.Data = Data - return resp } // SetMessage 设置Response的Message -func (resp *Response) SetMessage(msg string) *Response{ +func (resp *Response) SetMessage(msg string) { resp.Message = msg - return resp } // SetWithData 设置Data -func (resp *Response) SetData(Data interface{}) *Response{ +func (resp *Response) SetData(Data interface{}) { resp.Data = Data - return resp } // SetWithData 设置Response的Code和Message值 带Data入参数 -func (resp *Response) SetCode(Code int) *Response{ +func (resp *Response) SetCode(Code int) { resp.Code = Code - return resp } // SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response{ +func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) { resp.Code = sr.Code resp.Message = sr.Message if len(data) == 1 { resp.Data = data[0] } - return resp } // SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response{ +func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) { resp.Code = sr.Code resp.Message = msg if len(data) == 1 { resp.Data = data[0] } - return resp } \ No newline at end of file diff --git a/product/internal/logic/getproductlistlogic.go b/product/internal/logic/getproductlistlogic.go index f3aa7d59..d5ca2886 100644 --- a/product/internal/logic/getproductlistlogic.go +++ b/product/internal/logic/getproductlistlogic.go @@ -36,18 +36,22 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge // 获取产品列表 func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response) { + resp = &types.Response{} + loginInfo.UserId = 83 //校验前台登录情况 if loginInfo.UserId == 0 { - return &types.Response{Code: 401, Message: "please sign in"} + resp.Set(constants.CODE_UNAUTH, "please sign in") + return } //如果是demo if req.IsDemo == 1 { var demo types.GetProductListRsp if err := json.Unmarshal([]byte(constants.PRODUCT_LIST_DEMO), &demo); err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "demo data format err"} + resp.Set(constants.CODE_SERVICE_ERR, "demo data format err") } - return &types.Response{Code: 200, Message: "success", Data: demo} + resp.SetWithData(constants.CODE_OK, "success", demo) + return } if req.Page <= 0 { req.Page = 1 @@ -61,22 +65,25 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId) if err != nil && !errors.Is(err, sqlc.ErrNotFound) { logx.Error(err) - return &types.Response{Code: 510, Message: "get user info err"} + resp.Set(constants.CODE_SERVICE_ERR, "get user info err") + return } if userInfo == nil { - return &types.Response{Code: 401, Message: "user not exists"} + resp.Set(constants.CODE_UNAUTH, "user not exists") + return } //查询符合的产品列表 productModel := model.NewFsProductModel(l.svcCtx.MysqlConn) productList, err := productModel.GetProductListByConditions(l.ctx, int(req.Cid), 0, 1, "sort-desc") if err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get product list"} + resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list") + return } - fmt.Println(len(productList)) productLen := len(productList) if productLen == 0 { - return &types.Response{Code: 200, Message: "success"} + resp.Set(constants.CODE_OK, "success") + return } //提取产品ids productIds := make([]string, 0, productLen) @@ -87,7 +94,8 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login productPriceList, err := productPriceModel.GetPriceList(l.ctx, productIds) if err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "failed to get product min price list"} + resp.Set(constants.CODE_SERVICE_ERR, "failed to get product min price list") + return } //存储产品最小价格 mapProductMinPrice := make(map[int64]int64) @@ -96,7 +104,8 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login priceSlice, err := format.StrSlicToIntSlice(priceStrSlic) if err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: err.Error()} + resp.Set(constants.CODE_SERVICE_ERR, err.Error()) + return } if len(priceSlice) == 0 { continue @@ -109,7 +118,8 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login productTemplatesV2, err := productTemplateModel.FindAllByCondition(l.ctx, productIds) if err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "get product template_v2 err"} + resp.Set(constants.CODE_SERVICE_ERR, "get product template_v2 err") + return } mapProductTemplate := make(map[int64]struct{}) for _, v := range productTemplatesV2 { @@ -120,7 +130,8 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login tagInfo, err := tagsModel.FindOne(l.ctx, req.Cid) if err != nil && !errors.Is(err, sqlc.ErrNotFound) { logx.Error(err) - return &types.Response{Code: 510, Message: "get classification err "} + resp.Set(constants.CODE_SERVICE_ERR, "get tag err") + return } if tagInfo == nil { return &types.Response{Code: 510, Message: "classification not exists "} @@ -130,7 +141,8 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login productSizeCount, err := productSizeModel.CountByStatus(l.ctx, 1) if err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "get product size count err "} + resp.Set(constants.CODE_SERVICE_ERR, "get product size count err") + return } //拼接返回 itemList := make([]types.Items, 0, productLen) @@ -176,10 +188,10 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login } itemList = append(itemList, item) } - return &types.Response{Code: 200, Message: "success", Data: types.GetProductListRsp{ + resp.SetWithData(constants.CODE_OK, "success", types.GetProductListRsp{ Ob: types.Ob{ Items: itemList, }, TypeName: tagInfo.Title, Description: tagInfo.Description, - }} + }) return } diff --git a/product/internal/types/types.go b/product/internal/types/types.go index 7c5bdc57..46d0aefb 100644 --- a/product/internal/types/types.go +++ b/product/internal/types/types.go @@ -79,54 +79,47 @@ type Response struct { } // Set 设置Response的Code和Message值 -func (resp *Response) Set(Code int, Message string) *Response { +func (resp *Response) Set(Code int, Message string) { resp.Code = Code resp.Message = Message - return resp } // Set 设置整个Response -func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response { +func (resp *Response) SetWithData(Code int, Message string, Data interface{}) { resp.Code = Code resp.Message = Message resp.Data = Data - return resp } // SetMessage 设置Response的Message -func (resp *Response) SetMessage(msg string) *Response { +func (resp *Response) SetMessage(msg string) { resp.Message = msg - return resp } // SetWithData 设置Data -func (resp *Response) SetData(Data interface{}) *Response { +func (resp *Response) SetData(Data interface{}) { resp.Data = Data - return resp } // SetWithData 设置Response的Code和Message值 带Data入参数 -func (resp *Response) SetCode(Code int) *Response { +func (resp *Response) SetCode(Code int) { resp.Code = Code - return resp } // SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response { +func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) { resp.Code = sr.Code resp.Message = sr.Message if len(data) == 1 { resp.Data = data[0] } - return resp } // SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数 -func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response { +func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) { resp.Code = sr.Code resp.Message = msg if len(data) == 1 { resp.Data = data[0] } - return resp } From 8ba0952cc56721311079d10a752c7400cbeec386 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 6 Jun 2023 17:18:01 +0800 Subject: [PATCH 8/8] fix --- model/fsproductmodel_gen.go | 1 + model/self_fsproductmodel.go | 17 +++++ product/internal/logic/getproductlistlogic.go | 1 - .../logic/getsuccessrecommandlogic.go | 65 ++++++++++++++++++- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/model/fsproductmodel_gen.go b/model/fsproductmodel_gen.go index 86bc2bb1..e9edc4d9 100755 --- a/model/fsproductmodel_gen.go +++ b/model/fsproductmodel_gen.go @@ -29,6 +29,7 @@ type ( Update(ctx context.Context, data *FsProduct) error Delete(ctx context.Context, id int64) error GetProductListByConditions(ctx context.Context, productType int, isDel int, isShelf int, sort string) ([]FsProduct, error) + GetAllProductList(ctx context.Context, isDel int, isShelf int, sort string) (resp []FsProduct, err error) } defaultFsProductModel struct { diff --git a/model/self_fsproductmodel.go b/model/self_fsproductmodel.go index 9384d052..8655bdae 100755 --- a/model/self_fsproductmodel.go +++ b/model/self_fsproductmodel.go @@ -24,3 +24,20 @@ func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, } return } +func (m *defaultFsProductModel) GetAllProductList(ctx context.Context, isDel int, isShelf int, sort string) (resp []FsProduct, err error) { + query := fmt.Sprintf("select %s from %s where `is_del` =? and `is_shelf` = ?", + fsProductRows, m.table) + switch sort { + case "sort-asc": + query = fmt.Sprintf("%s order by sort ASC", query) + case "sort-desc": + query = fmt.Sprintf("%s order by sort DESC", query) + default: + query = fmt.Sprintf("%s order by sort DESC", query) + } + err = m.conn.QueryRowsCtx(ctx, &resp, query, isDel, isShelf) + if err != nil { + return nil, err + } + return +} diff --git a/product/internal/logic/getproductlistlogic.go b/product/internal/logic/getproductlistlogic.go index d5ca2886..97fd6732 100644 --- a/product/internal/logic/getproductlistlogic.go +++ b/product/internal/logic/getproductlistlogic.go @@ -37,7 +37,6 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge // 获取产品列表 func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response) { resp = &types.Response{} - loginInfo.UserId = 83 //校验前台登录情况 if loginInfo.UserId == 0 { resp.Set(constants.CODE_UNAUTH, "please sign in") diff --git a/product/internal/logic/getsuccessrecommandlogic.go b/product/internal/logic/getsuccessrecommandlogic.go index e72b4a39..1fb4d3fd 100644 --- a/product/internal/logic/getsuccessrecommandlogic.go +++ b/product/internal/logic/getsuccessrecommandlogic.go @@ -2,10 +2,16 @@ package logic import ( "context" - "fusenapi/utils/auth" - + "errors" + "fmt" + "fusenapi/constants" + "fusenapi/model" "fusenapi/product/internal/svc" "fusenapi/product/internal/types" + "fusenapi/utils/auth" + "fusenapi/utils/image" + "github.com/zeromicro/go-zero/core/stores/sqlx" + "math/rand" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +31,60 @@ func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext } func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo auth.UserInfo) (resp *types.Response) { - // 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error") resp = &types.Response{} + //校验前台登录情况 + if loginInfo.UserId == 0 { + resp.Set(constants.CODE_UNAUTH, "please sign in") + return + } + //获取用户信息 + userModel := model.NewFsUserModel(l.svcCtx.MysqlConn) + userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId) + if err != nil && errors.Is(err, sqlx.ErrNotFound) { + logx.Error(err) + resp.Set(constants.CODE_SERVICE_ERR, "failed to get user info") + return + } + if userInfo == nil { + resp.Set(constants.CODE_UNAUTH, "failed to get user info") + return + } + if req.Num == 0 { + req.Num = 8 + } + if req.Size > 0 { + req.Size = image.GetCurrentSize(req.Size) + } + //获取所有产品的ids + productModel := model.NewFsProductModel(l.svcCtx.MysqlConn) + productList, err := productModel.GetAllProductList(l.ctx, 0, 1, "sort-asc") + if err != nil { + logx.Error(err) + resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list") + return + } + //没有推荐产品就返回 + if len(productList) == 0 { + resp.Set(constants.CODE_OK, "success") + return + } + productIds := make([]string, 0, len(productList)) + for _, v := range productList { + productIds = append(productIds, fmt.Sprintf("%d", v.Id)) + } + //随机取8个 + if len(productIds) > int(req.Num) { + //打乱顺序 + indexArr := rand.Perm(len(productIds)) + tmpProductIds := make([]string, 0, int(req.Num)) + for k, v := range indexArr { + if k == 8 { + break + } + tmpProductIds = append(tmpProductIds, productIds[v]) + } + productIds = tmpProductIds + } + return resp }