181 lines
7.5 KiB
Go
Executable File
181 lines
7.5 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
|
// versions:
|
|
// goctl version: 1.9.2
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
invStockAdjustFieldNames = builder.RawFieldNames(&InvStockAdjust{})
|
|
invStockAdjustRows = strings.Join(invStockAdjustFieldNames, ",")
|
|
invStockAdjustRowsExpectAutoSet = strings.Join(stringx.Remove(invStockAdjustFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
invStockAdjustRowsWithPlaceHolder = strings.Join(stringx.Remove(invStockAdjustFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
|
|
cacheInvStockAdjustIdPrefix = "cache:invStockAdjust:id:"
|
|
cacheInvStockAdjustAdjustIdPrefix = "cache:invStockAdjust:adjustId:"
|
|
cacheInvStockAdjustAdjustNoPrefix = "cache:invStockAdjust:adjustNo:"
|
|
)
|
|
|
|
type (
|
|
invStockAdjustModel interface {
|
|
Insert(ctx context.Context, data *InvStockAdjust) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int64) (*InvStockAdjust, error)
|
|
FindOneByAdjustId(ctx context.Context, adjustId string) (*InvStockAdjust, error)
|
|
FindOneByAdjustNo(ctx context.Context, adjustNo string) (*InvStockAdjust, error)
|
|
Update(ctx context.Context, data *InvStockAdjust) error
|
|
Delete(ctx context.Context, id int64) error
|
|
}
|
|
|
|
defaultInvStockAdjustModel struct {
|
|
sqlc.CachedConn
|
|
table string
|
|
}
|
|
|
|
InvStockAdjust struct {
|
|
Id int64 `db:"id"`
|
|
AdjustId string `db:"adjust_id"`
|
|
AdjustNo string `db:"adjust_no"`
|
|
AdjustDate time.Time `db:"adjust_date"`
|
|
AdjustReason string `db:"adjust_reason"`
|
|
Operator string `db:"operator"`
|
|
Approver string `db:"approver"`
|
|
Status int64 `db:"status"` // 0:pending 1:approved 2:rejected
|
|
Remark sql.NullString `db:"remark"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at"`
|
|
}
|
|
)
|
|
|
|
func newInvStockAdjustModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultInvStockAdjustModel {
|
|
return &defaultInvStockAdjustModel{
|
|
CachedConn: sqlc.NewConn(conn, c, opts...),
|
|
table: "`inv_stock_adjust`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) Delete(ctx context.Context, id int64) error {
|
|
data, err := m.FindOne(ctx, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
invStockAdjustAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustIdPrefix, data.AdjustId)
|
|
invStockAdjustAdjustNoKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustNoPrefix, data.AdjustNo)
|
|
invStockAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustIdPrefix, id)
|
|
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
return conn.ExecCtx(ctx, query, id)
|
|
}, invStockAdjustAdjustIdKey, invStockAdjustAdjustNoKey, invStockAdjustIdKey)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) FindOne(ctx context.Context, id int64) (*InvStockAdjust, error) {
|
|
invStockAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustIdPrefix, id)
|
|
var resp InvStockAdjust
|
|
err := m.QueryRowCtx(ctx, &resp, invStockAdjustIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", invStockAdjustRows, m.table)
|
|
return conn.QueryRowCtx(ctx, v, query, id)
|
|
})
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) FindOneByAdjustId(ctx context.Context, adjustId string) (*InvStockAdjust, error) {
|
|
invStockAdjustAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustIdPrefix, adjustId)
|
|
var resp InvStockAdjust
|
|
err := m.QueryRowIndexCtx(ctx, &resp, invStockAdjustAdjustIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
|
query := fmt.Sprintf("select %s from %s where `adjust_id` = ? limit 1", invStockAdjustRows, m.table)
|
|
if err := conn.QueryRowCtx(ctx, &resp, query, adjustId); err != nil {
|
|
return nil, err
|
|
}
|
|
return resp.Id, nil
|
|
}, m.queryPrimary)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) FindOneByAdjustNo(ctx context.Context, adjustNo string) (*InvStockAdjust, error) {
|
|
invStockAdjustAdjustNoKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustNoPrefix, adjustNo)
|
|
var resp InvStockAdjust
|
|
err := m.QueryRowIndexCtx(ctx, &resp, invStockAdjustAdjustNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
|
|
query := fmt.Sprintf("select %s from %s where `adjust_no` = ? limit 1", invStockAdjustRows, m.table)
|
|
if err := conn.QueryRowCtx(ctx, &resp, query, adjustNo); err != nil {
|
|
return nil, err
|
|
}
|
|
return resp.Id, nil
|
|
}, m.queryPrimary)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) Insert(ctx context.Context, data *InvStockAdjust) (sql.Result, error) {
|
|
invStockAdjustAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustIdPrefix, data.AdjustId)
|
|
invStockAdjustAdjustNoKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustNoPrefix, data.AdjustNo)
|
|
invStockAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustIdPrefix, data.Id)
|
|
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, invStockAdjustRowsExpectAutoSet)
|
|
return conn.ExecCtx(ctx, query, data.AdjustId, data.AdjustNo, data.AdjustDate, data.AdjustReason, data.Operator, data.Approver, data.Status, data.Remark)
|
|
}, invStockAdjustAdjustIdKey, invStockAdjustAdjustNoKey, invStockAdjustIdKey)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) Update(ctx context.Context, newData *InvStockAdjust) error {
|
|
data, err := m.FindOne(ctx, newData.Id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
invStockAdjustAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustIdPrefix, data.AdjustId)
|
|
invStockAdjustAdjustNoKey := fmt.Sprintf("%s%v", cacheInvStockAdjustAdjustNoPrefix, data.AdjustNo)
|
|
invStockAdjustIdKey := fmt.Sprintf("%s%v", cacheInvStockAdjustIdPrefix, data.Id)
|
|
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, invStockAdjustRowsWithPlaceHolder)
|
|
return conn.ExecCtx(ctx, query, newData.AdjustId, newData.AdjustNo, newData.AdjustDate, newData.AdjustReason, newData.Operator, newData.Approver, newData.Status, newData.Remark, newData.Id)
|
|
}, invStockAdjustAdjustIdKey, invStockAdjustAdjustNoKey, invStockAdjustIdKey)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) formatPrimary(primary any) string {
|
|
return fmt.Sprintf("%s%v", cacheInvStockAdjustIdPrefix, primary)
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", invStockAdjustRows, m.table)
|
|
return conn.QueryRowCtx(ctx, v, query, primary)
|
|
}
|
|
|
|
func (m *defaultInvStockAdjustModel) tableName() string {
|
|
return m.table
|
|
}
|