fix
This commit is contained in:
38
model/fscanteenproductmodel.go
Executable file
38
model/fscanteenproductmodel.go
Executable file
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ FsCanteenProductModel = (*customFsCanteenProductModel)(nil)
|
||||
|
||||
type (
|
||||
// FsCanteenProductModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customFsCanteenProductModel.
|
||||
FsCanteenProductModel interface {
|
||||
fsCanteenProductModel
|
||||
GetAllByCanteenTypeId(ctx context.Context, canteenTypeId int64) (resp []FsCanteenProduct, err error)
|
||||
}
|
||||
|
||||
customFsCanteenProductModel struct {
|
||||
*defaultFsCanteenProductModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewFsCanteenProductModel returns a model for the database table.
|
||||
func NewFsCanteenProductModel(conn sqlx.SqlConn) FsCanteenProductModel {
|
||||
return &customFsCanteenProductModel{
|
||||
defaultFsCanteenProductModel: newFsCanteenProductModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsCanteenProductModel) GetAllByCanteenTypeId(ctx context.Context, canteenTypeId int64) (resp []FsCanteenProduct, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `canteen_type` = ? and `status` = ?", fsCanteenProductRows, m.table)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, canteenTypeId, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
90
model/fscanteenproductmodel_gen.go
Executable file
90
model/fscanteenproductmodel_gen.go
Executable file
@@ -0,0 +1,90 @@
|
||||
// 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 (
|
||||
fsCanteenProductFieldNames = builder.RawFieldNames(&FsCanteenProduct{})
|
||||
fsCanteenProductRows = strings.Join(fsCanteenProductFieldNames, ",")
|
||||
fsCanteenProductRowsExpectAutoSet = strings.Join(stringx.Remove(fsCanteenProductFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
fsCanteenProductRowsWithPlaceHolder = strings.Join(stringx.Remove(fsCanteenProductFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
fsCanteenProductModel interface {
|
||||
Insert(ctx context.Context, data *FsCanteenProduct) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*FsCanteenProduct, error)
|
||||
Update(ctx context.Context, data *FsCanteenProduct) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultFsCanteenProductModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
FsCanteenProduct struct {
|
||||
Id int64 `db:"id"` // ID
|
||||
CanteenType int64 `db:"canteen_type"` // 餐厅类别id
|
||||
ProductId int64 `db:"product_id"` // 产品id
|
||||
SizeId int64 `db:"size_id"` // 尺寸id
|
||||
Sort int64 `db:"sort"` // 排序
|
||||
Status int64 `db:"status"` // 状态位 1启用0停用
|
||||
Ctime int64 `db:"ctime"` // 添加时间
|
||||
Sid string `db:"sid"` // 前端带入的id
|
||||
}
|
||||
)
|
||||
|
||||
func newFsCanteenProductModel(conn sqlx.SqlConn) *defaultFsCanteenProductModel {
|
||||
return &defaultFsCanteenProductModel{
|
||||
conn: conn,
|
||||
table: "`fs_canteen_product`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsCanteenProductModel) 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 *defaultFsCanteenProductModel) FindOne(ctx context.Context, id int64) (*FsCanteenProduct, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsCanteenProductRows, m.table)
|
||||
var resp FsCanteenProduct
|
||||
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 *defaultFsCanteenProductModel) Insert(ctx context.Context, data *FsCanteenProduct) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, fsCanteenProductRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.CanteenType, data.ProductId, data.SizeId, data.Sort, data.Status, data.Ctime, data.Sid)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultFsCanteenProductModel) Update(ctx context.Context, data *FsCanteenProduct) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsCanteenProductRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.CanteenType, data.ProductId, data.SizeId, data.Sort, data.Status, data.Ctime, data.Sid, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultFsCanteenProductModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
|
||||
@@ -16,6 +16,7 @@ type (
|
||||
fsProductModel
|
||||
GetProductListByConditions(ctx context.Context, productTypes []string, sort string) ([]FsProduct, error)
|
||||
GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error)
|
||||
GetProductListByIds(ctx context.Context, ids []string, sort string) (resp []FsProduct, err error)
|
||||
}
|
||||
|
||||
customFsProductModel struct {
|
||||
@@ -55,3 +56,20 @@ func (m *defaultFsProductModel) GetRandomProductList(ctx context.Context, limit
|
||||
}
|
||||
return
|
||||
}
|
||||
func (m *defaultFsProductModel) GetProductListByIds(ctx context.Context, ids []string, sort string) (resp []FsProduct, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?",
|
||||
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, strings.Join(ids, ","), 0, 1, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ type (
|
||||
FsProductSizeModel interface {
|
||||
fsProductSizeModel
|
||||
CountByStatus(ctx context.Context, status int) (total int, err error)
|
||||
FindAllByProductIds(ctx context.Context, productIds []string, sort int) (resp []FsProductSize, err error)
|
||||
GetAllByProductIds(ctx context.Context, productIds []string, sort string) (resp []FsProductSize, err error)
|
||||
GetAllByiIds(ctx context.Context, ids []string, sort string) (resp []FsProductSize, err error)
|
||||
}
|
||||
|
||||
customFsProductSizeModel struct {
|
||||
@@ -37,12 +38,12 @@ func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status in
|
||||
}
|
||||
return
|
||||
}
|
||||
func (m *defaultFsProductSizeModel) FindAllByProductIds(ctx context.Context, productIds []string, sort int) (resp []FsProductSize, err error) {
|
||||
func (m *defaultFsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []string, sort string) (resp []FsProductSize, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_id` in(?) and `status` = ? ", fsProductSizeRows, m.table)
|
||||
switch sort {
|
||||
case 1:
|
||||
case "sort-asc":
|
||||
query = fmt.Sprintf("%s order by `sort` ASC", query)
|
||||
case 2:
|
||||
case "sort-desc":
|
||||
query = fmt.Sprintf("%s order by `sort` DESC", query)
|
||||
}
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 1)
|
||||
@@ -51,3 +52,18 @@ func (m *defaultFsProductSizeModel) FindAllByProductIds(ctx context.Context, pro
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *defaultFsProductSizeModel) GetAllByiIds(ctx context.Context, ids []string, sort string) (resp []FsProductSize, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` in(?) and `status` = ? ", fsProductSizeRows, 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)
|
||||
}
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(ids, ","), 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ FsTagsModel = (*customFsTagsModel)(nil)
|
||||
@@ -13,7 +14,8 @@ type (
|
||||
// and implement the added methods in customFsTagsModel.
|
||||
FsTagsModel interface {
|
||||
fsTagsModel
|
||||
ListAllByLevelStatus(ctx context.Context, level int, status int) (resp []FsTags, err error)
|
||||
GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error)
|
||||
GetAllByIds(ctx context.Context, ids []string) (resp []FsTags, err error)
|
||||
}
|
||||
|
||||
customFsTagsModel struct {
|
||||
@@ -28,9 +30,17 @@ func NewFsTagsModel(conn sqlx.SqlConn) FsTagsModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsTagsModel) ListAllByLevelStatus(ctx context.Context, level int, status int) (resp []FsTags, err error) {
|
||||
func (m *defaultFsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `level` = ? and `status` = ?", fsTagsRows, m.table)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, level, status)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, level, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
func (m *defaultFsTagsModel) GetAllByIds(ctx context.Context, ids []string) (resp []FsTags, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` in (?) and `status` = ?", fsTagsRows, m.table)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(ids, ","), 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user