edb_classify.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_index_lib/models"
  5. "eta/eta_index_lib/utils"
  6. )
  7. // 指标分类
  8. type EdbClassifyController struct {
  9. BaseAuthController
  10. }
  11. // @Title 查询/新增分类
  12. // @Description 查询/新增分类接口
  13. // @Param request body models.AddEdbClassifyReq true "type json string"
  14. // @Success 200 {object} models.EdbClassify
  15. // @router /get_or_add [post]
  16. func (this *EdbClassifyController) GetOrAdd() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. var req models.AddEdbClassifyReq
  23. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  24. if err != nil {
  25. br.Msg = "参数解析异常!"
  26. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  27. return
  28. }
  29. if req.ClassifyName == "" {
  30. br.Msg = "请输入分类名称"
  31. br.IsSendEmail = false
  32. return
  33. }
  34. if req.ParentId < 0 {
  35. br.Msg = "参数错误"
  36. br.IsSendEmail = false
  37. return
  38. }
  39. //添加指标
  40. edbClassify, err, errMsg := models.SaveEdbClassify(req.ClassifyName, req.ParentId, req.Level, req.ClassifyType, utils.InitAdminId, utils.InitAdminName)
  41. if errMsg != `` {
  42. br.Msg = errMsg
  43. br.ErrMsg = errMsg
  44. if err != nil {
  45. br.ErrMsg = errMsg + ";Err:" + err.Error()
  46. } else {
  47. br.IsSendEmail = false
  48. }
  49. return
  50. }
  51. br.Ret = 200
  52. br.Msg = "保存成功"
  53. br.Success = true
  54. br.Data = edbClassify
  55. }