ruleController.go 5.7 KB

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