56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
|
|
package model
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||
|
|
)
|
||
|
|
|
||
|
|
var _ InvStockAdjustDetailModel = (*customInvStockAdjustDetailModel)(nil)
|
||
|
|
|
||
|
|
type (
|
||
|
|
InvStockAdjustDetailModel interface {
|
||
|
|
invStockAdjustDetailModel
|
||
|
|
FindByAdjustId(ctx context.Context, adjustId string) ([]*InvStockAdjustDetail, error)
|
||
|
|
BatchInsert(ctx context.Context, details []*InvStockAdjustDetail) error
|
||
|
|
}
|
||
|
|
|
||
|
|
customInvStockAdjustDetailModel struct {
|
||
|
|
*defaultInvStockAdjustDetailModel
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
func NewInvStockAdjustDetailModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) InvStockAdjustDetailModel {
|
||
|
|
return &customInvStockAdjustDetailModel{
|
||
|
|
defaultInvStockAdjustDetailModel: newInvStockAdjustDetailModel(conn, c, opts...),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *customInvStockAdjustDetailModel) FindByAdjustId(ctx context.Context, adjustId string) ([]*InvStockAdjustDetail, error) {
|
||
|
|
var list []*InvStockAdjustDetail
|
||
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE adjust_id = ?", invStockAdjustDetailRows, m.table)
|
||
|
|
err := m.QueryRowsNoCacheCtx(ctx, &list, query, adjustId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return list, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *customInvStockAdjustDetailModel) BatchInsert(ctx context.Context, details []*InvStockAdjustDetail) error {
|
||
|
|
if len(details) == 0 {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
values := make([]string, 0, len(details))
|
||
|
|
args := make([]interface{}, 0, len(details)*7)
|
||
|
|
for _, d := range details {
|
||
|
|
values = append(values, "(?, ?, ?, ?, ?, ?, ?)")
|
||
|
|
args = append(args, d.DetailId, d.AdjustId, d.ProductId, d.BeforeQuantity, d.AdjustQuantity, d.AfterQuantity, d.Remark)
|
||
|
|
}
|
||
|
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES %s", m.table, invStockAdjustDetailRowsExpectAutoSet, strings.Join(values, ","))
|
||
|
|
_, err := m.ExecNoCacheCtx(ctx, query, args...)
|
||
|
|
return err
|
||
|
|
}
|