intelligentbuildingcontrol.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }
  12. func NewIntelligentBuildingControlRepository(
  13. repository *Repository,
  14. ) IntelligentBuildingControlRepository {
  15. return &intelligentBuildingControlRepository{
  16. Repository: repository,
  17. }
  18. }
  19. type intelligentBuildingControlRepository struct {
  20. *Repository
  21. }
  22. // GetPointType implements IntelligentBuildingControlRepository.
  23. func (r *intelligentBuildingControlRepository) GetPointType() ([]string, error) {
  24. var names []string
  25. err := r.db.Model(&model.Point{}).Select("point_name").Group("point_name").Find(&names).Error
  26. if err != nil {
  27. return nil, err
  28. }
  29. return names, nil
  30. }
  31. func (r *intelligentBuildingControlRepository) GetIntelligentBuildingControl(ctx context.Context, id int64) (*model.IntelligentBuildingControl, error) {
  32. var intelligentBuildingControl model.IntelligentBuildingControl
  33. // 模拟从数据库获取数据
  34. return &intelligentBuildingControl, nil
  35. }
  36. // 根据点位数据获取点位信息
  37. func (r *intelligentBuildingControlRepository) GetPoint(conds map[string]any) (*[]model.Point, error) {
  38. var points []model.Point
  39. points, err := helper.QueryByConditions[model.Point](r.db, conds)
  40. if err != nil {
  41. return &points, err
  42. }
  43. return &points, nil
  44. }