fusenapi/model/fsproductmodel_gen.go
laodaming 213665eb59 fix
2023-06-06 13:07:39 +08:00

128 lines
6.4 KiB
Go
Executable File

// 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 (
fsProductFieldNames = builder.RawFieldNames(&FsProduct{})
fsProductRows = strings.Join(fsProductFieldNames, ",")
fsProductRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsProductRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
fsProductModel interface {
Insert(ctx context.Context, data *FsProduct) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsProduct, error)
FindOneBySn(ctx context.Context, sn string) (*FsProduct, error)
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)
}
defaultFsProductModel struct {
conn sqlx.SqlConn
table string
}
FsProduct struct {
Id int64 `db:"id"`
Sn string `db:"sn"` // 商品编号 P98f087j
Type int64 `db:"type"` // 分类ID
Title string `db:"title"` // 名称
TitleCn string `db:"title_cn"` // 中文名称
Cover string `db:"cover"` // 封面图
Imgs string `db:"imgs"` // 一个或多个介绍图或视频
Keywords string `db:"keywords"` // 关键字
Intro sql.NullString `db:"intro"` // 简要描述
Sort int64 `db:"sort"` // 排序
SelledNum int64 `db:"selled_num"` // 已卖数量
Ctime sql.NullInt64 `db:"ctime"` // 添加时间
View int64 `db:"view"` // 浏览量
SizeIds sql.NullString `db:"size_ids"` // 尺寸 1,2,3,4
MaterialIds string `db:"material_ids"` // 材质 1,2,3
TagIds sql.NullString `db:"tag_ids"` // 标签 逗号间隔
Status int64 `db:"status"` // 状态位 弃用
ProduceDays int64 `db:"produce_days"` // 生产天数
DeliveryDays int64 `db:"delivery_days"` // 运送天数
CoverImg string `db:"cover_img"` // 背景图
IsShelf int64 `db:"is_shelf"` // 是否上架
IsRecommend int64 `db:"is_recommend"` // 是否推荐
IsHot int64 `db:"is_hot"` // 是否热销
IsProtection int64 `db:"is_protection"` // 是否环保
IsMicrowave int64 `db:"is_microwave"` // 是否可微波炉
IsDel int64 `db:"is_del"` // 是否删除
RecommendProduct sql.NullString `db:"recommend_product"` // 推荐产品id例如: 1,3,4,5
RecommendProductSort sql.NullString `db:"recommend_product_sort"` // 推荐排序例如:1324
SceneIds sql.NullString `db:"scene_ids"` // 关联的场景id
}
)
func newFsProductModel(conn sqlx.SqlConn) *defaultFsProductModel {
return &defaultFsProductModel{
conn: conn,
table: "`fs_product`",
}
}
func (m *defaultFsProductModel) 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 *defaultFsProductModel) FindOne(ctx context.Context, id int64) (*FsProduct, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductRows, m.table)
var resp FsProduct
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 *defaultFsProductModel) FindOneBySn(ctx context.Context, sn string) (*FsProduct, error) {
var resp FsProduct
query := fmt.Sprintf("select %s from %s where `sn` = ? limit 1", fsProductRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, sn)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultFsProductModel) Insert(ctx context.Context, data *FsProduct) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Sn, data.Type, data.Title, data.TitleCn, data.Cover, data.Imgs, data.Keywords, data.Intro, data.Sort, data.SelledNum, data.Ctime, data.View, data.SizeIds, data.MaterialIds, data.TagIds, data.Status, data.ProduceDays, data.DeliveryDays, data.CoverImg, data.IsShelf, data.IsRecommend, data.IsHot, data.IsProtection, data.IsMicrowave, data.IsDel, data.RecommendProduct, data.RecommendProductSort, data.SceneIds)
return ret, err
}
func (m *defaultFsProductModel) Update(ctx context.Context, newData *FsProduct) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Sn, newData.Type, newData.Title, newData.TitleCn, newData.Cover, newData.Imgs, newData.Keywords, newData.Intro, newData.Sort, newData.SelledNum, newData.Ctime, newData.View, newData.SizeIds, newData.MaterialIds, newData.TagIds, newData.Status, newData.ProduceDays, newData.DeliveryDays, newData.CoverImg, newData.IsShelf, newData.IsRecommend, newData.IsHot, newData.IsProtection, newData.IsMicrowave, newData.IsDel, newData.RecommendProduct, newData.RecommendProductSort, newData.SceneIds, newData.Id)
return err
}
func (m *defaultFsProductModel) tableName() string {
return m.table
}