muyu-apiserver/model/invstockcheckmodel.go
Chever John 71a2d912e2 feat: initial commit for muyu-apiserver
Go service with gateway, RPC, model layers and k8s deploy configs.

Made-with: Cursor
2026-02-28 15:29:16 +08:00

68 lines
1.8 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 _ 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
}