edb.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package controllers
  2. import (
  3. "hongze/hongze_open_api/models/response/edb"
  4. "hongze/hongze_open_api/services/edb_data"
  5. )
  6. // EdbController 指标模块
  7. type EdbController struct {
  8. BaseAuth
  9. }
  10. // Detail
  11. // @Title 获取指标详情
  12. // @Description 图表变更通知的插入点接口
  13. // @Param unique_code query string true "指标唯一编码"
  14. // @Param request body chart.CreatChartCeluePushReq true "type json string"
  15. // @Success 200 创建成功
  16. // @router /detail [get]
  17. func (c *EdbController) Detail() {
  18. uniqueCode := c.GetString("unique_code")
  19. if uniqueCode == `` {
  20. c.FailWithMessage("指标编码必传")
  21. return
  22. }
  23. edbInfoDetail, err, errMsg := edb_data.EdbDetail(uniqueCode)
  24. if err != nil {
  25. if errMsg == `` {
  26. errMsg = "获取失败"
  27. }
  28. c.FailWithMessage(errMsg)
  29. return
  30. }
  31. dataList := make([]edb.EdbInfoSearchData, 0)
  32. if edbInfoDetail.DataList != nil && len(edbInfoDetail.DataList) > 0 {
  33. for _, data := range edbInfoDetail.DataList {
  34. dataList = append(dataList, edb.EdbInfoSearchData{
  35. DataTime: data.DataTime,
  36. Value: data.Value,
  37. })
  38. }
  39. }
  40. resp := edb.EdbInfoDetailResp{
  41. SourceName: edbInfoDetail.SourceName,
  42. EdbCode: edbInfoDetail.EdbCode,
  43. EdbName: edbInfoDetail.EdbName,
  44. Frequency: edbInfoDetail.Frequency,
  45. Unit: edbInfoDetail.Unit,
  46. StartDate: edbInfoDetail.StartDate,
  47. EndDate: edbInfoDetail.EndDate,
  48. UniqueCode: edbInfoDetail.UniqueCode,
  49. MinValue: edbInfoDetail.MinValue,
  50. MaxValue: edbInfoDetail.MaxValue,
  51. EdbNameEn: edbInfoDetail.EdbNameEn,
  52. UnitEn: edbInfoDetail.UnitEn,
  53. LatestDate: edbInfoDetail.LatestDate,
  54. LatestValue: edbInfoDetail.LatestValue,
  55. ChartImage: edbInfoDetail.ChartImage,
  56. DataList: dataList,
  57. }
  58. c.OkDetailed(resp, "获取成功")
  59. }