edb_monitor.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 EdbMonitorController struct {
  11. controllers.BaseAuthController
  12. }
  13. // List
  14. // @Title 预警管理列表
  15. // @Description 预警管理列表
  16. // @Param PageSize query int true "每页数据条数"
  17. // @Param CurrentIndex query int true "当前页页码,从1开始"
  18. // @Param ClassifyId query string true "分类ID,多选用逗号分隔"
  19. // @Param Level query string true "预警等级,多选用逗号分隔"
  20. // @Param State query string true "预警状态,多选用逗号分隔"
  21. // @Param UserId query string true "创建人ID,多选用逗号分隔"
  22. // @Success 200 {object} response.EdbMonitorInfoListResp
  23. // @router /list [get]
  24. func (m *EdbMonitorController) List() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. m.Data["json"] = br
  28. m.ServeJSON()
  29. }()
  30. sysUser := m.SysUser
  31. if sysUser == nil {
  32. br.Msg = "请登录"
  33. br.ErrMsg = "请登录,SysUser Is Empty"
  34. br.Ret = 408
  35. return
  36. }
  37. pageSize, _ := m.GetInt("PageSize")
  38. currentIndex, _ := m.GetInt("CurrentIndex")
  39. classifyId := m.GetString("ClassifyId")
  40. level := m.GetString("Level")
  41. state := m.GetString("State")
  42. userId := m.GetString("UserId")
  43. resp, msg, err := edbmonitor.GetMonitorList(classifyId, level, state, userId, pageSize, currentIndex)
  44. if err != nil {
  45. if msg == "" {
  46. msg = "获取列表失败"
  47. }
  48. br.Msg = msg
  49. br.ErrMsg = err.Error()
  50. return
  51. }
  52. br.Data = resp
  53. br.Msg = "获取列表成功"
  54. br.Ret = 200
  55. br.Success = true
  56. }
  57. // Add
  58. // @Title 预警管理添加
  59. // @Description 预警管理添加
  60. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  61. // @Success 200 {object} models.EnglishReportEmailPageListResp
  62. // @router /add [post]
  63. func (m *EdbMonitorController) Add() {
  64. br := new(models.BaseResponse).Init()
  65. defer func() {
  66. m.Data["json"] = br
  67. m.ServeJSON()
  68. }()
  69. sysUser := m.SysUser
  70. if sysUser == nil {
  71. br.Msg = "请登录"
  72. br.ErrMsg = "请登录,SysUser Is Empty"
  73. br.Ret = 408
  74. return
  75. }
  76. var req request.EdbMonitorInfoSaveReq
  77. if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
  78. br.Msg = "参数解析失败"
  79. br.ErrMsg = err.Error()
  80. return
  81. }
  82. if req.ClassifyId <= 0 {
  83. br.Msg = "请选择分类"
  84. return
  85. }
  86. switch req.MonitorType {
  87. case edbmonitor.EDB_MONITOR_TYPE_DOWN, edbmonitor.EDB_MONITOR_TYPE_UP:
  88. default:
  89. br.Msg = "请选择预警等级"
  90. return
  91. }
  92. req.MonitorData = strings.TrimSpace(req.MonitorData)
  93. if req.MonitorData == "" {
  94. br.Msg = "请输入预警值"
  95. return
  96. }
  97. req.EdbMonitorName = strings.TrimSpace(req.EdbMonitorName)
  98. if req.EdbMonitorName == "" {
  99. br.Msg = "请输入预警名称"
  100. return
  101. }
  102. msg, err := edbmonitor.SaveEdbMonitorInfo(req, sysUser.AdminId)
  103. if err != nil {
  104. if msg == "" {
  105. msg = "添加失败"
  106. }
  107. br.Msg = msg
  108. br.ErrMsg = err.Error()
  109. return
  110. }
  111. br.Msg = "添加成功"
  112. br.Ret = 200
  113. br.Success = true
  114. }
  115. // edit
  116. // @Title 预警管理编辑
  117. // @Description 预警管理编辑
  118. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  119. // @Success 200 {object} models.EnglishReportEmailPageListResp
  120. // @router /edit [post]
  121. func (m *EdbMonitorController) Edit() {
  122. br := new(models.BaseResponse).Init()
  123. defer func() {
  124. m.Data["json"] = br
  125. m.ServeJSON()
  126. }()
  127. sysUser := m.SysUser
  128. if sysUser == nil {
  129. br.Msg = "请登录"
  130. br.ErrMsg = "请登录,SysUser Is Empty"
  131. br.Ret = 408
  132. return
  133. }
  134. var req request.EdbMonitorInfoSaveReq
  135. if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
  136. br.Msg = "参数解析失败"
  137. br.ErrMsg = err.Error()
  138. return
  139. }
  140. if req.EdbInfoId <= 0 {
  141. br.Msg = "请选择指标"
  142. return
  143. }
  144. if req.EdbMonitorId <= 0 {
  145. br.Msg = "请选择预警"
  146. return
  147. }
  148. if req.ClassifyId <= 0 {
  149. br.Msg = "请选择分类"
  150. return
  151. }
  152. switch req.MonitorType {
  153. case edbmonitor.EDB_MONITOR_TYPE_DOWN, edbmonitor.EDB_MONITOR_TYPE_UP:
  154. default:
  155. br.Msg = "请选择预警等级"
  156. return
  157. }
  158. req.MonitorData = strings.TrimSpace(req.MonitorData)
  159. if req.MonitorData == "" {
  160. br.Msg = "请输入预警值"
  161. return
  162. }
  163. req.EdbMonitorName = strings.TrimSpace(req.EdbMonitorName)
  164. if req.EdbMonitorName == "" {
  165. br.Msg = "请输入预警名称"
  166. return
  167. }
  168. msg, err := edbmonitor.SaveEdbMonitorInfo(req, sysUser.AdminId)
  169. if err != nil {
  170. if msg == "" {
  171. msg = "编辑失败"
  172. }
  173. br.Msg = msg
  174. br.ErrMsg = err.Error()
  175. return
  176. }
  177. br.Msg = "编辑成功"
  178. br.Ret = 200
  179. br.Success = true
  180. }
  181. // delete
  182. // @Title 预警管理编辑
  183. // @Description 预警管理编辑
  184. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  185. // @Success 200 {object} models.EnglishReportEmailPageListResp
  186. // @router /delete [post]
  187. func (m *EdbMonitorController) Delete() {
  188. br := new(models.BaseResponse).Init()
  189. defer func() {
  190. m.Data["json"] = br
  191. m.ServeJSON()
  192. }()
  193. sysUser := m.SysUser
  194. if sysUser == nil {
  195. br.Msg = "请登录"
  196. br.ErrMsg = "请登录,SysUser Is Empty"
  197. br.Ret = 408
  198. return
  199. }
  200. var req request.EdbMonitorInfoDeleteReq
  201. if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
  202. br.Msg = "参数解析失败"
  203. br.ErrMsg = err.Error()
  204. return
  205. }
  206. if req.EdbMonitorId <= 0 {
  207. br.Msg = "请选择指标"
  208. return
  209. }
  210. msg, err := edbmonitor.DeleteEdbMonitorInfo(req, sysUser.AdminId)
  211. if err != nil {
  212. if msg == "" {
  213. msg = "删除失败"
  214. }
  215. br.Msg = msg
  216. br.ErrMsg = err.Error()
  217. return
  218. }
  219. br.Msg = "删除成功"
  220. br.Ret = 200
  221. br.Success = true
  222. }
  223. // Close
  224. // @Title 预警管理关闭
  225. // @Description 预警管理关闭
  226. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  227. // @Success 200 {object} models.EnglishReportEmailPageListResp
  228. // @router /close [post]
  229. func (m *EdbMonitorController) Close() {
  230. br := new(models.BaseResponse).Init()
  231. defer func() {
  232. m.Data["json"] = br
  233. m.ServeJSON()
  234. }()
  235. sysUser := m.SysUser
  236. if sysUser == nil {
  237. br.Msg = "请登录"
  238. br.ErrMsg = "请登录,SysUser Is Empty"
  239. br.Ret = 408
  240. return
  241. }
  242. var req request.EdbMonitorInfoCloseReq
  243. if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
  244. br.Msg = "参数解析失败"
  245. br.ErrMsg = err.Error()
  246. return
  247. }
  248. if req.EdbMonitorId <= 0 {
  249. br.Msg = "请选择预警"
  250. return
  251. }
  252. msg, err := edbmonitor.CloseEdbMonitorInfo(req, sysUser.AdminId)
  253. if err != nil {
  254. if msg == "" {
  255. msg = "关闭失败"
  256. }
  257. br.Msg = msg
  258. br.ErrMsg = err.Error()
  259. return
  260. }
  261. br.Msg = "关闭成功"
  262. br.Ret = 200
  263. br.Success = true
  264. }
  265. // Restart
  266. // @Title 预警管理重启
  267. // @Description 预警管理重启
  268. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  269. // @Success 200 {object} models.EnglishReportEmailPageListResp
  270. // @router /restart [post]
  271. func (m *EdbMonitorController) Restart() {
  272. br := new(models.BaseResponse).Init()
  273. defer func() {
  274. m.Data["json"] = br
  275. m.ServeJSON()
  276. }()
  277. sysUser := m.SysUser
  278. if sysUser == nil {
  279. br.Msg = "请登录"
  280. br.ErrMsg = "请登录,SysUser Is Empty"
  281. br.Ret = 408
  282. return
  283. }
  284. var req request.EdbMonitorInfoRestartReq
  285. if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
  286. br.Msg = "参数解析失败"
  287. br.ErrMsg = err.Error()
  288. return
  289. }
  290. if req.EdbMonitorId <= 0 {
  291. br.Msg = "请选择预警"
  292. return
  293. }
  294. msg, err := edbmonitor.RestartEdbMonitorInfo(req, sysUser.AdminId)
  295. if err != nil {
  296. if msg == "" {
  297. msg = "重启失败"
  298. }
  299. br.Msg = msg
  300. br.ErrMsg = err.Error()
  301. return
  302. }
  303. br.Msg = "重启成功"
  304. br.Ret = 200
  305. br.Success = true
  306. }
  307. // GetMonitorLevel
  308. // @Title 预警管理等级列表
  309. // @Description 预警管理等级列表
  310. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  311. // @Success 200 {object} models.EnglishReportEmailPageListResp
  312. // @router /monitor_level/list [get]
  313. func (m *EdbMonitorController) GetMonitorLevel() {
  314. br := new(models.BaseResponse).Init()
  315. defer func() {
  316. m.Data["json"] = br
  317. m.ServeJSON()
  318. }()
  319. sysUser := m.SysUser
  320. if sysUser == nil {
  321. br.Msg = "请登录"
  322. br.ErrMsg = "请登录,SysUser Is Empty"
  323. br.Ret = 408
  324. return
  325. }
  326. list, msg, err := edbmonitor.GetEdbMonitorLevelList()
  327. if err != nil {
  328. if msg == "" {
  329. msg = "获取预警等级失败"
  330. }
  331. br.Msg = msg
  332. br.ErrMsg = err.Error()
  333. return
  334. }
  335. br.Data = list
  336. br.Msg = "获取成功"
  337. br.Ret = 200
  338. br.Success = true
  339. }
  340. // GetMonitorUser
  341. // @Title 预警管理用户列表
  342. // @Description 预警管理用户列表
  343. // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
  344. // @Success 200 {object} models.EnglishReportEmailPageListResp
  345. // @router /monitor_user/list [get]
  346. func (m *EdbMonitorController) GetMonitorUser() {
  347. br := new(models.BaseResponse).Init()
  348. defer func() {
  349. m.Data["json"] = br
  350. m.ServeJSON()
  351. }()
  352. sysUser := m.SysUser
  353. if sysUser == nil {
  354. br.Msg = "请登录"
  355. br.ErrMsg = "请登录,SysUser Is Empty"
  356. br.Ret = 408
  357. return
  358. }
  359. resp, msg, err := edbmonitor.GetEdbMonitorInfoUserList()
  360. if err != nil {
  361. if msg == "" {
  362. msg = "获取用户列表失败"
  363. }
  364. br.Msg = msg
  365. br.ErrMsg = err.Error()
  366. return
  367. }
  368. br.Data = resp
  369. br.Msg = "获取成功"
  370. br.Ret = 200
  371. br.Success = true
  372. }