alarmInfoHisController.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package controllers
  2. import (
  3. "rtzh_elec_temperature/rtelec_app_public_lib/service"
  4. "rtzh_elec_temperature/tools"
  5. )
  6. type AlarmInfoHisController struct {
  7. BaseController
  8. }
  9. var alarmInfoService = new(service.AlarmInfoService)
  10. // 告警详情列表查询
  11. // @Summary 告警详情列表查询
  12. // @Description 告警详情列表查询.根据查询条件返回查询结果
  13. // @Tags api
  14. // @Accept x-www-form-urlencoded
  15. // @Produce json
  16. // @Param pageInex query int true "页数."
  17. // @Param pageSize query int true "每页记录数."
  18. // @Param alarm_level query int true "告警等级."
  19. // @Param mpname query string true "测点名称."
  20. // @Param alarmDesc query string true "告警描述."
  21. // @Param beginTime query string true "开始时间"
  22. // @Param endTime query string true "结束时间"
  23. // @router /query [get]
  24. func (c *AlarmInfoHisController) QueryAlarmInfoList() {
  25. pageInex, _ := c.GetInt("pageInex", 1)
  26. pageSize, _ := c.GetInt("pageSize", 10)
  27. alarm_level, _ := c.GetInt("alarm_level", 0)
  28. mpname := c.GetString("mpname")
  29. alarmDesc := c.GetString("alarmDesc")
  30. beginTime := c.GetString("beginTime")
  31. endTime := c.GetString("endTime")
  32. res, err := alarmInfoService.QueryAlarmInfoList(mpname, alarm_level, alarmDesc, beginTime, endTime, pageInex, pageSize)
  33. if err != nil {
  34. c.Data["json"] = c.ApiError("查询告警信息明细出现错误:" + err.Error())
  35. c.ServeJSON()
  36. return
  37. }
  38. c.Data["json"] = c.ApiOK(res)
  39. c.ServeJSON()
  40. return
  41. }
  42. // 告警总数汇总统计
  43. // @Summary 告警总数汇总统计
  44. // @Description 告警总数汇总统计.统计结果包括总数、月总数、周总数、当前日总数
  45. // @Tags api
  46. // @Accept x-www-form-urlencoded
  47. // @Produce json
  48. // @Param device_id query int false "设备ID"
  49. // @Param area_id query int false "区域ID"
  50. // @router /stat/total [get]
  51. func (c *AlarmInfoHisController) StatTotal() {
  52. device_id, _ := c.GetInt64("device_id")
  53. areaid, _ := c.GetInt("area_id")
  54. res, err := alarmInfoService.GetAlarmTotal(areaid, device_id)
  55. if err != nil {
  56. c.Data["json"] = c.ApiError(err.Error())
  57. c.ServeJSON()
  58. return
  59. }
  60. c.Data["json"] = c.ApiOK(res)
  61. c.ServeJSON()
  62. return
  63. }
  64. // 按策略分类统计告警总数,并返回echarts柱状图格式数据
  65. // @Summary 按策略分类统计告警总数
  66. // @Description 按策略分类统计告警总数.并返回echarts柱状图格式数据,格式为:{"legend":[],"data":[]}
  67. // @Tags api
  68. // @Accept x-www-form-urlencoded
  69. // @Produce json
  70. // @Param device_id query int false "设备ID"
  71. // @Param area_id query int false "区域ID"
  72. // @router /stat/strategy_total/echarts [get]
  73. func (c *AlarmInfoHisController) StatStrategyTotal() {
  74. device_id, _ := c.GetInt64("device_id")
  75. areaid, _ := c.GetInt("area_id")
  76. res, err := alarmInfoService.GetAlarmTotalByStrategy(areaid, device_id)
  77. if err != nil {
  78. c.Data["json"] = c.ApiError(err.Error())
  79. c.ServeJSON()
  80. return
  81. }
  82. legend := []string{}
  83. datas := []string{}
  84. for _, row := range res {
  85. legend = append(legend, tools.IsEmpty(row["strategy_name"]))
  86. cnt := tools.IsEmpty(row["cnt"])
  87. if cnt == "" {
  88. cnt = "0"
  89. }
  90. datas = append(datas, cnt)
  91. }
  92. c.Data["json"] = c.ApiOK(map[string]interface{}{
  93. "legend": legend,
  94. "data": datas,
  95. })
  96. c.ServeJSON()
  97. return
  98. }
  99. // 用户告警确认
  100. // @Summary 用户告警确认
  101. // @Description 用户告警确认
  102. // @Tags api
  103. // @Accept x-www-form-urlencoded
  104. // @Produce json
  105. // @Param id query int64 true "告警信息ID"
  106. // @router /confirm [POST]
  107. func (c *AlarmInfoHisController) ConfirmAlrmInfo() {
  108. id, err := c.GetInt64("id")
  109. if err != nil {
  110. c.Data["json"] = c.ApiError(err.Error())
  111. c.ServeJSON()
  112. return
  113. }
  114. err = alarmInfoService.ConfirmAlrmInfo(id)
  115. if err != nil {
  116. c.Data["json"] = c.ApiError(err.Error())
  117. c.ServeJSON()
  118. return
  119. }
  120. c.Data["json"] = c.ApiOK("ok")
  121. c.ServeJSON()
  122. return
  123. }