view_all_code_dao.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package dao
  2. import (
  3. "iot_manager_service/util/common"
  4. )
  5. type ViewsAllCode struct {
  6. DeviceType int
  7. DeviceTypeName string
  8. DeviceId int
  9. DeviceName string
  10. Sn string
  11. Address string
  12. LampPoleName string
  13. LampPoleSn string
  14. LampPoleId int
  15. InstallTime string
  16. CreateTime common.Time
  17. IsDeleted int
  18. TenantId int
  19. }
  20. func (ViewsAllCode) TableName() string {
  21. return "view_all_code" //此处不是真实表,是使用视图查询的
  22. }
  23. // GetAlls 全部数据
  24. func (v *ViewsAllCode) GetAlls() ([]ViewsAllCode, error) {
  25. var viewsAllCodes []ViewsAllCode
  26. err := Db.Debug().Model(&viewsAllCodes).Where("tenant_id=?", v.TenantId).Find(&viewsAllCodes).Error
  27. return viewsAllCodes, err
  28. }
  29. // GetGroupByDeviceType 根据不能设备类型列出
  30. func (v *ViewsAllCode) GetGroupByDeviceType(searchValue string) ([]ViewsAllCode, error) {
  31. var viewsAllCodes []ViewsAllCode
  32. db := Db.Debug().Model(&viewsAllCodes).Select("device_type,device_type_name").Where("is_deleted=0 and tenant_id=?", v.TenantId)
  33. if searchValue != "" {
  34. db.Where("device_name=? or sn=?", searchValue, searchValue)
  35. }
  36. err := db.Group("device_type,device_type_name").Find(&viewsAllCodes).Error
  37. return viewsAllCodes, err
  38. }
  39. // GetDatasByDeviceType 根据设备类型查设备
  40. func (v *ViewsAllCode) GetDatasByDeviceType(searchValue string) ([]ViewsAllCode, error) {
  41. var viewsAllCodes []ViewsAllCode
  42. db := Db.Debug().Model(&viewsAllCodes).Where("is_deleted=0 and tenant_id=? and device_type=?", v.TenantId, v.DeviceType)
  43. if searchValue != "" {
  44. db.Where("device_name=? or sn=?", searchValue, searchValue)
  45. }
  46. err := db.Find(&viewsAllCodes).Error
  47. return viewsAllCodes, err
  48. }