123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package controllers
- import (
- "rtzh_elec_temperature/rtelec_app_public_lib/service"
- "rtzh_elec_temperature/tools"
- )
- type AlarmInfoHisController struct {
- BaseController
- }
- var alarmInfoService = new(service.AlarmInfoService)
- // 告警详情列表查询
- // @Summary 告警详情列表查询
- // @Description 告警详情列表查询.根据查询条件返回查询结果
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pageInex query int true "页数."
- // @Param pageSize query int true "每页记录数."
- // @Param alarm_level query int true "告警等级."
- // @Param mpname query string true "测点名称."
- // @Param alarmDesc query string true "告警描述."
- // @Param beginTime query string true "开始时间"
- // @Param endTime query string true "结束时间"
- // @router /query [get]
- func (c *AlarmInfoHisController) QueryAlarmInfoList() {
- pageInex, _ := c.GetInt("pageInex", 1)
- pageSize, _ := c.GetInt("pageSize", 10)
- alarm_level, _ := c.GetInt("alarm_level", 0)
- mpname := c.GetString("mpname")
- alarmDesc := c.GetString("alarmDesc")
- beginTime := c.GetString("beginTime")
- endTime := c.GetString("endTime")
- res, err := alarmInfoService.QueryAlarmInfoList(mpname, alarm_level, alarmDesc, beginTime, endTime, pageInex, pageSize)
- if err != nil {
- c.Data["json"] = c.ApiError("查询告警信息明细出现错误:" + err.Error())
- c.ServeJSON()
- return
- }
- c.Data["json"] = c.ApiOK(res)
- c.ServeJSON()
- return
- }
- // 告警总数汇总统计
- // @Summary 告警总数汇总统计
- // @Description 告警总数汇总统计.统计结果包括总数、月总数、周总数、当前日总数
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param device_id query int false "设备ID"
- // @Param area_id query int false "区域ID"
- // @router /stat/total [get]
- func (c *AlarmInfoHisController) StatTotal() {
- device_id, _ := c.GetInt64("device_id")
- areaid, _ := c.GetInt("area_id")
- res, err := alarmInfoService.GetAlarmTotal(areaid, device_id)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- c.ServeJSON()
- return
- }
- c.Data["json"] = c.ApiOK(res)
- c.ServeJSON()
- return
- }
- // 按策略分类统计告警总数,并返回echarts柱状图格式数据
- // @Summary 按策略分类统计告警总数
- // @Description 按策略分类统计告警总数.并返回echarts柱状图格式数据,格式为:{"legend":[],"data":[]}
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param device_id query int false "设备ID"
- // @Param area_id query int false "区域ID"
- // @router /stat/strategy_total/echarts [get]
- func (c *AlarmInfoHisController) StatStrategyTotal() {
- device_id, _ := c.GetInt64("device_id")
- areaid, _ := c.GetInt("area_id")
- res, err := alarmInfoService.GetAlarmTotalByStrategy(areaid, device_id)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- c.ServeJSON()
- return
- }
- legend := []string{}
- datas := []string{}
- for _, row := range res {
- legend = append(legend, tools.IsEmpty(row["strategy_name"]))
- cnt := tools.IsEmpty(row["cnt"])
- if cnt == "" {
- cnt = "0"
- }
- datas = append(datas, cnt)
- }
- c.Data["json"] = c.ApiOK(map[string]interface{}{
- "legend": legend,
- "data": datas,
- })
- c.ServeJSON()
- return
- }
- // 用户告警确认
- // @Summary 用户告警确认
- // @Description 用户告警确认
- // @Tags api
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int64 true "告警信息ID"
- // @router /confirm [POST]
- func (c *AlarmInfoHisController) ConfirmAlrmInfo() {
- id, err := c.GetInt64("id")
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- c.ServeJSON()
- return
- }
- err = alarmInfoService.ConfirmAlrmInfo(id)
- if err != nil {
- c.Data["json"] = c.ApiError(err.Error())
- c.ServeJSON()
- return
- }
- c.Data["json"] = c.ApiOK("ok")
- c.ServeJSON()
- return
- }
|