edb_info.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package edb_info
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/models/request"
  6. "hongze/hongze_yb/models/tables/edb_data"
  7. edbInfoModel "hongze/hongze_yb/models/tables/edb_info"
  8. "hongze/hongze_yb/utils"
  9. "strconv"
  10. )
  11. // EdbData 指标数据
  12. func EdbData(c *gin.Context) {
  13. var req request.EdbInfoDataReq
  14. if err := c.Bind(&req); err != nil {
  15. response.Fail("参数有误", c)
  16. return
  17. }
  18. if req.EdbInfoId <= 0 {
  19. response.Fail("参数错误", c)
  20. return
  21. }
  22. if req.DateType <= 0 {
  23. req.DateType = 3
  24. }
  25. if req.EdbInfoType <= 0 {
  26. req.EdbInfoType = 1
  27. }
  28. edbInfo, e := edbInfoModel.GetEdbInfoById(req.EdbInfoId)
  29. if e != nil {
  30. if e == utils.ErrNoRow {
  31. response.FailMsg("获取失败", "指标不存在,EdbInfoId:"+strconv.Itoa(req.EdbInfoId), c)
  32. return
  33. }
  34. response.FailMsg("获取失败", "获取指标信息失败,Err:"+e.Error(), c)
  35. return
  36. }
  37. maxYear := 0
  38. if !edbInfo.LatestDate.IsZero() {
  39. maxYear = edbInfo.LatestDate.Year()
  40. }
  41. dataList := make([]*edb_data.EdbDataList, 0)
  42. startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, maxYear)
  43. dataList, e = edb_data.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, req.EdbInfoId, startDate, endDate)
  44. if e != nil {
  45. response.FailMsg("获取失败", "获取指标数据失败, Err: "+e.Error(), c)
  46. return
  47. }
  48. type EdbInfoDataFullClassifyResp struct {
  49. EdbInfo *edbInfoModel.EdbInfo
  50. DataList []*edb_data.EdbDataList
  51. }
  52. resp := new(EdbInfoDataFullClassifyResp)
  53. resp.EdbInfo = edbInfo
  54. resp.DataList = dataList
  55. response.OkData("获取成功", resp, c)
  56. }