2026-02-28 15:29:16 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ InvStockCheckModel = (*customInvStockCheckModel)(nil)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
InvStockCheckModel interface {
|
|
|
|
|
invStockCheckModel
|
2026-03-30 02:53:55 +00:00
|
|
|
FindList(ctx context.Context, tenantId string, page, pageSize int64, checkNo string, status int64, startDate, endDate string) ([]*InvStockCheck, int64, error)
|
2026-02-28 15:29:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
customInvStockCheckModel struct {
|
|
|
|
|
*defaultInvStockCheckModel
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func NewInvStockCheckModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) InvStockCheckModel {
|
|
|
|
|
return &customInvStockCheckModel{
|
|
|
|
|
defaultInvStockCheckModel: newInvStockCheckModel(conn, c, opts...),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 02:53:55 +00:00
|
|
|
func (m *customInvStockCheckModel) FindList(ctx context.Context, tenantId string, page, pageSize int64, checkNo string, status int64, startDate, endDate string) ([]*InvStockCheck, int64, error) {
|
|
|
|
|
where := "WHERE tenant_id = ?"
|
|
|
|
|
args := []interface{}{tenantId}
|
2026-02-28 15:29:16 +08:00
|
|
|
|
|
|
|
|
if checkNo != "" {
|
|
|
|
|
where += " AND check_no LIKE ?"
|
|
|
|
|
args = append(args, "%"+checkNo+"%")
|
|
|
|
|
}
|
|
|
|
|
if status != -1 {
|
|
|
|
|
where += " AND status = ?"
|
|
|
|
|
args = append(args, status)
|
|
|
|
|
}
|
|
|
|
|
if startDate != "" {
|
|
|
|
|
where += " AND check_date >= ?"
|
|
|
|
|
args = append(args, startDate)
|
|
|
|
|
}
|
|
|
|
|
if endDate != "" {
|
|
|
|
|
where += " AND check_date <= ?"
|
|
|
|
|
args = append(args, endDate)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var total int64
|
|
|
|
|
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s %s", m.table, where)
|
|
|
|
|
err := m.QueryRowNoCacheCtx(ctx, &total, countQuery, args...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list []*InvStockCheck
|
|
|
|
|
query := fmt.Sprintf("SELECT %s FROM %s %s ORDER BY created_at DESC LIMIT ? OFFSET ?", invStockCheckRows, m.table, where)
|
|
|
|
|
args = append(args, pageSize, (page-1)*pageSize)
|
|
|
|
|
err = m.QueryRowsNoCacheCtx(ctx, &list, query, args...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, 0, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list, total, nil
|
|
|
|
|
}
|