47 lines
1.3 KiB
Go
Executable File
47 lines
1.3 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ InvStockImportLogModel = (*customInvStockImportLogModel)(nil)
|
|
|
|
type (
|
|
InvStockImportLogModel interface {
|
|
invStockImportLogModel
|
|
FindList(ctx context.Context, page, pageSize int64) ([]*InvStockImportLog, int64, error)
|
|
}
|
|
|
|
customInvStockImportLogModel struct {
|
|
*defaultInvStockImportLogModel
|
|
}
|
|
)
|
|
|
|
func NewInvStockImportLogModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) InvStockImportLogModel {
|
|
return &customInvStockImportLogModel{
|
|
defaultInvStockImportLogModel: newInvStockImportLogModel(conn, c, opts...),
|
|
}
|
|
}
|
|
|
|
func (m *customInvStockImportLogModel) FindList(ctx context.Context, page, pageSize int64) ([]*InvStockImportLog, int64, error) {
|
|
var total int64
|
|
countQuery := fmt.Sprintf("SELECT COUNT(*) FROM %s", m.table)
|
|
err := m.QueryRowNoCacheCtx(ctx, &total, countQuery)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
var list []*InvStockImportLog
|
|
query := fmt.Sprintf("SELECT %s FROM %s ORDER BY created_at DESC LIMIT ? OFFSET ?", invStockImportLogRows, m.table)
|
|
err = m.QueryRowsNoCacheCtx(ctx, &list, query, pageSize, (page-1)*pageSize)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
return list, total, nil
|
|
}
|