123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- package edb_monitor
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/edb_monitor/request"
- edbmonitor "eta/eta_api/services/edb_monitor"
- "strings"
- )
- type EdbMonitorController struct {
- controllers.BaseAuthController
- }
- // List
- // @Title 预警管理列表
- // @Description 预警管理列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query string true "分类ID,多选用逗号分隔"
- // @Param Level query string true "预警等级,多选用逗号分隔"
- // @Param State query string true "预警状态,多选用逗号分隔"
- // @Param UserId query string true "创建人ID,多选用逗号分隔"
- // @Success 200 {object} response.EdbMonitorInfoListResp
- // @router /list [get]
- func (m *EdbMonitorController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- pageSize, _ := m.GetInt("PageSize")
- currentIndex, _ := m.GetInt("CurrentIndex")
- classifyId := m.GetString("ClassifyId")
- level := m.GetString("Level")
- state := m.GetString("State")
- userId := m.GetString("UserId")
- resp, msg, err := edbmonitor.GetMonitorList(classifyId, level, state, userId, pageSize, currentIndex)
- if err != nil {
- if msg == "" {
- msg = "获取列表失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Data = resp
- br.Msg = "获取列表成功"
- br.Ret = 200
- br.Success = true
- }
- // Add
- // @Title 预警管理添加
- // @Description 预警管理添加
- // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
- // @Success 200 {object} models.EnglishReportEmailPageListResp
- // @router /add [post]
- func (m *EdbMonitorController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.EdbMonitorInfoSaveReq
- if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = err.Error()
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- switch req.MonitorType {
- case edbmonitor.EDB_MONITOR_TYPE_DOWN, edbmonitor.EDB_MONITOR_TYPE_UP:
- default:
- br.Msg = "请选择预警等级"
- return
- }
- req.MonitorData = strings.TrimSpace(req.MonitorData)
- if req.MonitorData == "" {
- br.Msg = "请输入预警值"
- return
- }
- req.EdbMonitorName = strings.TrimSpace(req.EdbMonitorName)
- if req.EdbMonitorName == "" {
- br.Msg = "请输入预警名称"
- return
- }
- msg, err := edbmonitor.SaveEdbMonitorInfo(req, sysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "添加失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Msg = "添加成功"
- br.Ret = 200
- br.Success = true
- }
- // edit
- // @Title 预警管理编辑
- // @Description 预警管理编辑
- // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
- // @Success 200 {object} models.EnglishReportEmailPageListResp
- // @router /edit [post]
- func (m *EdbMonitorController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.EdbMonitorInfoSaveReq
- if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "请选择指标"
- return
- }
- if req.EdbMonitorId <= 0 {
- br.Msg = "请选择预警"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- switch req.MonitorType {
- case edbmonitor.EDB_MONITOR_TYPE_DOWN, edbmonitor.EDB_MONITOR_TYPE_UP:
- default:
- br.Msg = "请选择预警等级"
- return
- }
- req.MonitorData = strings.TrimSpace(req.MonitorData)
- if req.MonitorData == "" {
- br.Msg = "请输入预警值"
- return
- }
- req.EdbMonitorName = strings.TrimSpace(req.EdbMonitorName)
- if req.EdbMonitorName == "" {
- br.Msg = "请输入预警名称"
- return
- }
- msg, err := edbmonitor.SaveEdbMonitorInfo(req, sysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "编辑失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Msg = "编辑成功"
- br.Ret = 200
- br.Success = true
- }
- // delete
- // @Title 预警管理编辑
- // @Description 预警管理编辑
- // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
- // @Success 200 {object} models.EnglishReportEmailPageListResp
- // @router /delete [post]
- func (m *EdbMonitorController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.EdbMonitorInfoDeleteReq
- if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = err.Error()
- return
- }
- if req.EdbMonitorId <= 0 {
- br.Msg = "请选择指标"
- return
- }
- msg, err := edbmonitor.DeleteEdbMonitorInfo(req, sysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "删除失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Msg = "删除成功"
- br.Ret = 200
- br.Success = true
- }
- // Close
- // @Title 预警管理关闭
- // @Description 预警管理关闭
- // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
- // @Success 200 {object} models.EnglishReportEmailPageListResp
- // @router /close [post]
- func (m *EdbMonitorController) Close() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.EdbMonitorInfoCloseReq
- if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = err.Error()
- return
- }
- if req.EdbMonitorId <= 0 {
- br.Msg = "请选择预警"
- return
- }
- msg, err := edbmonitor.CloseEdbMonitorInfo(req, sysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "关闭失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Msg = "关闭成功"
- br.Ret = 200
- br.Success = true
- }
- // Restart
- // @Title 预警管理重启
- // @Description 预警管理重启
- // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
- // @Success 200 {object} models.EnglishReportEmailPageListResp
- // @router /restart [post]
- func (m *EdbMonitorController) Restart() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req request.EdbMonitorInfoRestartReq
- if err := json.Unmarshal(m.Ctx.Input.RequestBody, &req); err != nil {
- br.Msg = "参数解析失败"
- br.ErrMsg = err.Error()
- return
- }
- if req.EdbMonitorId <= 0 {
- br.Msg = "请选择预警"
- return
- }
- msg, err := edbmonitor.RestartEdbMonitorInfo(req, sysUser.AdminId)
- if err != nil {
- if msg == "" {
- msg = "重启失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Msg = "重启成功"
- br.Ret = 200
- br.Success = true
- }
- // GetMonitorLevel
- // @Title 预警管理等级列表
- // @Description 预警管理等级列表
- // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
- // @Success 200 {object} models.EnglishReportEmailPageListResp
- // @router /monitor_level/list [get]
- func (m *EdbMonitorController) GetMonitorLevel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- list, msg, err := edbmonitor.GetEdbMonitorLevelList()
- if err != nil {
- if msg == "" {
- msg = "获取预警等级失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Data = list
- br.Msg = "获取成功"
- br.Ret = 200
- br.Success = true
- }
- // GetMonitorUser
- // @Title 预警管理用户列表
- // @Description 预警管理用户列表
- // @Param request body request.EdbMonitorSaveRequest true "每页数据条数"
- // @Success 200 {object} models.EnglishReportEmailPageListResp
- // @router /monitor_user/list [get]
- func (m *EdbMonitorController) GetMonitorUser() {
- br := new(models.BaseResponse).Init()
- defer func() {
- m.Data["json"] = br
- m.ServeJSON()
- }()
- sysUser := m.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- resp, msg, err := edbmonitor.GetEdbMonitorInfoUserList()
- if err != nil {
- if msg == "" {
- msg = "获取用户列表失败"
- }
- br.Msg = msg
- br.ErrMsg = err.Error()
- return
- }
- br.Data = resp
- br.Msg = "获取成功"
- br.Ret = 200
- br.Success = true
- }
|