109 lines
3.9 KiB
Go
Executable File
109 lines
3.9 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 (
|
|
serverOrderRsFieldNames = builder.RawFieldNames(&ServerOrderRs{})
|
|
serverOrderRsRows = strings.Join(serverOrderRsFieldNames, ",")
|
|
serverOrderRsRowsExpectAutoSet = strings.Join(stringx.Remove(serverOrderRsFieldNames, "`order_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
serverOrderRsRowsWithPlaceHolder = strings.Join(stringx.Remove(serverOrderRsFieldNames, "`order_id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
serverOrderRsModel interface {
|
|
Insert(ctx context.Context, data *ServerOrderRs) (sql.Result, error)
|
|
FindOne(ctx context.Context, orderId uint64) (*ServerOrderRs, error)
|
|
FindByOutBizId(ctx context.Context, outBizId string) (*ServerOrderRs, error)
|
|
Update(ctx context.Context, data *ServerOrderRs) error
|
|
Delete(ctx context.Context, orderId uint64) error
|
|
}
|
|
|
|
defaultServerOrderRsModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
ServerOrderRs 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 newServerOrderRsModel(conn sqlx.SqlConn) *defaultServerOrderRsModel {
|
|
return &defaultServerOrderRsModel{
|
|
conn: conn,
|
|
table: "`server_order_rs`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultServerOrderRsModel) 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 *defaultServerOrderRsModel) FindOne(ctx context.Context, orderId uint64) (*ServerOrderRs, error) {
|
|
query := fmt.Sprintf("select %s from %s where `order_id` = ? limit 1", serverOrderRsRows, m.table)
|
|
var resp ServerOrderRs
|
|
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 *defaultServerOrderRsModel) FindByOutBizId(ctx context.Context, outBizId string) (*ServerOrderRs, error) {
|
|
query := fmt.Sprintf("select %s from %s where `out_biz_id` = ? limit 1", serverOrderRsRows, m.table)
|
|
var resp ServerOrderRs
|
|
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 *defaultServerOrderRsModel) Insert(ctx context.Context, data *ServerOrderRs) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, serverOrderRsRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.OutBizNo, data.VoucherNum, data.OrderNum, data.ProductId, data.Num, data.LogId, data.ReqTime, data.Status)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultServerOrderRsModel) Update(ctx context.Context, data *ServerOrderRs) error {
|
|
query := fmt.Sprintf("update %s set %s where `order_id` = ?", m.table, serverOrderRsRowsWithPlaceHolder)
|
|
_, 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 *defaultServerOrderRsModel) tableName() string {
|
|
return m.table
|
|
}
|