【feat】首页面板告警数据

This commit is contained in:
XM-GO
2023-09-25 11:47:39 +08:00
parent d3a7deb66f
commit cdbbe85a70
6 changed files with 214 additions and 1 deletions

View File

@@ -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{}

View File

@@ -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"`
}

View File

@@ -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)
}).

View File

@@ -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
}