ruleController.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * @Author: lilig
  3. * @Date: 2022-10-04 10:07:52
  4. * @LastEditors: lilifor
  5. * @LastEditTime: 2022-10-04 10:44:58
  6. * @FilePath: \SCD\controllers\wsController.go
  7. * @Description:
  8. *
  9. * Copyright (c) 2022 by lilig/jujutong, All Rights Reserved.
  10. */
  11. package controllers
  12. import (
  13. "scd_check_tools/models/bo"
  14. "strconv"
  15. )
  16. //校验规则管理服务
  17. type RuleController struct {
  18. BaseController
  19. }
  20. func init() {
  21. }
  22. // @Summary 获取校验规则列表
  23. // @Description 获取校验规则列表
  24. // @Tags 校验规则管理服务接口
  25. // @Accept x-www-form-urlencoded
  26. // @Produce json
  27. // @Param pageindex query int false "当前页码。默认为1 "
  28. // @Param pagesize query int false "每页显示记录数。默认为20"
  29. // @Param id query int false "规则ID"
  30. // @Param enable query int false "是否启用。默认为全部"
  31. // @Param object_name query string false "规则的对象名称"
  32. // @Param object_type query int false "规则的对象分类"
  33. // @Param alert_level query string false "规则的告警级别。值为error\alert\hint之一。"
  34. // @Param apply_standard query string false "规则标准"
  35. // @Success 200 {object} ResultOK 成功
  36. // @Failure 500 status 失败
  37. // @router /scd/rule/list [get]
  38. func (c *RuleController) GetRuleDefList() {
  39. rule_type := c.GetString("rule_type")
  40. enable := c.GetString("enable")
  41. object_name := c.GetString("object_name")
  42. object_type := c.GetString("object_type")
  43. alert_level := c.GetString("alert_level")
  44. rule_id := c.GetString("id")
  45. pageno, _ := c.GetInt("pageindex", 1)
  46. pagesize, _ := c.GetInt("pagesize", 20)
  47. if rule_type == "" {
  48. rule_type = "logic"
  49. }
  50. obj := new(bo.ScdNodeRule)
  51. para := map[string]interface{}{}
  52. para["rule_id"] = rule_id
  53. para["rule_type"] = rule_type
  54. para["enable"] = enable
  55. para["object_name"] = object_name
  56. para["object_type"] = object_type
  57. para["alert_level"] = alert_level
  58. para["check_type"] = c.GetString("check_type")
  59. para["apply_standard"] = c.GetString("apply_standard")
  60. rowset, cnt, err := obj.GetDefList(para, pageno, pagesize)
  61. if err != nil {
  62. c.Data["json"] = c.ResultError(err.Error())
  63. c.ServeJSON()
  64. return
  65. }
  66. c.Data["json"] = c.ResultOK(rowset, cnt)
  67. c.ServeJSON()
  68. }
  69. /**
  70. * @description: 保存信息
  71. * @Author: liling
  72. * @method: post
  73. * @parameter:
  74. * @url: /save
  75. * @content-type: application/json
  76. * @return json格式
  77. */
  78. // @Summary 保存校验规则
  79. // @Description 保存校验规则
  80. // @Tags 校验规则管理服务接口
  81. // @Accept x-www-form-urlencoded
  82. // @Produce json
  83. // @Param id formData int false "规则ID。不为0时表示编辑"
  84. // @Param enable formData int false "是否启用。默认为全部"
  85. // @Param object_name formData string false "规则的对象名称"
  86. // @Param object_type formData int false "规则的对象分类"
  87. // @Param alert_level formData string false "规则的告警级别。值为error\alert\hint之一。"
  88. // @Param apply_standard formData string false "规则标准"
  89. // @Success 200 {object} ResultOK 成功
  90. // @Failure 500 status 失败
  91. // @router /scd/rule/save [post]
  92. func (c *RuleController) SaveScdRuleDef() {
  93. //变电站ID
  94. //station_id := c.GetString("station_id")
  95. rule_type := c.GetString("rule_type")
  96. if rule_type == "" {
  97. rule_type = "logic"
  98. }
  99. param := map[string]string{}
  100. flowObj := new(bo.ScdNodeRule)
  101. flowObj.SetUserInfo(c.GetCurrentUserInfo())
  102. for k, v := range c.Ctx.Request.PostForm {
  103. param[k] = v[0]
  104. }
  105. err := flowObj.AddRuleDef(param, rule_type)
  106. if err != nil {
  107. c.Data["json"] = c.ResultError(err.Error())
  108. c.ServeJSON()
  109. return
  110. }
  111. c.Data["json"] = c.ResultOK("", 0)
  112. c.ServeJSON()
  113. }
  114. /**
  115. * @description: 删除信息
  116. * @Author: liling
  117. * @method: post
  118. * @parameter: user_id,id
  119. * @url: /remove
  120. * @content-type: application/json
  121. * @return json格式
  122. */
  123. // @Summary 删除校验规则
  124. // @Description 删除校验规则
  125. // @Tags 校验规则管理服务接口
  126. // @Accept x-www-form-urlencoded
  127. // @Produce json
  128. // @Param id formData int true "规则ID"
  129. // @Success 200 {object} ResultOK 成功
  130. // @Failure 500 status 失败
  131. // @router /scd/rule/remove [post]
  132. func (c *RuleController) DeleteScdRuleDef() {
  133. id := c.GetString("id")
  134. if id == "" {
  135. c.Data["json"] = c.ResultError("规则编号不能为空!")
  136. c.ServeJSON()
  137. return
  138. }
  139. rule_type := c.GetString("rule_type")
  140. if rule_type == "" {
  141. rule_type = "logic"
  142. }
  143. flowObj := new(bo.ScdNodeRule)
  144. flowObj.SetUserInfo(c.GetCurrentUserInfo())
  145. err := flowObj.DeleteRuleDef(id, rule_type)
  146. if err != nil {
  147. c.Data["json"] = c.ResultError(err.Error())
  148. c.ServeJSON()
  149. return
  150. }
  151. c.Data["json"] = c.ResultOK("", 0)
  152. c.ServeJSON()
  153. }
  154. //重新校验指定scd
  155. // @Summary 重新校验指定scd
  156. // @Description 重新校验指定scd
  157. // @Tags 校验规则管理服务接口
  158. // @Accept x-www-form-urlencoded
  159. // @Produce json
  160. // @Param scd_id formData int true "SCD文件ID"
  161. // @Success 200 {object} ResultOK 成功
  162. // @Failure 500 status 失败
  163. // @router /scd/rule/reset [post]
  164. func (c *RuleController) ResetRule() {
  165. id := c.GetString("scd_id")
  166. if id == "" {
  167. c.Data["json"] = c.ResultError("校验的SCD文件编号不能为空!")
  168. c.ServeJSON()
  169. return
  170. }
  171. flowObj := new(bo.ScdNodeRule)
  172. flowObj.SetUserInfo(c.GetCurrentUserInfo())
  173. flowObj.ScdID, _ = strconv.ParseInt(id, 10, 64)
  174. flowObj.TestCheckRule()
  175. c.Data["json"] = c.ResultOK("", 0)
  176. c.ServeJSON()
  177. }