瀏覽代碼

数据大屏-总览 接口

longan 2 年之前
父節點
當前提交
7f0e56c995
共有 36 個文件被更改,包括 1296 次插入28 次删除
  1. 138 0
      app/device/controller/bigController.go
  2. 29 0
      app/device/dao/alarmDao.go
  3. 31 0
      app/device/dao/alarmTerminalDao.go
  4. 178 0
      app/device/dao/bigModel.go
  5. 160 0
      app/device/dao/bigScreen.go
  6. 32 0
      app/device/dao/bridgeDao.go
  7. 33 1
      app/device/dao/cameraDao.go
  8. 28 1
      app/device/dao/captureUnitDao.go
  9. 34 1
      app/device/dao/gatewayDao.go
  10. 32 0
      app/device/dao/infoBoardDao.go
  11. 28 0
      app/device/dao/ipBroadcastDao.go
  12. 48 1
      app/device/dao/lampPoleDao.go
  13. 32 1
      app/device/dao/lightControlDao.go
  14. 30 0
      app/device/dao/manholeCoverDao.go
  15. 32 1
      app/device/dao/optoSensoDao.go
  16. 59 1
      app/device/dao/switchBoxDao.go
  17. 34 1
      app/device/dao/zigbeeDao.go
  18. 14 2
      app/device/service/alarmService.go
  19. 12 0
      app/device/service/alarmTerminalService.go
  20. 136 0
      app/device/service/bigService.go
  21. 13 1
      app/device/service/bridgeService.go
  22. 12 1
      app/device/service/cameraService.go
  23. 14 2
      app/device/service/captureUintService.go
  24. 13 2
      app/device/service/gatewayService.go
  25. 13 1
      app/device/service/infoBoardServiceTime.go
  26. 11 0
      app/device/service/ipBroadcastService.go
  27. 12 1
      app/device/service/lampPoleService.go
  28. 13 1
      app/device/service/lightControlService.go
  29. 10 0
      app/device/service/manholeCoverService.go
  30. 12 0
      app/device/service/optoSensoService.go
  31. 14 2
      app/device/service/switchBoxService.go
  32. 12 0
      app/device/service/zigbeeService.go
  33. 1 1
      app/warn/dao/platformAlarmDao.go
  34. 2 2
      config/config.yaml
  35. 4 4
      go.mod
  36. 20 0
      router/router.go

+ 138 - 0
app/device/controller/bigController.go

@@ -0,0 +1,138 @@
+package controller
+
+import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"iot_manager_service/app/device/dao"
+	"iot_manager_service/app/device/service"
+	"iot_manager_service/app/middleware"
+	"iot_manager_service/util/common"
+	"net/http"
+	"strconv"
+)
+
+//点击获取当前设备总数/状态数量+列表
+//http://localhost/api/longchi/largescreen/mapclieck/device-num?queryType=lampPole
+//需要数据:
+//countNum:灯杆总数,
+//faultNum:灯杆报警数,
+//[]polist:(lng经度,lat纬度,status:状态,name:名字,code:编码,lampPoleName:灯杆名,brand:品牌,model:型号,linkNum:连接设备数,)
+
+var BigScreen = new(bigScreen)
+
+type bigScreen struct {
+}
+
+func (big *bigScreen) DeviceNum(ctx *gin.Context) {
+	queryType := ctx.Query("queryType")
+	rsp := service.BigServer.DeviceNum(queryType)
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp))
+}
+
+func (big *bigScreen) LampPoleStatus(ctx *gin.Context) {
+	var rsp dao.TotalLamp
+	all, fault := service.BigServer.GetLampCount()
+	rsp.CountNum = all
+	rsp.FaultNum = fault
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+// DevicesStatus 设备统计  /api/longchi/largescreen/overview/device-status
+func (big *bigScreen) DevicesStatus(ctx *gin.Context) {
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, service.BigServer.DevicesStatus()))
+}
+
+// Energy 能耗: /api/longchi/largescreen/overview/energy-consumption
+func (big *bigScreen) Energy(ctx *gin.Context) {
+	fmt.Printf("Start:%v,End:%v\n", ctx.Query("startDate"), ctx.Query("endDate"))
+	rsp := service.BigServer.GetEnergy(ctx.Query("startDate"), ctx.Query("endDate"))
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+// LightRate 亮灯率:  /api/longchi/largescreen/overview/lighting-rate
+func (big *bigScreen) LightRate(ctx *gin.Context) {
+	authorization := ctx.GetHeader("Authorization")
+	claims := middleware.ParseAccessToken(authorization)
+	//rsp := service.BigServer.GetLightRate(claims.TenantId)
+	//var rsp = make([]interface{}, 0, 4)
+	//var lrm = dao.LightRateM{Month: "2023-07", Rate: 30}
+	//var lrq = dao.LightRateQ{Quarter: "3", Rate: 50}
+	//var lry = dao.LightRateY{Year: "2023", Rate: 50}
+	//rsp = append(rsp, []interface{}{})
+	//rsp = append(rsp, lrm)
+	//rsp = append(rsp, lrq)
+	//rsp = append(rsp, lry)
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, service.BigServer.GetLightRate(claims.TenantId)))
+}
+
+// AlarmInfo http://localhost/api/longchi/largescreen/overview/alarm-information
+func (big *bigScreen) AlarmInfo(ctx *gin.Context) {
+	rsp := service.BigServer.GetAlarmInfo()
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+// AlarmStatistics 报警设备统计 http://localhost/api/longchi/largescreen/overview/alarm-device-count?startDate=2022-07-10&endDate=2023-07-10
+func (big *bigScreen) AlarmStatistics(ctx *gin.Context) {
+	//deviceType faultNum
+	rsp := service.BigServer.AlarmStatus()
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+// FlowInfo 工单信息 http://localhost/api/longchi/largescreen/overview/flow-information
+func (big *bigScreen) FlowInfo(ctx *gin.Context) {
+	//deviceType faultNum
+	rsp := service.BigServer.AlarmStatus()
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+func (big *bigScreen) Environment(ctx *gin.Context) {
+	deviceId := ctx.Query("id")
+	rsp := service.BigServer.GetEnv(deviceId)
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+func (big *bigScreen) InfoBoard(ctx *gin.Context) {
+	authorization := ctx.GetHeader("Authorization")
+	claims := middleware.ParseAccessToken(authorization)
+	rsp := service.BigServer.GetLEDProgram(claims.TenantId)
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+func (big *bigScreen) Program(ctx *gin.Context) {
+	id := ctx.Query("id")
+	atoi, _ := strconv.Atoi(id)
+	rsp := service.BigServer.GetProgramUrl(id)
+	rsp.Id = int64(atoi)
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+func (big *bigScreen) BridgeSensor(ctx *gin.Context) {
+	authorization := ctx.GetHeader("Authorization")
+	claims := middleware.ParseAccessToken(authorization)
+	rsp := service.BigServer.GetBridgeSensors(claims.TenantId)
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+// QueryOverView http://localhost/api/longchi/largescreen/setting/query-large-screen?padScreen=overview
+func (big *bigScreen) QueryOverView(ctx *gin.Context) {
+	padScreen := ctx.Query("padScreen")
+	authorization := ctx.GetHeader("Authorization")
+	claims := middleware.ParseAccessToken(authorization)
+	rsp := service.BigServer.OverView(claims.TenantId, padScreen)
+	ctx.JSON(http.StatusOK, common.SuccessResponse(common.Success, rsp))
+}
+
+func (big *bigScreen) SubmitOverView(ctx *gin.Context) {
+	authorization := ctx.GetHeader("Authorization")
+	claims := middleware.ParseAccessToken(authorization)
+	var req []dao.OverView
+	err := ctx.ShouldBind(&req)
+	if err != nil {
+		logrus.Errorf("SubmitOverView ShouldBind error:%v", err)
+	}
+	for i, _ := range req {
+		req[i].TenantId = claims.TenantId
+	}
+	service.BigServer.Submit(req)
+	ctx.JSON(200, "")
+}

+ 29 - 0
app/device/dao/alarmDao.go

@@ -89,3 +89,32 @@ func (c Alarm) GetAllDevices() ([]*Alarm, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c Alarm) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c Alarm) ListDevices1() []Device {
+	var devices []Alarm
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Status: v.Status,
+			Name:   v.ServeName,
+			Code:   v.ServeSN,
+			Model:  "模型",
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 31 - 0
app/device/dao/alarmTerminalDao.go

@@ -113,3 +113,34 @@ func (c AlarmTerminal) GetTerminalCount(serverId int) int64 {
 		serverId).Count(&count)
 	return count
 }
+
+func (c AlarmTerminal) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c AlarmTerminal) ListDevices1() []Device {
+	var devices []AlarmTerminal
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.PoleLng,
+			Lat:          v.PoleLat,
+			Status:       v.Status,
+			Name:         v.TerminalName,
+			Code:         v.TerminalSN,
+			LampPoleName: v.LampPoleName,
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 178 - 0
app/device/dao/bigModel.go

@@ -0,0 +1,178 @@
+package dao
+
+import (
+	"time"
+)
+
+type QueryDevices struct {
+	//countNum:灯杆总数,
+	//faultNum:灯杆报警数,
+	CountNum int64    `json:"countNum"`
+	FaultNum int64    `json:"faultNum"`
+	Devices  []Device `json:"list"`
+}
+
+type Device struct {
+	//lng经度,lat纬度,status:状态,name:名字,code:编码,lampPoleName:灯杆名,brand:品牌,model:型号,linkNum:连接设备数,
+	Lng          float64 `json:"lng"`
+	Lat          float64 `json:"lat"`
+	Status       int     `json:"status"`
+	Name         string  `json:"name"`
+	Code         string  `json:"code"`
+	LampPoleName string  `json:"lampPoleName"`
+	Model        string  `json:"model"`
+	LinkNum      int64   `json:"linkNum"`
+}
+
+type TotalLamp struct {
+	CountNum int64 `json:"countNum"`
+	FaultNum int64 `json:"faultNum"`
+}
+
+type ConfigInfo struct {
+	Id        int64  `json:"id"`
+	SiteValue string `json:"siteValue"`
+}
+
+// url: '/api/longchi/largescreen/overview/device-status',
+type DeviceStatus struct {
+	DeviceType string `json:"deviceType"`
+	CountNum   int64  `json:"countNum"`
+	FaultNum   int64  `json:"faultNum"`
+}
+
+func (d *DeviceStatus) Set(n, m int64) {
+	d.CountNum = n
+	d.FaultNum = m
+}
+
+// /api/longchi/largescreen/overview/energy-consumption
+type Energy struct {
+	Date       string  `json:"date"`
+	Difference float64 `json:"difference"`
+}
+type LightRate struct {
+	Data []interface{}
+}
+
+// LightRate 亮灯率:  /api/longchi/largescreen/overview/lighting-rate
+type LightRateM struct {
+	Month string  `json:"month"`
+	Rate  float64 `json:"rate"`
+}
+type LightRateQ struct {
+	Quarter string  `json:"quarter"`
+	Rate    float64 `json:"rate"`
+}
+type LightRateY struct {
+	Year string  `json:"year"`
+	Rate float64 `json:"rate"`
+}
+
+// AlarmInfo http://localhost/api/longchi/largescreen/overview/alarm-information
+type AlarmList struct {
+	Backlog        int64       `json:"backlog"`
+	LastMonthAlarm int64       `json:"lastMonthAlarm"`
+	LastYearAlarm  int64       `json:"lastYearAlarm"`
+	List           []AlarmInfo `json:"list"`
+}
+
+type AlarmInfo struct {
+	ArmContent        string         `gorm:"arm_content" json:"armContent"`
+	ArmDeviceTypeName string         `gorm:"arm_device_type_name" json:"armDeviceTypeName"`
+	ArmLevelName      string         `gorm:"level_name" json:"armLevelName"`
+	CreateTime        DateTimeString `gorm:"arm_time" json:"createTime"`
+}
+type DateTimeString time.Time
+
+const DateTimeFormatCN = "2006-01-02 15:04:05"
+
+func (t *DateTimeString) UnmarshalJSON(data []byte) (err error) {
+	now, err := time.ParseInLocation(`"`+DateTimeFormatCN+`"`, string(data), time.Local)
+	*t = DateTimeString(now)
+	return
+}
+
+func (t *DateTimeString) MarshalJSON() ([]byte, error) {
+	b := make([]byte, 0, len(DateTimeFormatCN)+2)
+	b = append(b, '"')
+	b = time.Time(*t).AppendFormat(b, DateTimeFormatCN)
+	b = append(b, '"')
+	return b, nil
+}
+func (t *DateTimeString) String() string {
+	return time.Time(*t).Format(DateTimeFormatCN)
+}
+
+// lastYearJob,本月已处理lastMonthJob,待处理backJob,list{type,name,createTime})
+type FlowList struct {
+	LastYearJob  int64      `json:"lastYearJob"`
+	LastMonthJob int64      `json:"lastMonthJob"`
+	List         []FlowInfo `json:"list"`
+}
+type FlowInfo struct {
+	Name       string    `json:"name"`
+	CreateTime time.Time `json:"createTime"`
+}
+
+// /setting/query-large-screen
+type ScreenSet struct {
+	SiteValue string
+}
+
+// 环境监测http://localhost/api/longchi/largescreen/overview/weather-now?id=1
+type Environment struct {
+	//AirIndex         int64
+	Air float64 `json:"airQuality"`
+	//LampPoleLocation string    `json:"lampPoleLocation"`
+	CreateDate    string  `json:"endLineTime"`
+	Temperature   float64 `json:"realTimeTemperature"`
+	Humidity      float64 `json:"humidity"`
+	Pm25          float64 `json:"pm25"`
+	Pm10          float64 `json:"pm10"`
+	Noise         float64 `json:"noise"`
+	Hpa           float64 `json:"pressure"` //气压
+	WindDirection string  `json:"direction"`
+	WindSpeed     float64 `json:"realTimeWindSpeed"` //风力等级
+}
+
+// 信息屏
+
+type InfoBoardProgram struct {
+	Id             int64      `json:"id"`
+	Name           string     `json:"name"`           //节目名字
+	Duration       int64      `json:"duration"`       //播放时长
+	Count          int64      `json:"countDeviceNum"` //关联设备
+	ResolutionName string     `json:"resolutionName"` //分辨率
+	EndTime        DateString `json:"endTime"`        //结束时间
+}
+type Program struct {
+	Id      int64  `json:"id"`
+	SendUrl string `json:"sendUrl"`
+}
+
+type DateString time.Time
+
+const TimeFormatCN = "2006-01-02"
+
+func (t *DateString) UnmarshalJSON(data []byte) (err error) {
+	now, err := time.ParseInLocation(`"`+TimeFormatCN+`"`, string(data), time.Local)
+	*t = DateString(now)
+	return
+}
+
+func (t *DateString) MarshalJSON() ([]byte, error) {
+	b := make([]byte, 0, len(TimeFormatCN)+2)
+	b = append(b, '"')
+	b = time.Time(*t).AppendFormat(b, TimeFormatCN)
+	b = append(b, '"')
+	return b, nil
+}
+func (t *DateString) String() string {
+	return time.Time(*t).Format(TimeFormatCN)
+}
+
+type Sensor struct {
+	Id   int64  `json:"id"`
+	Name string `json:"name"`
+}

+ 160 - 0
app/device/dao/bigScreen.go

@@ -0,0 +1,160 @@
+package dao
+
+import (
+	"fmt"
+	"iot_manager_service/util/logger"
+)
+
+type Big interface {
+	ListDevices() ([]Device, int64, error)
+	CountFault() (int64, error)
+}
+
+func getLinkNum(sn string) int64 {
+	var i int64
+	//SELECT total FROM device_wisdom_gateway a LEFT JOIN device_gateway_relation b ON a.id = b.id
+	//WHERE a.lamp_pole_sn='ZHDG4306268O408R' ORDER BY total DESC LIMIT 1;
+	Db.Select("total").Table("device_wisdom_gateway a").
+		Joins("LEFT JOIN device_gateway_relation b ON a.id = b.id").
+		Where("a.lamp_pole_sn = ?", sn).
+		Order("total DESC").Limit(1).Find(&i)
+	return i
+}
+
+func GetEnergy(start, end string) []Energy {
+	var rsp = make([]Energy, 0, 12)
+	//select  SUBSTR(date FROM 1 FOR 7) AS date1,SUM(difference) AS difference
+	//FROM `t_device_energy_day_data` t WHERE date BETWEEN "2023-04-01" AND "2023-06-01" GROUP BY date1;
+	rows, err := Db.Debug().Select("SUBSTR(date FROM 1 FOR 7) AS dates,SUM(difference) AS difference").
+		Table("`t_device_energy_day_data`").Where("date BETWEEN ? AND ?", start, end).Group("dates").Rows()
+	defer rows.Close()
+	if err != nil {
+		logger.Logger.Errorf("GetEnergy error: %v", err)
+	}
+	for rows.Next() {
+		var e Energy
+		rows.Scan(&e.Date, &e.Difference)
+		rsp = append(rsp, e)
+	}
+	return rsp
+}
+
+// GetLightRate
+// SELECT DATE_FORMAT(NOW(),'%Y-%m') AS month, AVG(rate) AS rate FROM `t_lamp_lighting_rate_day_data` WHERE SUBSTR(date FROM 1 FOR 7) = DATE_FORMAT(NOW(),'%Y-%m') AND tenant = '000000';
+// SELECT QUARTER(NOW()) AS quarter, AVG(rate) AS rate FROM `t_lamp_lighting_rate_day_data` WHERE QUARTER(date) = QUARTER(NOW()) AND tenant = '000000';
+// SELECT YEAR(NOW()) AS year, AVG(rate) AS rate FROM `t_lamp_lighting_rate_day_data` WHERE YEAR(date) = YEAR(NOW()) AND tenant = '000000';
+func GetLightRate(tenant string) []interface{} {
+	var rsp = make([]interface{}, 0, 4)
+	var lrm LightRateM
+	var lrq LightRateQ
+	var lry LightRateY
+	Db.Debug().Select("DATE_FORMAT(NOW(),'%Y-%m') AS month,ROUND(AVG(rate),2) AS rate").Table("`t_lamp_lighting_rate_day_data`").
+		Where("SUBSTR(date FROM 1 FOR 7) = DATE_FORMAT(NOW(),'%Y-%m') And tenant = ?", tenant).Find(&lrm)
+	Db.Debug().Select("QUARTER(NOW()) AS quarter, ROUND(AVG(rate),2) AS rate").Table("`t_lamp_lighting_rate_day_data`").
+		Where("quarter(date) = quarter(NOW()) AND tenant = ?", tenant).Find(&lrq)
+	Db.Debug().Select("YEAR(NOW()) AS year, ROUND(AVG(rate),2) AS rate").Table("`t_lamp_lighting_rate_day_data`").
+		Where("YEAR(date) = YEAR(NOW()) AND tenant = ?", tenant).Find(&lry)
+	//lr[0].Month = ""
+	rsp = append(rsp, []interface{}{})
+	rsp = append(rsp, lrm)
+	rsp = append(rsp, lrq)
+	rsp = append(rsp, lry)
+	return rsp
+}
+
+// GetAlarmInfo 1待处理2忽略3已处理4其他
+// #待处理
+// SELECT COUNT(id) FROM `warn_platform_alarm` WHERE arm_handle = 1;
+// SELECT arm_content,arm_device_type_name,dict_value AS level_name,arm_time
+// FROM `warn_platform_alarm` w JOIN `dict` d
+// ON w.arm_level = d.dict_key
+// WHERE w.arm_handle = 1 AND d.`code` = 'arm_level_type'
+// LIMIT 10;
+// #本月已处理
+// SELECT COUNT(id) FROM `warn_platform_alarm` WHERE SUBSTR(arm_end_time FROM 1 FOR 7)=SUBSTR(NOW() FROM 1 FOR 7) AND arm_handle = 3;
+// #本年已处理
+// SELECT COUNT(id) FROM `warn_platform_alarm` WHERE YEAR(arm_end_time)=YEAR(NOW()) AND arm_handle = 3;
+func GetAlarmInfo() AlarmList {
+	var al AlarmList
+	Db.Debug().Select("COUNT(id)").Table("`warn_platform_alarm`").
+		Where("arm_handle = 1").Find(&al.Backlog)
+	Db.Debug().Select("COUNT(id)").Table("`warn_platform_alarm`").
+		Where("SUBSTR(arm_end_time FROM 1 FOR 7)=SUBSTR(NOW() FROM 1 FOR 7) AND arm_handle = 3").Find(&al.LastMonthAlarm)
+	Db.Debug().Select("COUNT(id)").Table("`warn_platform_alarm`").
+		Where("YEAR(arm_end_time)=YEAR(NOW()) AND arm_handle = 3").Find(&al.LastYearAlarm)
+	Db.Debug().Select("arm_content,arm_device_type_name,dict_value AS arm_level_name,arm_time AS create_time").
+		Table("`warn_platform_alarm` AS w JOIN `dict` AS d ON w.arm_level = d.dict_key").
+		Where("w.arm_handle = 1 AND d.`code` = 'arm_level_type'").Order("create_time DESC").Limit(7).Find(&al.List)
+	return al
+}
+
+type OverView struct {
+	Id        int64  `gorm:"primary_key" json:"id"`
+	TenantId  string `json:"tenantId"`
+	PadScreen string `json:"padScreen"`
+	Site      string `json:"site"`
+	SiteValue int64  `json:"siteValue"`
+}
+
+func (o *OverView) TableName() string {
+	return "big_screen_overview"
+}
+
+type OverViewInfo struct {
+	Id        int64 `gorm:"primary_key" json:"id"`
+	SiteValue int64 `json:"siteValue"`
+}
+
+func (o *OverView) Query(tenantId, padScreen string) []OverViewInfo {
+	var rsp []OverViewInfo
+	Db.Debug().Select("id, site_value").Table(o.TableName()).Where("tenant_id = ? AND pad_screen = ?", tenantId, padScreen).Find(&rsp)
+	return rsp
+}
+func (o *OverView) Submit(data OverView) {
+	Db.Debug().Model(&o).Select("pad_screen", "site_value").Where("id=?", data.Id).Updates(&data)
+}
+
+func GetEnvData(id string) Environment {
+	var env Environment
+	//"lampPoleLocation"
+	Db.Debug().Select("air, create_date, temperature, humidity, pm25, pm10, noise, hpa, wind_direction, wind_speed").
+		Table("data_environment").Where("device_id=?", id).
+		Order("create_date DESC").Limit(1).Find(&env)
+	fmt.Printf("==============env:%+v\n", env)
+	return env
+}
+
+// GetLEDProgramList
+// SELECT m.id,m.name,m.duration,d.dict_value, end_time
+// FROM `media_publish_libraries` m JOIN `dict` d
+// ON dict_key = m.resolution
+// WHERE m.tenant_id = '000000' and m.sys_type=0 and m.is_deleted = 0 AND d.code = 'resolution_type'
+// ORDER BY id desc LIMIT 10
+func GetLEDProgramList(tenantId string) []InfoBoardProgram {
+	var list []InfoBoardProgram
+	Db.Debug().Select("m.id,m.name,m.duration,d.dict_value AS resolution_name, end_time ,(LENGTH(info_id) - LENGTH(REPLACE(info_id, ',', '')) + 1) AS count").
+		Table("`media_publish_libraries` m JOIN `dict` d ON dict_key = m.resolution").
+		Where("d.code='resolution_type' AND m.sys_type=0 AND m.is_deleted=0 AND m.tenant_id=?", tenantId).
+		Order("id DESC").Limit(10).Find(&list)
+	return list
+}
+
+func GetProgramUrl(id string) Program {
+	var rsp Program
+	//SELECT name FROM `media_publish_libraries` WHERE id = 45
+	t1 := Db.Select("name").Table("media_publish_libraries").Where("id=(?)", id)
+	//SELECT id FROM `media_program` WHERE name =?
+	t2 := Db.Select("id").Table("media_program").Where("name=(?)", t1)
+	//SELECT library_id FROM media_program_relation WHERE program_id = ?
+	t3 := Db.Select("library_id").Table("media_program_relation").Where("program_id=(?)", t2)
+	//SELECT material_address FROM `media_library` WHERE id =?
+	Db.Debug().Select("material_address AS send_url").Table("media_library").Where("id =(?)", t3).Find(&rsp)
+	return rsp
+}
+
+func GetBridgeSensors(tenantId string) []Sensor {
+	var rsp []Sensor
+	//SELECT id,name FROM `device_bridge_sensor` WHERE tenant_id = '000000' AND is_deleted = 0
+	Db.Debug().Select("id,name").Table("device_bridge_sensor").Where("tenant_id = ? AND is_deleted = 0", tenantId).Find(&rsp)
+	return rsp
+}

+ 32 - 0
app/device/dao/bridgeDao.go

@@ -97,3 +97,35 @@ func (c Bridge) GetAllDevices() ([]*Bridge, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+func (c Bridge) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c Bridge) ListDevices1() []Device {
+	var devices []Bridge
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.Lng,
+			Lat:          v.Lat,
+			Status:       v.Status,
+			Name:         v.Name,
+			Code:         v.SN,
+			LampPoleName: v.DistrictName,
+			Model:        "模型",
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 33 - 1
app/device/dao/cameraDao.go

@@ -5,7 +5,7 @@ import (
 	"time"
 )
 
-//CameraDevice 网关下挂载的设备, 摄像头
+// CameraDevice 网关下挂载的设备, 摄像头
 type CameraDevice struct {
 	ID               int         `gorm:"primary_key" json:"id"`                          //编号
 	DeviceName       string      `gorm:"type:varchar(64)" json:"deviceName"`             //设备名称
@@ -121,3 +121,35 @@ func (c CameraDevice) GetDevicesByIds(ids string) []CameraDevice {
 	db.Find(&devices)
 	return devices
 }
+
+func (c CameraDevice) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+func (c CameraDevice) ListDevices1() []Device {
+	var devices []CameraDevice
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.LampLng,
+			Lat:          v.LampLat,
+			Status:       v.Status,
+			Name:         v.DeviceName,
+			Code:         v.DeviceSN,
+			LampPoleName: v.LampPoleName,
+			Model:        "模型",
+			LinkNum:      getLinkNum(v.LampPoleSn),
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 28 - 1
app/device/dao/captureUnitDao.go

@@ -4,7 +4,7 @@ import (
 	"time"
 )
 
-//CaptureUnit 抓拍单元
+// CaptureUnit 抓拍单元
 type CaptureUnit struct {
 	ID                     int       `gorm:"primary_key" json:"id"`                                //编号
 	CaptureName            string    `gorm:"type:varchar(64)" json:"captureName"`                  //设备名称
@@ -99,3 +99,30 @@ func (c CaptureUnit) GetDevicesByLampPole() []CaptureUnit {
 		c.LampPoleId).Find(&devices)
 	return devices
 }
+func (c CaptureUnit) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = 0
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = 0
+	}
+	return all, fault
+}
+
+func (c CaptureUnit) ListDevices1() []Device {
+	var devices []CaptureUnit
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Name:         v.CaptureName,
+			Code:         v.CaptureSn,
+			LampPoleName: v.GatewayName,
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 34 - 1
app/device/dao/gatewayDao.go

@@ -6,7 +6,7 @@ import (
 	"time"
 )
 
-//Gateway 网关设备
+// Gateway 网关设备
 type Gateway struct {
 	ID                 int         `gorm:"primary_key" json:"id"`                           //编号
 	GatewayName        string      `gorm:"type:varchar(64)"  json:"gatewayName"`            //设备名称
@@ -106,3 +106,36 @@ func (c Gateway) GetDevicesByLampPole() []Gateway {
 		c.LampPoleId).Find(&devices)
 	return devices
 }
+
+func (c Gateway) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c Gateway) ListDevices1() []Device {
+	var devices []Gateway
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.LampLng,
+			Lat:          v.LampLat,
+			Status:       v.Status,
+			Name:         v.GatewayName,
+			Code:         v.GatewaySn,
+			LampPoleName: v.LampPoleName,
+			Model:        "模型",
+			LinkNum:      getLinkNum(v.LampPoleSn),
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 32 - 0
app/device/dao/infoBoardDao.go

@@ -142,3 +142,35 @@ func (c InfoBoard) GetDevicesByIds(ids string) []InfoBoard {
 	fmt.Printf("devices = %v", devices)
 	return devices
 }
+
+func (c InfoBoard) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = 0
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = 0
+	}
+	return all, fault
+}
+
+func (c InfoBoard) ListDevices1() []Device {
+	var devices []InfoBoard
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.PoleLng,
+			Lat:          v.PoleLat,
+			Status:       -1,
+			Name:         v.InfoName,
+			Code:         v.Sn,
+			LampPoleName: v.LampPoleName,
+			Model:        "模型",
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 28 - 0
app/device/dao/ipBroadcastDao.go

@@ -130,3 +130,31 @@ func (c IpBroadcast) GetAllDevicesNotTenant() ([]*IpBroadcast, error) {
 	err := db.Where("is_deleted = 0 ").Scan(&devices).Error
 	return devices, err
 }
+
+func (c IpBroadcast) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = 0
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = 0
+	}
+	return all, fault
+}
+
+func (c IpBroadcast) ListDevices1() []Device {
+	var devices []IpBroadcast
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Name:  v.CastName,
+			Code:  v.CastSn,
+			Model: "模型",
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 48 - 1
app/device/dao/lampPoleDao.go

@@ -6,7 +6,7 @@ import (
 	"time"
 )
 
-//LampPole 灯杆设备
+// LampPole 灯杆设备
 type LampPole struct {
 	ID              int         `gorm:"primary_key" json:"id"`                    //编号
 	PoleName        string      `gorm:"type:varchar(64)"  json:"poleName"`        //灯杆名称
@@ -129,3 +129,50 @@ func (c LampPole) GetGroupIdCount() (int, error) {
 		c.GroupId).Count(&count).Error
 	return int(count), err
 }
+
+// CountAll SELECT COUNT(id) AS countNum FROM `device_lamp_pole` WHERE `is_deleted` = 0;
+func (c LampPole) CountAll() (int64, error) {
+	var i int64
+	err := Db.Debug().Table("device_lamp_pole").Where("is_deleted = 0").Count(&i).Error
+	return i, err
+}
+
+// CountFault SELECT COUNT(id) AS faultNum FROM `device_lamp_pole` WHERE `is_deleted` = 0 AND `status` = -1;
+func (c LampPole) CountFault() (int64, error) {
+	var i int64
+	err := Db.Debug().Model(&c).Where(map[string]interface{}{"is_deleted": 0, "status": 0}).Count(&i).Error
+	return i, err
+}
+
+func (c LampPole) ListDevices1() []Device {
+	var devices []LampPole
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.PoleLng,
+			Lat:          v.PoleLat,
+			Status:       v.Status,
+			Name:         v.PoleName,
+			Code:         v.PoleSN,
+			LampPoleName: v.PoleName,
+			Model:        "型号",
+			LinkNum:      getLinkNum(v.PoleSN),
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}
+
+func (c LampPole) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}

+ 32 - 1
app/device/dao/lightControlDao.go

@@ -6,7 +6,7 @@ import (
 	"time"
 )
 
-//LightControl 灯控
+// LightControl 灯控
 type LightControl struct {
 	ID               int         `gorm:"primary_key" json:"id"`                     //编号
 	Name             string      `gorm:"type:varchar(64)"  json:"name"`             //名称
@@ -137,3 +137,34 @@ func (c LightControl) GetDevicesByLampPole() []LightControl {
 		c.LampPoleId).Find(&devices)
 	return devices
 }
+
+func (c LightControl) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c LightControl) ListDevices1() []Device {
+	var devices []LightControl
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.LampLng,
+			Lat:          v.LampLat,
+			Status:       v.Status,
+			Name:         v.Name,
+			Code:         v.Sn,
+			LampPoleName: v.LampPoleName,
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 30 - 0
app/device/dao/manholeCoverDao.go

@@ -117,3 +117,33 @@ func (c ManholeCover) FindDeviceIdByImei(imei string) (int, error) {
 	err := Db.Debug().Raw("SELECT * FROM `device_manhole_cover` WHERE `device_i_mei` = ? AND `is_deleted` = '0' limit 1", imei).First(&device).Error
 	return device.ID, err
 }
+
+func (c ManholeCover) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+func (c ManholeCover) ListDevices1() []Device {
+	var devices []ManholeCover
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.Longitude,
+			Lat:          v.Latitude,
+			Status:       v.Status,
+			Name:         v.ManholeName,
+			Code:         v.ManholeSn,
+			LampPoleName: v.WayName,
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 32 - 1
app/device/dao/optoSensoDao.go

@@ -6,7 +6,7 @@ import (
 	"time"
 )
 
-//OptoSensor 集控器
+// OptoSensor 集控器
 type OptoSensor struct {
 	ID               int         `gorm:"primary_key" json:"id"`                     //编号
 	Name             string      `gorm:"type:varchar(64)" json:"name"`              //名称
@@ -135,3 +135,34 @@ func (c OptoSensor) getList(optoSensor OptoSensor) []OptoSensorVO {
 
 	return optoSensorVO
 }
+
+func (c OptoSensor) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c OptoSensor) ListDevices1() []Device {
+	var devices []OptoSensor
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.LampLng,
+			Lat:          v.LampLat,
+			Status:       v.Status,
+			Name:         v.Name,
+			Code:         v.Sn,
+			LampPoleName: v.LampPoleName,
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 59 - 1
app/device/dao/switchBoxDao.go

@@ -92,7 +92,7 @@ func (c SwitchBox) GetDevices(offset, limit int) ([]SwitchBox, int64, error) {
 	return devices, count, err
 }
 
-//得到关联设备 2022-12-08 dsx
+// 得到关联设备 2022-12-08 dsx
 func (c SwitchBox) GetDeviceCount() (int64, error) {
 	var count int64
 	err := Db.Debug().Model(&c).Where("(transformer_id = ?) and is_deleted = 0",
@@ -105,3 +105,61 @@ func (c SwitchBox) GetAllDevices() ([]*SwitchBox, error) {
 	err := Db.Debug().Model(&c).Where(" tenant_id = ? and is_deleted = ? ", c.TenantId, c.IsDeleted).Scan(&devices).Error
 	return devices, err
 }
+
+// CountFault SELECT COUNT(id) FROM `device_lamp_pole` WHERE `is_deleted` = 0 AND `status` = 0;
+func (c SwitchBox) CountFault() (int64, error) {
+	var i int64
+	err := Db.Debug().Model(&c).Where(map[string]interface{}{"is_deleted": "0", "status": "0"}).Count(&i).Error
+	return i, err
+}
+
+func (c SwitchBox) ListDevices() ([]Device, int64, error) {
+	var devices []SwitchBox
+	result := Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:    v.PoleLng,
+			Lat:    v.PoleLat,
+			Status: v.Status,
+			Name:   v.BoxName,
+			Code:   v.BoxSN,
+			Model:  "型号",
+		}
+		rsp = append(rsp, d)
+	}
+	var i int64
+	result.Count(&i)
+	return rsp, i, result.Error
+}
+
+func (c SwitchBox) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c SwitchBox) ListDevices1() []Device {
+	var devices []SwitchBox
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:    v.PoleLng,
+			Lat:    v.PoleLat,
+			Status: v.Status,
+			Name:   v.BoxName,
+			Code:   v.BoxSN,
+			Model:  "模型",
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 34 - 1
app/device/dao/zigbeeDao.go

@@ -6,7 +6,7 @@ import (
 	"time"
 )
 
-//Zigbee集控器
+// Zigbee集控器
 type Zigbee struct {
 	ID               int         `gorm:"primary_key" json:"id"`                     //编号
 	Name             string      `gorm:"type:varchar(64)" json:"name"`              //名称
@@ -112,3 +112,36 @@ func (c Zigbee) GetDevicesByLampPole() []Zigbee {
 		c.LampPoleId).Find(&devices)
 	return devices
 }
+
+func (c Zigbee) DeviceCount1() (int64, int64) {
+	var all, fault int64
+	err := Db.Model(&c).Where("is_deleted = 0").Count(&all).Error
+	if err != nil {
+		all = -1
+	}
+	err = Db.Model(&c).Where("is_deleted = 0 and status = 0").Count(&fault).Error
+	if err != nil {
+		fault = -1
+	}
+	return all, fault
+}
+
+func (c Zigbee) ListDevices1() []Device {
+	var devices []Zigbee
+	Db.Debug().Model(&c).Where("is_deleted = 0").Find(&devices)
+	var rsp = make([]Device, 0, len(devices))
+	for _, v := range devices {
+		var d = Device{
+			Lng:          v.PoleLng,
+			Lat:          v.PoleLat,
+			Status:       v.Status,
+			Name:         v.Name,
+			Code:         v.Sn,
+			LampPoleName: v.LampPoleName,
+			Model:        "模型",
+			LinkNum:      getLinkNum(v.LampPoleSn),
+		}
+		rsp = append(rsp, d)
+	}
+	return rsp
+}

+ 14 - 2
app/device/service/alarmService.go

@@ -99,7 +99,7 @@ func (s *alarmService) Remove(userId int64, tenantId string, id int) *common.Err
 	return nil
 }
 
-func (s *alarmService) GetList(tenantId string, ) ([]*dao.Alarm, *common.Errors) {
+func (s *alarmService) GetList(tenantId string) ([]*dao.Alarm, *common.Errors) {
 	var devices []*dao.Alarm
 	err := cache.Redis.Get(getAlarmListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
@@ -117,6 +117,18 @@ func (s *alarmService) GetList(tenantId string, ) ([]*dao.Alarm, *common.Errors)
 	return devices, nil
 }
 
-func getAlarmListRedisKey(tenantId string, ) string {
+func getAlarmListRedisKey(tenantId string) string {
 	return fmt.Sprintf(model.AlarmList, tenantId)
 }
+
+func (s *alarmService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.Alarm{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *alarmService) ListDevices() []dao.Device {
+	d := dao.Alarm{}
+	return d.ListDevices1()
+}

+ 12 - 0
app/device/service/alarmTerminalService.go

@@ -125,3 +125,15 @@ func (s *alarmTerminalService) GetByLampPole(id int) []dao.AlarmTerminal {
 	}
 	return device.GetDevicesByLampPole()
 }
+
+func (s *alarmTerminalService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.AlarmTerminal{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *alarmTerminalService) ListDevices() []dao.Device {
+	d := dao.AlarmTerminal{}
+	return d.ListDevices1()
+}

+ 136 - 0
app/device/service/bigService.go

@@ -0,0 +1,136 @@
+package service
+
+import (
+	deviceDao "iot_manager_service/app/device/dao"
+)
+
+type BigService interface {
+	DeviceCount() deviceDao.DeviceStatus
+	ListDevices() []deviceDao.Device
+}
+
+var BigServer = new(bigService)
+
+type bigService struct {
+}
+
+func (big *bigService) DeviceNum(queryType string) deviceDao.QueryDevices {
+	var server BigService
+	server = getService(queryType)
+	obj := server.DeviceCount()
+	return deviceDao.QueryDevices{
+		CountNum: obj.CountNum,
+		FaultNum: obj.FaultNum,
+		Devices:  server.ListDevices(),
+	}
+}
+
+func (big *bigService) GetLampCount() (int64, int64) {
+	dao := deviceDao.LampPole{}
+	all, err1 := dao.CountAll()
+	fault, err2 := dao.CountFault()
+	if err1 != nil {
+		all = 0
+	}
+	if err2 != nil {
+		fault = 0
+	}
+	return all, fault
+}
+
+func (big *bigService) DevicesStatus() []deviceDao.DeviceStatus {
+	//1.灯杆 2.灯控 3.摄像头 4.led 5.环境传感器 6.网关 7. 报警器 8.管理端
+	//9.路面状况传感器 10.ip音柱 11.集控器 12.抓拍单元
+	var names = []string{"camera", "wisdomGateway", "lightControl", "switchBox", "infoBoard",
+		"optoSensor", "zigBee", "aKeyAlarmTerminal", "aKeyAlarmServe", "lampPole", "captureUnit", "bridgeSensor", "ipCast", "manhole"}
+	var rsp = make([]deviceDao.DeviceStatus, 0, 14)
+	for _, v := range names {
+		ds := getService(v).DeviceCount()
+		ds.DeviceType = v
+		rsp = append(rsp, ds)
+	}
+	return rsp
+}
+func (big *bigService) AlarmStatus() []deviceDao.DeviceStatus {
+	var names = []string{"camera", "lightControl", "infoBoard", "optoSensor",
+		"zigBee", "lampPole", "captureUnit"}
+	var rsp = make([]deviceDao.DeviceStatus, 0, 6)
+	for _, v := range names {
+		ds := getService(v).DeviceCount()
+		ds.DeviceType = v
+		rsp = append(rsp, ds)
+	}
+	return rsp
+}
+
+func getService(deviceName string) BigService {
+	switch deviceName {
+	case "camera":
+		return CameraService
+	case "wisdomGateway", "gateway":
+		return GatewayService
+	case "lightControl", "control":
+		return LightControlService
+	case "switchBox", "box":
+		return SwitchBoxService
+	case "infoBoard", "board":
+		return InfoBoardService
+	case "optoSensor", "sensor":
+		return OptoSensorService
+	case "zigBee", "zigbee":
+		return ZigbeeService
+	case "aKeyAlarmTerminal", "terminal":
+		return AlarmTerminalService
+	case "aKeyAlarmServe", "serve":
+		return AlarmService
+	case "lampPole", "lamppole":
+		return LampPoleService
+	case "captureUnit":
+		return CaptureUintService
+	case "bridgeSensor", "xueshui":
+		return BridgeService
+	case "ipCast", "ipcast":
+		return IpBroadcastService
+	case "manhole":
+		return ManholeCoverService
+	default:
+		return nil
+	}
+}
+
+func (big *bigService) GetEnergy(start, end string) []deviceDao.Energy {
+	return deviceDao.GetEnergy(start, end)
+}
+
+func (big *bigService) GetLightRate(tenant string) []interface{} {
+	return deviceDao.GetLightRate(tenant)
+}
+
+func (big *bigService) GetAlarmInfo() deviceDao.AlarmList {
+	return deviceDao.GetAlarmInfo()
+}
+
+func (big *bigService) GetEnv(deviceId string) deviceDao.Environment {
+	return deviceDao.GetEnvData(deviceId)
+}
+
+func (big *bigService) GetLEDProgram(tenantId string) []deviceDao.InfoBoardProgram {
+	return deviceDao.GetLEDProgramList(tenantId)
+}
+func (big *bigService) GetProgramUrl(id string) deviceDao.Program {
+	return deviceDao.GetProgramUrl(id)
+}
+func (big *bigService) GetBridgeSensors(tenantId string) []deviceDao.Sensor {
+	return deviceDao.GetBridgeSensors(tenantId)
+}
+
+func (big *bigService) OverView(tenantId, padScreen string) []deviceDao.OverViewInfo {
+	dao := deviceDao.OverView{}
+	return dao.Query(tenantId, padScreen)
+}
+func (big *bigService) Submit(data []deviceDao.OverView) {
+	dao := deviceDao.OverView{}
+	for _, v := range data {
+		dao.Submit(v)
+	}
+}

+ 13 - 1
app/device/service/bridgeService.go

@@ -93,7 +93,7 @@ func (s *bridgeService) Remove(userId int64, tenantId string, id int) *common.Er
 	return nil
 }
 
-func (s *bridgeService) GetList(tenantId string, ) ([]*dao.Bridge, *common.Errors) {
+func (s *bridgeService) GetList(tenantId string) ([]*dao.Bridge, *common.Errors) {
 	// todo use redis cache
 	device := &dao.Bridge{
 		TenantId:  tenantId,
@@ -106,3 +106,15 @@ func (s *bridgeService) GetList(tenantId string, ) ([]*dao.Bridge, *common.Error
 
 	return devices, nil
 }
+
+func (s *bridgeService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.Bridge{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *bridgeService) ListDevices() []dao.Device {
+	d := dao.Bridge{}
+	return d.ListDevices1()
+}

+ 12 - 1
app/device/service/cameraService.go

@@ -140,7 +140,7 @@ func (s *cameraService) Remove(userId int64, tenantId string, id int) *common.Er
 	return nil
 }
 
-func (s *cameraService) GetList(tenantId string, ) ([]dao.CameraDevice, *common.Errors) {
+func (s *cameraService) GetList(tenantId string) ([]dao.CameraDevice, *common.Errors) {
 	device := &dao.CameraDevice{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -195,3 +195,14 @@ func (s *cameraService) GetByLampPoleGroup(id int) []dao.CameraDevice {
 	}
 	return device.GetDevicesByLampPoleGroup()
 }
+
+func (s *cameraService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.CameraDevice{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+func (s *cameraService) ListDevices() []dao.Device {
+	pole := dao.CameraDevice{}
+	return pole.ListDevices1()
+}

+ 14 - 2
app/device/service/captureUintService.go

@@ -98,7 +98,7 @@ func (s *captureUintService) CaptureList(searchValue string, current, size int)
 	return details, total, nil
 }
 
-func (s *captureUintService) CaptureGetList(tenantId string, ) ([]*dao.CaptureUnit, *common.Errors) {
+func (s *captureUintService) CaptureGetList(tenantId string) ([]*dao.CaptureUnit, *common.Errors) {
 	device := &dao.CaptureUnit{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -175,7 +175,7 @@ func (s *captureUintService) PointList(searchValue string, current, size int) ([
 	return devices, total, nil
 }
 
-func (s *captureUintService) PointGetList(tenantId string, ) ([]*dao.CheckPoint, *common.Errors) {
+func (s *captureUintService) PointGetList(tenantId string) ([]*dao.CheckPoint, *common.Errors) {
 	device := &dao.CheckPoint{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -239,3 +239,15 @@ func (s *captureUintService) GetByLampPole(id int) []dao.CaptureUnit {
 	}
 	return device.GetDevicesByLampPole()
 }
+
+func (s *captureUintService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.CaptureUnit{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *captureUintService) ListDevices() []dao.Device {
+	d := dao.CaptureUnit{}
+	return d.ListDevices1()
+}

+ 13 - 2
app/device/service/gatewayService.go

@@ -148,7 +148,7 @@ func (s *gatewayService) Remove(userId int64, tenantId string, id int) *common.E
 	return nil
 }
 
-func (s *gatewayService) GetList(tenantId string, ) ([]*dao.Gateway, *common.Errors) {
+func (s *gatewayService) GetList(tenantId string) ([]*dao.Gateway, *common.Errors) {
 	var devices []*dao.Gateway
 	err := cache.Redis.Get(getGatewayListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
@@ -171,7 +171,7 @@ func (s *gatewayService) GetList(tenantId string, ) ([]*dao.Gateway, *common.Err
 	return devices, nil
 }
 
-func getGatewayListRedisKey(tenantId string, ) string {
+func getGatewayListRedisKey(tenantId string) string {
 	return fmt.Sprintf(model.GatewayList, tenantId)
 }
 
@@ -217,3 +217,14 @@ func (s *gatewayService) GetByLampPole(id int) []dao.Gateway {
 	}
 	return device.GetDevicesByLampPole()
 }
+
+func (s *gatewayService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.Gateway{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+func (s *gatewayService) ListDevices() []dao.Device {
+	pole := dao.Gateway{}
+	return pole.ListDevices1()
+}

+ 13 - 1
app/device/service/infoBoardServiceTime.go

@@ -266,7 +266,7 @@ func (s *infoBoardService) EdgeCmd(tenant, sn string, cmdNum, id int) {
 	}
 }
 
-//公用请求边缘云端
+// 公用请求边缘云端
 func (s *infoBoardService) reqEdge(tenant string, edgePost edge_service.CltLedControlReqPost, param map[string]interface{}, action string) {
 	edgePost.Param = param
 	req := edge_service.CltLedControlReq{
@@ -312,3 +312,15 @@ func ledTimeFormat(stime string, etime string) (string, string) {
 
 	return fmt.Sprintf("%v:%v:59", atoi1, ktime.Format("4")), fmt.Sprintf("%v:%v:59", atoi2, jtime.Format("4"))
 }
+
+func (s *infoBoardService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.InfoBoard{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *infoBoardService) ListDevices() []dao.Device {
+	d := dao.InfoBoard{}
+	return d.ListDevices1()
+}

+ 11 - 0
app/device/service/ipBroadcastService.go

@@ -192,3 +192,14 @@ func (s *ipBroadcastService) GetByIds(tenantId string, ids string) []dao.IpBroad
 	}
 	return device.GetByIds(ids)
 }
+func (s *ipBroadcastService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.IpBroadcast{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *ipBroadcastService) ListDevices() []dao.Device {
+	d := dao.IpBroadcast{}
+	return d.ListDevices1()
+}

+ 12 - 1
app/device/service/lampPoleService.go

@@ -120,7 +120,7 @@ func (s *lampPoleService) Remove(userId int64, tenantId string, id int) *common.
 	return nil
 }
 
-func (s *lampPoleService) GetList(tenantId string, ) ([]*dao.LampPole, *common.Errors) {
+func (s *lampPoleService) GetList(tenantId string) ([]*dao.LampPole, *common.Errors) {
 	device := &dao.LampPole{
 		TenantId:  tenantId,
 		IsDeleted: 0,
@@ -153,3 +153,14 @@ func (s *lampPoleService) CountLampPole(groupId int) int64 {
 	}
 	return device.Count()
 }
+
+func (s *lampPoleService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.LampPole{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+func (s *lampPoleService) ListDevices() []dao.Device {
+	pole := dao.LampPole{}
+	return pole.ListDevices1()
+}

+ 13 - 1
app/device/service/lightControlService.go

@@ -235,7 +235,7 @@ func (s *lightControlService) GetByLampPole(id int) []dao.LightControl {
 	return device.GetDevicesByLampPole()
 }
 
-//检查灯控编号是否合规1-1——255-255
+// 检查灯控编号是否合规1-1——255-255
 func checkControlNoIsCompliance(controlNo string) bool {
 	arr := strings.Split(controlNo, "-")
 	if len(arr) != 2 {
@@ -251,3 +251,15 @@ func checkControlNoIsCompliance(controlNo string) bool {
 	}
 	return true
 }
+
+func (s *lightControlService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.LightControl{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *lightControlService) ListDevices() []dao.Device {
+	d := dao.LightControl{}
+	return d.ListDevices1()
+}

+ 10 - 0
app/device/service/manholeCoverService.go

@@ -125,3 +125,13 @@ func (s *manholeCoverService) Setting(tenantId string, id int, threshold string)
 	}
 	return device.Update()
 }
+func (s *manholeCoverService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.ManholeCover{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+func (s *manholeCoverService) ListDevices() []dao.Device {
+	d := dao.ManholeCover{}
+	return d.ListDevices1()
+}

+ 12 - 0
app/device/service/optoSensoService.go

@@ -164,3 +164,15 @@ func (s *optoSensorService) GetAll() []*dao.OptoSensor {
 	devices := device.GetAll()
 	return devices
 }
+
+func (s *optoSensorService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.OptoSensor{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *optoSensorService) ListDevices() []dao.Device {
+	d := dao.OptoSensor{}
+	return d.ListDevices1()
+}

+ 14 - 2
app/device/service/switchBoxService.go

@@ -105,7 +105,7 @@ func (s *switchBoxService) Remove(userId int64, tenantId string, id int) *common
 	return nil
 }
 
-func (s *switchBoxService) GetList(tenantId string, ) ([]*dao.SwitchBox, *common.Errors) {
+func (s *switchBoxService) GetList(tenantId string) ([]*dao.SwitchBox, *common.Errors) {
 	var devices []*dao.SwitchBox
 	err := cache.Redis.Get(getSwitchBoxListRedisKey(tenantId)).Scan(&devices)
 	if err == nil {
@@ -124,6 +124,18 @@ func (s *switchBoxService) GetList(tenantId string, ) ([]*dao.SwitchBox, *common
 	return devices, nil
 }
 
-func getSwitchBoxListRedisKey(tenantId string, ) string {
+func getSwitchBoxListRedisKey(tenantId string) string {
 	return fmt.Sprintf(model.SwitchBoxList, tenantId)
 }
+
+func (s *switchBoxService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.SwitchBox{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *switchBoxService) ListDevices() []dao.Device {
+	d := dao.SwitchBox{}
+	return d.ListDevices1()
+}

+ 12 - 0
app/device/service/zigbeeService.go

@@ -139,3 +139,15 @@ func (s *zigbeeService) GetByLampPole(id int) []dao.Zigbee {
 	}
 	return device.GetDevicesByLampPole()
 }
+
+func (s *zigbeeService) DeviceCount() dao.DeviceStatus {
+	var rsp dao.DeviceStatus
+	d := dao.Zigbee{}
+	rsp.Set(d.DeviceCount1())
+	return rsp
+}
+
+func (s *zigbeeService) ListDevices() []dao.Device {
+	d := dao.Zigbee{}
+	return d.ListDevices1()
+}

+ 1 - 1
app/warn/dao/platformAlarmDao.go

@@ -40,7 +40,7 @@ type PlatformAlarm struct {
 	Sid               int         `gorm:"column:sid;type:int(11);comment:物模型sid" json:"sid"`                                    // 物模型sid
 	Cid               uint        `gorm:"column:cid;type:int(10) unsigned;comment:告警策略编号" json:"cid"`                           // 告警策略编号
 	Cname             string      `gorm:"column:cname;type:varchar(100);comment:告警策略名称" json:"cname"`                           // 告警策略名称
-	ExtendId          int         `gorm:"column:extend_id;type:int(11);comment:扩展id"json:"extendId"`                            // 扩展id
+	ExtendId          int         `gorm:"column:extend_id;type:int(11);comment:扩展id" json:"extendId"`                           // 扩展id
 }
 
 func (PlatformAlarm) TableName() string {

+ 2 - 2
config/config.yaml

@@ -18,7 +18,7 @@ database:
   # 数据库配置
   #db.host : 106.52.134.22
   #db.host : 120.77.219.16
-  host: "192.168.110.28"
+  host: "localhost"
   user: "root"
   password: "root"
   #password : "lczm@2019oS"
@@ -28,7 +28,7 @@ database:
   timezone: "Asia/Shanghai"
 
 redis:
-  host: "192.168.110.28:6379"
+  host: "localhost:6379"
   #password: "123456"
   #password: "lczm*2019"
 

+ 4 - 4
go.mod

@@ -6,11 +6,14 @@ require (
 	github.com/druidcaesa/gotool v0.0.0-20220613023420-645c641d1304
 	github.com/gin-gonic/gin v1.8.1
 	github.com/go-redis/redis v6.15.9+incompatible
+	github.com/goccy/go-json v0.9.7
 	github.com/golang-jwt/jwt v3.2.2+incompatible
+	github.com/google/uuid v1.3.0
 	github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f
 	github.com/minio/minio-go/v7 v7.0.43
 	github.com/mitchellh/mapstructure v1.5.0
 	github.com/mojocn/base64Captcha v1.3.5
+	github.com/olivere/elastic v6.2.37+incompatible
 	github.com/robfig/cron v1.2.0
 	github.com/satori/go.uuid v1.2.0
 	github.com/sirupsen/logrus v1.9.0
@@ -26,15 +29,14 @@ require (
 	github.com/dustin/go-humanize v1.0.0 // indirect
 	github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
 	github.com/fogleman/gg v1.3.0 // indirect
+	github.com/fortytw2/leaktest v1.3.0 // indirect
 	github.com/gin-contrib/sse v0.1.0 // indirect
 	github.com/go-playground/locales v0.14.0 // indirect
 	github.com/go-playground/universal-translator v0.18.0 // indirect
 	github.com/go-playground/validator/v10 v10.10.0 // indirect
 	github.com/go-sql-driver/mysql v1.6.0 // indirect
-	github.com/goccy/go-json v0.9.7 // indirect
 	github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
 	github.com/google/go-cmp v0.5.8 // indirect
-	github.com/google/uuid v1.3.0 // indirect
 	github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
 	github.com/jinzhu/inflection v1.0.0 // indirect
 	github.com/jinzhu/now v1.1.5 // indirect
@@ -52,12 +54,10 @@ require (
 	github.com/minio/sha256-simd v1.0.0 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
-	github.com/olivere/elastic v6.2.37+incompatible // indirect
 	github.com/onsi/ginkgo v1.16.5 // indirect
 	github.com/onsi/gomega v1.20.0 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.1 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
-	github.com/robfig/cron/v3 v3.0.0 // indirect
 	github.com/rs/xid v1.4.0 // indirect
 	github.com/tebeka/strftime v0.1.5 // indirect
 	github.com/ugorji/go/codec v1.2.7 // indirect

+ 20 - 0
router/router.go

@@ -647,4 +647,24 @@ func InitRouter(engine *gin.Engine) {
 	{
 		logGroup.POST("/callback", operation.AepCallback.Save)
 	}
+
+	//数据大屏
+	bigScreen := engine.Group("/api/longchi/largescreen")
+	{
+		bigScreen.GET("/mapclieck/device-num", device.BigScreen.DeviceNum)
+		bigScreen.GET("/overview/lamppole-status", device.BigScreen.LampPoleStatus)
+		bigScreen.GET("/overview/device-status", device.BigScreen.DevicesStatus)
+		bigScreen.GET("/overview/energy-consumption", device.BigScreen.Energy)
+		bigScreen.GET("/overview/lighting-rate", device.BigScreen.LightRate)
+		bigScreen.GET("/overview/alarm-information", device.BigScreen.AlarmInfo)
+		bigScreen.GET("/overview/alarm-device-count", device.BigScreen.AlarmStatistics)
+		bigScreen.GET("/overview/flow-information", device.BigScreen.FlowInfo)
+		bigScreen.GET("/overview/weather-now", device.BigScreen.Environment)
+		bigScreen.GET("/popup/play-programs-list", device.BigScreen.InfoBoard)
+		bigScreen.GET("/overview/play-programs", device.BigScreen.Program)
+		bigScreen.GET("/popup/bridge-sensor-pull-down-list", device.BigScreen.BridgeSensor)
+
+		bigScreen.GET("/setting/query-large-screen", device.BigScreen.QueryOverView)
+		bigScreen.POST("/setting/submit", device.BigScreen.SubmitOverView)
+	}
 }