approveflow/app/infrastructure/kernel.go

30 lines
833 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package infrastructure
import (
"github.com/Superdanda/hade/framework"
"gorm.io/gorm"
)
func NewOrmRepositoryAndRegister(container framework.Container) {
NewOrmFlowRepositoryImplAndRegister(container)
NewOrmInstanceRepositoryImplAndRegister(container)
}
// ListFlows 泛型分页查询方法
func ListFlows[T any](db *gorm.DB, pageNum, pageSize int, filter *T) ([]*T, int64, error) {
var results []*T
var totalRecords int64
// 计算偏移量OFFSET
offset := (pageNum - 1) * pageSize
// 查询总记录数
if err := db.Where(filter).Count(&totalRecords).Error; err != nil {
return nil, 0, err
}
// 查询分页数据
if err := db.Where(filter).Offset(offset).Limit(pageSize).Find(&results).Error; err != nil {
return nil, 0, err
}
// 返回查询结果和总记录数
return results, totalRecords, nil
}