edb_monitor_classify.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package edb_monitor
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/edb_monitor/request"
  7. edbmonitor "eta/eta_api/services/edb_monitor"
  8. "strings"
  9. )
  10. type EdbMonitorClassifyController struct {
  11. controllers.BaseAuthController
  12. }
  13. // List
  14. // @Title 预警管理分类列表
  15. // @Description 预警管理分类列表
  16. // @Success 200 {object} response.EdbMonitorClassifyTree
  17. // @router /classify/list [get]
  18. func (c *EdbMonitorClassifyController) List() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. c.Data["json"] = br
  22. c.ServeJSON()
  23. }()
  24. sysUser := c.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. resp, msg, err := edbmonitor.GetEdbMonitorClassifyTree()
  32. if err != nil {
  33. if msg == "" {
  34. msg = "获取分类列表失败"
  35. }
  36. br.Msg = msg
  37. br.ErrMsg = err.Error()
  38. return
  39. }
  40. br.Data = resp
  41. br.Msg = "获取成功"
  42. br.Ret = 200
  43. br.Success = true
  44. }
  45. // Add
  46. // @Title 预警管理分类添加
  47. // @Description 预警管理分类添加
  48. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  49. // @Success 200 {object} models.EnglishReportEmailPageListResp
  50. // @router /classify/add [post]
  51. func (c *EdbMonitorClassifyController) Add() {
  52. br := new(models.BaseResponse).Init()
  53. defer func() {
  54. c.Data["json"] = br
  55. c.ServeJSON()
  56. }()
  57. sysUser := c.SysUser
  58. if sysUser == nil {
  59. br.Msg = "请登录"
  60. br.ErrMsg = "请登录,SysUser Is Empty"
  61. br.Ret = 408
  62. return
  63. }
  64. var req request.EdbMonitorClassifySaveReq
  65. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  66. br.Msg = "参数解析失败"
  67. br.ErrMsg = err.Error()
  68. return
  69. }
  70. req.ClassifyName = strings.TrimSpace(req.ClassifyName)
  71. if req.ClassifyName == "" {
  72. br.Msg = "分类名称不能为空"
  73. return
  74. }
  75. if req.Level <= 0 || req.ClassifyId > 0 {
  76. br.Msg = "参数错误"
  77. return
  78. }
  79. msg, err := edbmonitor.SaveEdbMonitorClassify(req)
  80. if err != nil {
  81. if msg == "" {
  82. msg = "分类添加失败"
  83. }
  84. br.Msg = msg
  85. br.ErrMsg = err.Error()
  86. return
  87. }
  88. br.Msg = "分类添加成功"
  89. br.Ret = 200
  90. br.Success = true
  91. }
  92. // Edit
  93. // @Title 预警管理分类编辑
  94. // @Description 预警管理分类编辑
  95. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  96. // @router /classify/edit [post]
  97. func (c *EdbMonitorClassifyController) Edit() {
  98. br := new(models.BaseResponse).Init()
  99. defer func() {
  100. c.Data["json"] = br
  101. c.ServeJSON()
  102. }()
  103. sysUser := c.SysUser
  104. if sysUser == nil {
  105. br.Msg = "请登录"
  106. br.ErrMsg = "请登录,SysUser Is Empty"
  107. br.Ret = 408
  108. return
  109. }
  110. var req request.EdbMonitorClassifySaveReq
  111. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  112. br.Msg = "参数解析失败"
  113. br.ErrMsg = err.Error()
  114. return
  115. }
  116. if req.ClassifyId <= 0 {
  117. br.Msg = "分类不存在,请刷新页面"
  118. return
  119. }
  120. req.ClassifyName = strings.TrimSpace(req.ClassifyName)
  121. if req.ClassifyName == "" {
  122. br.Msg = "分类名称不能为空"
  123. return
  124. }
  125. if req.Level <= 0 {
  126. br.Msg = "参数错误"
  127. return
  128. }
  129. msg, err := edbmonitor.SaveEdbMonitorClassify(req)
  130. if err != nil {
  131. if msg == "" {
  132. msg = "分类添加失败"
  133. }
  134. br.Msg = msg
  135. br.ErrMsg = err.Error()
  136. return
  137. }
  138. br.Msg = "分类编辑成功"
  139. br.Ret = 200
  140. br.Success = true
  141. }
  142. // Delete
  143. // @Title 预警管理分类删除
  144. // @Description 预警管理分类删除
  145. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  146. // @router /classify/delete [post]
  147. func (c *EdbMonitorClassifyController) Delete() {
  148. br := new(models.BaseResponse).Init()
  149. defer func() {
  150. c.Data["json"] = br
  151. c.ServeJSON()
  152. }()
  153. sysUser := c.SysUser
  154. if sysUser == nil {
  155. br.Msg = "请登录"
  156. br.ErrMsg = "请登录,SysUser Is Empty"
  157. br.Ret = 408
  158. return
  159. }
  160. var req request.EdbMonitorClassifyDeleteReq
  161. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  162. br.Msg = "参数解析失败"
  163. br.ErrMsg = err.Error()
  164. return
  165. }
  166. if req.ClassifyId <= 0 {
  167. br.Msg = "分类不存在,请刷新页面"
  168. return
  169. }
  170. msg, err := edbmonitor.DeleteEdbMonitorClassify(req)
  171. if err != nil {
  172. if msg == "" {
  173. msg = "分类删除失败"
  174. }
  175. br.Msg = msg
  176. br.ErrMsg = err.Error()
  177. return
  178. }
  179. br.Msg = "分类删除成功"
  180. br.Ret = 200
  181. br.Success = true
  182. }
  183. // Move
  184. // @Title 预警分类移动接口
  185. // @Description 预警分类移动接口
  186. // @Param request body request.MoveEdbMonitorClassifyReq true "每页数据条数"
  187. // @router /classify/move [post]
  188. func (c *EdbMonitorClassifyController) Move() {
  189. br := new(models.BaseResponse).Init()
  190. defer func() {
  191. c.Data["json"] = br
  192. c.ServeJSON()
  193. }()
  194. var req request.MoveEdbMonitorClassifyReq
  195. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  196. br.Msg = "参数解析失败"
  197. br.ErrMsg = err.Error()
  198. return
  199. }
  200. if req.ClassifyId <= 0 {
  201. br.Msg = "参数错误"
  202. br.ErrMsg = "分类id小于等于0"
  203. return
  204. }
  205. msg, err := edbmonitor.MoveEdbMonitorClassify(req)
  206. if err != nil {
  207. if msg == "" {
  208. msg = "分类移动失败"
  209. }
  210. br.Msg = msg
  211. br.ErrMsg = err.Error()
  212. return
  213. }
  214. br.Msg = "分类移动成功"
  215. br.Ret = 200
  216. br.Success = true
  217. }