edb_info.go 2.2 KB

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