109 lines
4.4 KiB
Go
Executable File
109 lines
4.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 (
|
|
fsOrderDetailTemplateFieldNames = builder.RawFieldNames(&FsOrderDetailTemplate{})
|
|
fsOrderDetailTemplateRows = strings.Join(fsOrderDetailTemplateFieldNames, ",")
|
|
fsOrderDetailTemplateRowsExpectAutoSet = strings.Join(stringx.Remove(fsOrderDetailTemplateFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
fsOrderDetailTemplateRowsWithPlaceHolder = strings.Join(stringx.Remove(fsOrderDetailTemplateFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
fsOrderDetailTemplateModel interface {
|
|
Insert(ctx context.Context, data *FsOrderDetailTemplate) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int64) (*FsOrderDetailTemplate, error)
|
|
FindOneBySn(ctx context.Context, sn string) (*FsOrderDetailTemplate, error)
|
|
Update(ctx context.Context, data *FsOrderDetailTemplate) error
|
|
Delete(ctx context.Context, id int64) error
|
|
}
|
|
|
|
defaultFsOrderDetailTemplateModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
FsOrderDetailTemplate struct {
|
|
Id int64 `db:"id"`
|
|
Sn string `db:"sn"` // 唯一编码
|
|
ProductId int64 `db:"product_id"` // 产品ID
|
|
ModelId int64 `db:"model_id"` // 模型ID
|
|
TemplateId int64 `db:"template_id"` // 模板ID
|
|
MaterialId int64 `db:"material_id"` // 材质id
|
|
SizeId int64 `db:"size_id"` // 尺寸id
|
|
EachBoxNum int64 `db:"each_box_num"` // 每一箱的个数
|
|
EachBoxWeight float64 `db:"each_box_weight"` // 每一箱的重量 单位KG
|
|
DesignId int64 `db:"design_id"` // 设计ID
|
|
Ctime sql.NullInt64 `db:"ctime"` // 添加时间
|
|
}
|
|
)
|
|
|
|
func newFsOrderDetailTemplateModel(conn sqlx.SqlConn) *defaultFsOrderDetailTemplateModel {
|
|
return &defaultFsOrderDetailTemplateModel{
|
|
conn: conn,
|
|
table: "`fs_order_detail_template`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailTemplateModel) 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 *defaultFsOrderDetailTemplateModel) FindOne(ctx context.Context, id int64) (*FsOrderDetailTemplate, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsOrderDetailTemplateRows, m.table)
|
|
var resp FsOrderDetailTemplate
|
|
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 *defaultFsOrderDetailTemplateModel) FindOneBySn(ctx context.Context, sn string) (*FsOrderDetailTemplate, error) {
|
|
var resp FsOrderDetailTemplate
|
|
query := fmt.Sprintf("select %s from %s where `sn` = ? limit 1", fsOrderDetailTemplateRows, 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 *defaultFsOrderDetailTemplateModel) Insert(ctx context.Context, data *FsOrderDetailTemplate) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsOrderDetailTemplateRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Sn, data.ProductId, data.ModelId, data.TemplateId, data.MaterialId, data.SizeId, data.EachBoxNum, data.EachBoxWeight, data.DesignId, data.Ctime)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailTemplateModel) Update(ctx context.Context, newData *FsOrderDetailTemplate) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsOrderDetailTemplateRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, newData.Sn, newData.ProductId, newData.ModelId, newData.TemplateId, newData.MaterialId, newData.SizeId, newData.EachBoxNum, newData.EachBoxWeight, newData.DesignId, newData.Ctime, newData.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultFsOrderDetailTemplateModel) tableName() string {
|
|
return m.table
|
|
}
|