123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- 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
- }
|