108 lines
4.1 KiB
Go
Executable File
108 lines
4.1 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
|
|
|
package genModel
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
serverOrderPhysicalFieldNames = builder.RawFieldNames(&ServerOrderPhysical{})
|
|
serverOrderPhysicalRows = strings.Join(serverOrderPhysicalFieldNames, ",")
|
|
serverOrderPhysicalRowsExpectAutoSet = strings.Join(stringx.Remove(serverOrderPhysicalFieldNames, "`order_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
serverOrderPhysicalRowsWithPlaceHolder = strings.Join(stringx.Remove(serverOrderPhysicalFieldNames, "`order_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
serverOrderPhysicalModel interface {
|
|
Insert(ctx context.Context, data *ServerOrderPhysical) (sql.Result, error)
|
|
FindOne(ctx context.Context, orderId uint64) (*ServerOrderPhysical, error)
|
|
Update(ctx context.Context, data *ServerOrderPhysical) error
|
|
Delete(ctx context.Context, orderId uint64) error
|
|
FindByOutBizId(ctx context.Context, outBizId string) (*ServerOrderPhysical, error)
|
|
}
|
|
|
|
defaultServerOrderPhysicalModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
ServerOrderPhysical struct {
|
|
OrderId uint64 `db:"order_id"`
|
|
CustomerOrderNum string `db:"customer_order_num"` // 用户侧流水号
|
|
OrderNum string `db:"order_num"` // 平台订单号
|
|
Num int64 `db:"num"` // 购买数量
|
|
AppId string `db:"app_id"` // 平台商户号
|
|
LogId int64 `db:"log_id"` // 对应的日志id
|
|
ReqTime time.Time `db:"req_time"` // 请求时间
|
|
CreateTime time.Time `db:"create_time"`
|
|
UpdateTime time.Time `db:"update_time"`
|
|
Status int64 `db:"status"` // 状态
|
|
}
|
|
)
|
|
|
|
func newServerOrderPhysicalModel(conn sqlx.SqlConn) *defaultServerOrderPhysicalModel {
|
|
return &defaultServerOrderPhysicalModel{
|
|
conn: conn,
|
|
table: "`server_order_physical`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultServerOrderPhysicalModel) Delete(ctx context.Context, orderId uint64) error {
|
|
query := fmt.Sprintf("delete from %s where `order_id` = ?", m.table)
|
|
_, err := m.conn.ExecCtx(ctx, query, orderId)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultServerOrderPhysicalModel) FindOne(ctx context.Context, orderId uint64) (*ServerOrderPhysical, error) {
|
|
query := fmt.Sprintf("select %s from %s where `order_id` = ? limit 1", serverOrderPhysicalRows, m.table)
|
|
var resp ServerOrderPhysical
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, orderId)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultServerOrderPhysicalModel) Insert(ctx context.Context, data *ServerOrderPhysical) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, serverOrderPhysicalRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.CustomerOrderNum, data.OrderNum, data.Num, data.AppId, data.LogId, data.ReqTime, data.Status)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultServerOrderPhysicalModel) Update(ctx context.Context, data *ServerOrderPhysical) error {
|
|
query := fmt.Sprintf("update %s set %s where `order_id` = ?", m.table, serverOrderPhysicalRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, data.CustomerOrderNum, data.OrderNum, data.Num, data.AppId, data.LogId, data.ReqTime, data.Status, data.OrderId)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultServerOrderPhysicalModel) FindByOutBizId(ctx context.Context, outBizId string) (*ServerOrderPhysical, error) {
|
|
query := fmt.Sprintf("select %s from %s where `customer_order_num` = ? limit 1", serverOrderPhysicalRows, m.table)
|
|
var resp ServerOrderPhysical
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, outBizId)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultServerOrderPhysicalModel) tableName() string {
|
|
return m.table
|
|
}
|