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 }