edb_info.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_data_push/models"
  5. "eta/eta_data_push/utils"
  6. )
  7. // 指标
  8. type EdbInfoController struct {
  9. BaseAuthController
  10. }
  11. // @Title 获取基础指标详情
  12. // @Description 获取基础指标详情
  13. // @Param request body models.EdbInfoDetailReq true "type json string"
  14. // @Success 200 {object} models.EdbInfo
  15. // @router /detail [post]
  16. func (this *EdbInfoController) EdbIndexDetail() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. var req models.EdbInfoDetailReq
  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.EdbCode == "" {
  30. br.Msg = "请输入指标编码!"
  31. return
  32. }
  33. detail, err := models.GetEdbInfoByEdbCode(req.EdbCode)
  34. if err != nil {
  35. br.Msg = "获取数据失败!"
  36. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  37. return
  38. }
  39. calculateList, err := models.GetEdbInfoCalculateMapping(req.EdbCode)
  40. if err != nil && err.Error() != utils.ErrNoRow() {
  41. br.Msg = "获取数据失败!"
  42. br.ErrMsg = "获取计算指标失败,Err:" + err.Error()
  43. return
  44. }
  45. for _, v := range calculateList {
  46. baseEdbInfoList, err := models.GetEdbInfoCalculateBaseEdbInfo(v.EdbCode)
  47. if err != nil && err.Error() != utils.ErrNoRow() {
  48. br.Msg = "获取数据失败!"
  49. br.ErrMsg = "获取计算指标所依赖的基础指标编码失败,Err:" + err.Error()
  50. return
  51. }
  52. v.BaseEdbInfoCode = baseEdbInfoList
  53. }
  54. detail.CalculateList = calculateList
  55. br.Ret = 200
  56. br.Success = true
  57. br.Msg = "获取成功"
  58. br.Data = detail
  59. }
  60. // @Title 获取指标信息
  61. // @Description 获取指标信息
  62. // @Param request body models.EdbInfoDetailReq true "type json string"
  63. // @Success 200 {object} models.EdbInfo
  64. // @router /item [post]
  65. func (this *EdbInfoController) EdbIndexItem() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. this.Data["json"] = br
  69. this.ServeJSON()
  70. }()
  71. var req models.EdbInfoDetailReq
  72. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  73. if err != nil {
  74. br.Msg = "参数解析异常!"
  75. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  76. return
  77. }
  78. if req.EdbCode == "" {
  79. br.Msg = "请输入指标编码!"
  80. return
  81. }
  82. item, err := models.GetEdbInfoItemByEdbCode(req.EdbCode)
  83. if err != nil {
  84. br.Msg = "获取数据失败!"
  85. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  86. return
  87. }
  88. br.Ret = 200
  89. br.Success = true
  90. br.Msg = "获取成功"
  91. br.Data = item
  92. }