package model import ( "context" "fmt" "github.com/zeromicro/go-zero/core/stores/cache" "github.com/zeromicro/go-zero/core/stores/sqlx" ) var _ InvStockAdjustModel = (*customInvStockAdjustModel)(nil) type ( InvStockAdjustModel interface { invStockAdjustModel FindList(ctx context.Context, tenantId string, page, pageSize int64, adjustNo, adjustReason string, status int64, startDate, endDate string) ([]*InvStockAdjust, int64, error) } customInvStockAdjustModel struct { *defaultInvStockAdjustModel } ) func NewInvStockAdjustModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) InvStockAdjustModel { return &customInvStockAdjustModel{ defaultInvStockAdjustModel: newInvStockAdjustModel(conn, c, opts...), } } func (m *customInvStockAdjustModel) FindList(ctx context.Context, tenantId string, page, pageSize int64, adjustNo, adjustReason string, status int64, startDate, endDate string) ([]*InvStockAdjust, int64, error) { where := "WHERE tenant_id = ?" args := []interface{}{tenantId} if adjustNo != "" { where += " AND adjust_no LIKE ?" args = append(args, "%"+adjustNo+"%") } if adjustReason != "" { where += " AND adjust_reason LIKE ?" args = append(args, "%"+adjustReason+"%") } if status != -1 { where += " AND status = ?" args = append(args, status) } if startDate != "" { where += " AND adjust_date >= ?" args = append(args, startDate) } if endDate != "" { where += " AND adjust_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 []*InvStockAdjust query := fmt.Sprintf("SELECT %s FROM %s %s ORDER BY created_at DESC LIMIT ? OFFSET ?", invStockAdjustRows, 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 }