package controller import ( "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) { 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, "") }