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 }