edb_info.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package open
  2. import (
  3. "encoding/json"
  4. "eta/eta_index_lib/controllers"
  5. "eta/eta_index_lib/models"
  6. "eta/eta_index_lib/utils"
  7. "fmt"
  8. )
  9. // EdbInfoController 指标数据
  10. type EdbInfoController struct {
  11. controllers.BaseAuthController
  12. }
  13. // Detail
  14. // @Title 指标详情接口
  15. // @Description 指标详情接口
  16. // @Success 200 {object} models.EdbInfoDetailReq
  17. // @router /edb/detail [post]
  18. func (this *EdbInfoController) Detail() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. var req models.EdbInfoDetailReq
  25. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  26. if err != nil {
  27. br.Msg = "参数解析异常!"
  28. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  29. return
  30. }
  31. if req.UniqueCode == "" {
  32. br.Msg = "请输入指标编码!"
  33. br.ErrMsg = "请输入指标编码,指标编码为空"
  34. return
  35. }
  36. edbInfo, err := models.GetEdbInfoByUniqueCode(req.UniqueCode)
  37. if err != nil {
  38. br.Msg = "获取失败"
  39. if err.Error() == utils.ErrNoRow() {
  40. br.Msg = "找不到该指标"
  41. }
  42. br.ErrMsg = "获取失败,ERR;" + err.Error()
  43. return
  44. }
  45. dataList := make([]*models.EdbInfoSearchData, 0)
  46. switch edbInfo.EdbInfoType {
  47. case 0:
  48. //获取来源指标的数据
  49. dataList, err = models.GetEdbDataListAll(edbInfo.Source, edbInfo.SubSource, models.FindEdbDataListAllCond{
  50. EdbInfoId: edbInfo.EdbInfoId,
  51. }, 1)
  52. case 1:
  53. dataList, err = models.GetPredictEdbDataListAllByStartDate(edbInfo, 1, "")
  54. default:
  55. br.Msg = "获取失败"
  56. br.ErrMsg = fmt.Sprint("获取失败,指标base类型异常", edbInfo.EdbInfoType)
  57. return
  58. }
  59. resp := models.EdbInfoDetailResp{
  60. SourceName: edbInfo.SourceName,
  61. EdbCode: edbInfo.EdbCode,
  62. EdbName: edbInfo.EdbName,
  63. EdbNameSource: edbInfo.EdbNameSource,
  64. Frequency: edbInfo.Frequency,
  65. Unit: edbInfo.Unit,
  66. StartDate: edbInfo.StartDate,
  67. EndDate: edbInfo.EndDate,
  68. UniqueCode: edbInfo.UniqueCode,
  69. CreateTime: edbInfo.CreateTime,
  70. ModifyTime: edbInfo.ModifyTime,
  71. MinValue: edbInfo.MinValue,
  72. MaxValue: edbInfo.MaxValue,
  73. EdbNameEn: edbInfo.EdbNameEn,
  74. UnitEn: edbInfo.UnitEn,
  75. LatestDate: edbInfo.LatestDate,
  76. LatestValue: edbInfo.LatestValue,
  77. ChartImage: edbInfo.ChartImage,
  78. DataList: dataList,
  79. }
  80. br.Data = resp
  81. br.Ret = 200
  82. br.Success = true
  83. br.Msg = "获取成功"
  84. }