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 FindList(ctx context.Context, page, pageSize int64, checkNo string, status int64, startDate, endDate string) ([]*InvStockCheck, int64, error) } customInvStockCheckModel struct { *defaultInvStockCheckModel } ) func NewInvStockCheckModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) InvStockCheckModel { return &customInvStockCheckModel{ defaultInvStockCheckModel: newInvStockCheckModel(conn, c, opts...), } } func (m *customInvStockCheckModel) FindList(ctx context.Context, page, pageSize int64, checkNo string, status int64, startDate, endDate string) ([]*InvStockCheck, int64, error) { where := "WHERE 1=1" args := make([]interface{}, 0) 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 }