123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package repository
- import (
- "city_chips/internal/model"
- helper "city_chips/pkg/helper/dbutils"
- "context"
- )
- type IntelligentBuildingControlRepository interface {
- GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error)
- GetPoint(conds map[string]any) (*[]model.Point, error)
- GetPointType() ([]string, error)
- DeviceType() ([]string, error)
- DeviceCount() (int64, error)
- }
- func NewIntelligentBuildingControlRepository(
- repository *Repository,
- ) IntelligentBuildingControlRepository {
- return &intelligentBuildingControlRepository{
- Repository: repository,
- }
- }
- type intelligentBuildingControlRepository struct {
- *Repository
- }
- func (r *intelligentBuildingControlRepository) DeviceCount() (int64, error) {
- //TODO implement me
- var count int64
- err := r.db.Model(&model.Point{}).Count(&count).Error
- if err != nil {
- return 0, err
- }
- return count, nil
- }
- // GetPointType implements IntelligentBuildingControlRepository.
- func (r *intelligentBuildingControlRepository) DeviceType() ([]string, error) {
- var names []string
- err := r.db.Model(&model.Point{}).Select("device_type").Group("device_type").Find(&names).Error
- if err != nil {
- return nil, err
- }
- return names, nil
- }
- func (r *intelligentBuildingControlRepository) GetPointType() ([]string, error) {
- var names []string
- err := r.db.Model(&model.Point{}).Select("point_name").Group("point_name").Find(&names).Error
- if err != nil {
- return nil, err
- }
- return names, nil
- }
- func (r *intelligentBuildingControlRepository) GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error) {
- var intelligentBuildingControl model.IntelligentBuildingControl
- // 模拟从数据库获取数据
- return &intelligentBuildingControl, nil
- }
- // GetPoint 根据点位数据获取点位信息
- func (r *intelligentBuildingControlRepository) GetPoint(conds map[string]any) (*[]model.Point, error) {
- var points []model.Point
- points, err := helper.QueryByConditions[model.Point](r.db, conds)
- if err != nil {
- return &points, err
- }
- return &points, nil
- }
|