123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package dao
- import (
- "strings"
- )
- type CountDevice struct {
- CountNum int `json:"countNum"`
- DeviceType string `json:"deviceType"`
- }
- func GetDeviceCount(tenantId int) ([]CountDevice, error) {
- var result []CountDevice
- var count CountDevice
- Db.Debug().Model(&LampPole{}).Select(" count(*) count_num, 'lamppole' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&CameraDevice{}).Select(" count(*) count_num, 'camera' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&Gateway{}).Select(" count(*) count_num, 'gateway' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&LightControl{}).Select(" count(*) count_num, 'control' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&SwitchBox{}).Select(" count(*) count_num, 'box' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&InfoBoard{}).Select(" count(*) count_num, 'board' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&OptoSensor{}).Select(" count(*) count_num, 'sensor' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&Zigbee{}).Select(" count(*) count_num, 'zigbee' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&AlarmTerminal{}).Select(" count(*) count_num, 'terminal' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&Alarm{}).Select(" count(*) count_num, 'alarmserve' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- Db.Debug().Model(&IpBroadcast{}).Select(" count(*) count_num, 'ipcast' device_type ").
- Where("tenant_id = ? and is_deleted = 0", tenantId).Scan(&count)
- result = append(result, count)
- return result, nil
- }
- type CountAlarm struct {
- LastYearAlarm int `json:"lastYearAlarm"`
- LastMonthAlarm int `json:"lastMonthAlarm"`
- Backlog int `json:"backlog"`
- }
- func GetAlarmCount(tenantId int) (*CountAlarm, error) {
- var alarm CountAlarm
- return &alarm, nil
- }
- type CountJobTodo struct {
- BackJob int `json:"backJob"`
- LastMonthJob int `json:"lastMonthJob"`
- LastYearJob int `json:"lastYearJob"`
- }
- func GetCountJobTodo(tenantId int) (*CountJobTodo, error) {
- var todos CountJobTodo
- return &todos, nil
- }
- type Notification struct {
- Category int `json:"category"`
- Title string `json:"title"`
- }
- func GetNotification(tenantId int) (*Notification, error) {
- var notification Notification
- return ¬ification, nil
- }
- type AqiData struct {
- Name string
- Aqi float64
- }
- type OptoSensorVO struct {
- OptoSensor
- Ids string `json:"ids"`
- Brand string `json:"brand"`
- Model string `json:"model"`
- RunState string `json:"runState"`
- NetworkState int `json:"networkState"`
- RealTimeTemperature string `json:"realTimeTemperature"`
- RealTimeWindSpeed string `json:"realTimeWindSpeed"`
- AirQuality string `json:"airQuality"`
- AirIndex int `json:"airIndex"`
- IlluminationIntensity string `json:"illuminationIntensity"`
- Pm25 string `json:"pm25"`
- Pm10 string `json:"pm10"`
- Humidity string `json:"humidity"`
- Pressure string `json:"pressure"`
- Noise string `json:"noise"`
- Direction string `json:"direction"`
- EndLineTime string `json:"endLineTime"`
- QueryGatewayIds string `json:"queryGatewayIds"`
- GatewayName string `json:"gatewayName"`
- GatewaySn string `json:"gatewaySn"`
- DistrictName string `json:"districtName"`
- }
- func GetAqi(tenantId int) (*OptoSensorVO, error) {
- var sensorVO OptoSensorVO
- var optoSensor OptoSensor
- optoSensor.TenantId = tenantId
- optoSensor.IsDefault = 1
- isSet := len(optoSensor.GetDevicesByTenantId())
- if isSet == 0 {
- optoSensor.IsDefault = 0
- }
- list := optoSensor.getList(optoSensor)
- if isSet == 0 {
- for _, sensor := range list {
- if sensor.NetworkState == 1 {
- sensorVO = sensor
- break
- }
- }
- } else {
- if len(list) != 0 {
- sensorVO = list[0]
- }
- }
- if sensorVO.RealTimeTemperature != "" {
- temp := strings.Split(sensorVO.RealTimeTemperature, " ")
- if len(temp) == 2 {
- temperature := temp[0] + " " + temp[1]
- sensorVO.RealTimeTemperature = temperature
- }
- }
- return &sensorVO, nil
- }
|