mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【feat】首页面板告警数据
This commit is contained in:
@@ -14,6 +14,11 @@ type DeviceAlarmApi struct {
|
||||
DeviceAlarmApp services.DeviceAlarmModel
|
||||
}
|
||||
|
||||
func (p *DeviceAlarmApi) GetDeviceAlarmPanel(rc *restfulx.ReqCtx) {
|
||||
panel := p.DeviceAlarmApp.FindAlarmPanel()
|
||||
rc.ResData = panel
|
||||
}
|
||||
|
||||
// GetDeviceAlarmList 告警列表数据
|
||||
func (p *DeviceAlarmApi) GetDeviceAlarmList(rc *restfulx.ReqCtx) {
|
||||
data := entity.DeviceAlarmForm{}
|
||||
|
||||
@@ -65,3 +65,8 @@ type DeviceCountType struct {
|
||||
Total int64 `json:"deviceTotal"`
|
||||
DeviceType string `json:"deviceType"`
|
||||
}
|
||||
|
||||
type DeviceAlarmCount struct {
|
||||
Date string `json:"date"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
|
||||
@@ -20,6 +20,14 @@ func InitDeviceAlarmRouter(container *restful.Container) {
|
||||
ws.Path("/device/alarm").Produces(restful.MIME_JSON)
|
||||
tags := []string{"alarm"}
|
||||
|
||||
ws.Route(ws.GET("/panel").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取面板告警分组").Handle(s.GetDeviceAlarmPanel)
|
||||
}).
|
||||
Doc("获取面板告警分组").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Writes(entity.DeviceAlarmCount{}).
|
||||
Returns(200, "OK", entity.DeviceAlarmCount{}))
|
||||
|
||||
ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
|
||||
restfulx.NewReqCtx(request, response).WithLog("获取告警分页列表").Handle(s.GetDeviceAlarmList)
|
||||
}).
|
||||
|
||||
@@ -16,6 +16,7 @@ type (
|
||||
Update(data entity.DeviceAlarm) error
|
||||
Delete(ids []string)
|
||||
FindAlarmCount() entity.DeviceCount
|
||||
FindAlarmPanel() []entity.DeviceAlarmCount
|
||||
}
|
||||
|
||||
alarmModelImpl struct {
|
||||
@@ -102,3 +103,9 @@ func (m *alarmModelImpl) FindAlarmCount() (count entity.DeviceCount) {
|
||||
biz.ErrIsNil(err, "获取告警统计总数失败")
|
||||
return
|
||||
}
|
||||
func (m *alarmModelImpl) FindAlarmPanel() (count []entity.DeviceAlarmCount) {
|
||||
sql := `SELECT CAST(time AS DATE) AS date, COUNT(*) AS count FROM device_alarms WHERE time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY CAST(time AS DATE)`
|
||||
err := global.Db.Raw(sql).Scan(&count).Error
|
||||
biz.ErrIsNil(err, "获取告警统计列表失败")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user