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 EdbMonitorClassifyController struct { controllers.BaseAuthController } // List // @Title 预警管理分类列表 // @Description 预警管理分类列表 // @Success 200 {object} response.EdbMonitorClassifyTree // @router /classify/list [get] func (c *EdbMonitorClassifyController) List() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } resp, msg, err := edbmonitor.GetEdbMonitorClassifyTree() 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 /classify/add [post] func (c *EdbMonitorClassifyController) Add() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.EdbMonitorClassifySaveReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = err.Error() return } req.ClassifyName = strings.TrimSpace(req.ClassifyName) if req.ClassifyName == "" { br.Msg = "分类名称不能为空" return } if req.Level <= 0 || req.ClassifyId > 0 { br.Msg = "参数错误" return } msg, err := edbmonitor.SaveEdbMonitorClassify(req) 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 "每页数据条数" // @router /classify/edit [post] func (c *EdbMonitorClassifyController) Edit() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.EdbMonitorClassifySaveReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = err.Error() return } if req.ClassifyId <= 0 { br.Msg = "分类不存在,请刷新页面" return } req.ClassifyName = strings.TrimSpace(req.ClassifyName) if req.ClassifyName == "" { br.Msg = "分类名称不能为空" return } if req.Level <= 0 { br.Msg = "参数错误" return } msg, err := edbmonitor.SaveEdbMonitorClassify(req) 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 "每页数据条数" // @router /classify/delete [post] func (c *EdbMonitorClassifyController) Delete() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() sysUser := c.SysUser if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req request.EdbMonitorClassifyDeleteReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = err.Error() return } if req.ClassifyId <= 0 { br.Msg = "分类不存在,请刷新页面" return } msg, err := edbmonitor.DeleteEdbMonitorClassify(req) if err != nil { if msg == "" { msg = "分类删除失败" } br.Msg = msg br.ErrMsg = err.Error() return } br.Msg = "分类删除成功" br.Ret = 200 br.Success = true } // Move // @Title 预警分类移动接口 // @Description 预警分类移动接口 // @Param request body request.MoveEdbMonitorClassifyReq true "每页数据条数" // @router /classify/move [post] func (c *EdbMonitorClassifyController) Move() { br := new(models.BaseResponse).Init() defer func() { c.Data["json"] = br c.ServeJSON() }() var req request.MoveEdbMonitorClassifyReq if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil { br.Msg = "参数解析失败" br.ErrMsg = err.Error() return } if req.ClassifyId <= 0 { br.Msg = "参数错误" br.ErrMsg = "分类id小于等于0" return } msg, err := edbmonitor.MoveEdbMonitorClassify(req) if err != nil { if msg == "" { msg = "分类移动失败" } br.Msg = msg br.ErrMsg = err.Error() return } br.Msg = "分类移动成功" br.Ret = 200 br.Success = true }