109 lines
4.0 KiB
Go
Executable File
109 lines
4.0 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 (
|
|
serverOrderZltxFieldNames = builder.RawFieldNames(&ServerOrderZltx{})
|
|
serverOrderZltxRows = strings.Join(serverOrderZltxFieldNames, ",")
|
|
serverOrderZltxRowsExpectAutoSet = strings.Join(stringx.Remove(serverOrderZltxFieldNames, "`order_id`", "`create_at`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
serverOrderZltxRowsWithPlaceHolder = strings.Join(stringx.Remove(serverOrderZltxFieldNames, "`order_id`", "`create_at`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
serverOrderZltxModel interface {
|
|
Insert(ctx context.Context, data *ServerOrderZltx) (sql.Result, error)
|
|
FindOne(ctx context.Context, orderId uint64) (*ServerOrderZltx, error)
|
|
FindOneByBizNo(ctx context.Context, orderId string) (*ServerOrderZltx, error)
|
|
Update(ctx context.Context, data *ServerOrderZltx) error
|
|
Delete(ctx context.Context, orderId uint64) error
|
|
}
|
|
|
|
defaultServerOrderZltxModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
ServerOrderZltx struct {
|
|
OrderId uint64 `db:"order_id"`
|
|
OutBizNo string `db:"out_biz_no"` // 用户侧流水号
|
|
VoucherNum string `db:"voucher_num"` // 商户号
|
|
OrderNum string `db:"order_num"` // 系统侧订单号
|
|
ProductId int64 `db:"product_id"` // 平台提供商品id
|
|
Num int64 `db:"num"` // 购买数量
|
|
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 newServerOrderZltxModel(conn sqlx.SqlConn) *defaultServerOrderZltxModel {
|
|
return &defaultServerOrderZltxModel{
|
|
conn: conn,
|
|
table: "`server_order_zltx`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultServerOrderZltxModel) 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 *defaultServerOrderZltxModel) FindOne(ctx context.Context, orderId uint64) (*ServerOrderZltx, error) {
|
|
query := fmt.Sprintf("select %s from %s where `order_id` = ? limit 1", serverOrderZltxRows, m.table)
|
|
var resp ServerOrderZltx
|
|
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 *defaultServerOrderZltxModel) FindOneByBizNo(ctx context.Context, ountBizNo string) (*ServerOrderZltx, error) {
|
|
query := fmt.Sprintf("select %s from %s where `out_biz_no` = ? limit 1", serverOrderZltxRows, m.table)
|
|
var resp ServerOrderZltx
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, ountBizNo)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultServerOrderZltxModel) Insert(ctx context.Context, data *ServerOrderZltx) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?,?)", m.table, serverOrderZltxRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.OutBizNo, data.VoucherNum, data.OrderNum, data.ProductId, data.Num, data.LogId, data.ReqTime, data.CreateTime, data.Status)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultServerOrderZltxModel) Update(ctx context.Context, data *ServerOrderZltx) error {
|
|
query := fmt.Sprintf("update %s set %s where `order_id` = ?", m.table, serverOrderZltxRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, data.OutBizNo, data.VoucherNum, data.OrderNum, data.ProductId, data.Num, data.LogId, data.ReqTime, data.Status, data.OrderId)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultServerOrderZltxModel) tableName() string {
|
|
return m.table
|
|
}
|