intelligentbuildingcontrol.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package repository
  2. import (
  3. "city_chips/internal/model"
  4. helper "city_chips/pkg/helper/dbutils"
  5. "context"
  6. )
  7. type IntelligentBuildingControlRepository interface {
  8. GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error)
  9. GetPoint(conds map[string]any) (*[]model.Point, error)
  10. GetPointType() ([]string, error)
  11. DeviceType() ([]string, error)
  12. DeviceCount() (int64, error)
  13. }
  14. func NewIntelligentBuildingControlRepository(
  15. repository *Repository,
  16. ) IntelligentBuildingControlRepository {
  17. return &intelligentBuildingControlRepository{
  18. Repository: repository,
  19. }
  20. }
  21. type intelligentBuildingControlRepository struct {
  22. *Repository
  23. }
  24. func (r *intelligentBuildingControlRepository) DeviceCount() (int64, error) {
  25. //TODO implement me
  26. var count int64
  27. err := r.db.Model(&model.Point{}).Count(&count).Error
  28. if err != nil {
  29. return 0, err
  30. }
  31. return count, nil
  32. }
  33. // GetPointType implements IntelligentBuildingControlRepository.
  34. func (r *intelligentBuildingControlRepository) DeviceType() ([]string, error) {
  35. var names []string
  36. err := r.db.Model(&model.Point{}).Select("device_type").Group("device_type").Find(&names).Error
  37. if err != nil {
  38. return nil, err
  39. }
  40. return names, nil
  41. }
  42. func (r *intelligentBuildingControlRepository) GetPointType() ([]string, error) {
  43. var names []string
  44. err := r.db.Model(&model.Point{}).Select("point_name").Group("point_name").Find(&names).Error
  45. if err != nil {
  46. return nil, err
  47. }
  48. return names, nil
  49. }
  50. func (r *intelligentBuildingControlRepository) GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error) {
  51. var intelligentBuildingControl model.IntelligentBuildingControl
  52. // 模拟从数据库获取数据
  53. return &intelligentBuildingControl, nil
  54. }
  55. // GetPoint 根据点位数据获取点位信息
  56. func (r *intelligentBuildingControlRepository) GetPoint(conds map[string]any) (*[]model.Point, error) {
  57. var points []model.Point
  58. points, err := helper.QueryByConditions[model.Point](r.db, conds)
  59. if err != nil {
  60. return &points, err
  61. }
  62. return &points, nil
  63. }