predict_edb_info.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. edbInfoModel "hongze/hongze_yb/models/tables/edb_info"
  7. "hongze/hongze_yb/services/chart"
  8. "hongze/hongze_yb/utils"
  9. "strconv"
  10. "time"
  11. )
  12. // PredictEdbData 预测指标数据
  13. func PredictEdbData(c *gin.Context) {
  14. var req request.PredictEdbInfoDataReq
  15. if err := c.Bind(&req); err != nil {
  16. response.Fail("参数有误", c)
  17. return
  18. }
  19. if req.EdbInfoId <= 0 {
  20. response.Fail("参数错误", c)
  21. return
  22. }
  23. if req.DateType <= 0 {
  24. req.DateType = 3
  25. }
  26. if req.EdbInfoType <= 0 {
  27. req.EdbInfoType = 1
  28. }
  29. if req.ChartType <= 0 {
  30. req.ChartType = 1
  31. }
  32. if req.Calendar == "" {
  33. req.Calendar = "公历"
  34. }
  35. isTimeBetween := false //是否是时间区间
  36. if req.ChartType == 2 {
  37. req.DateType = 0
  38. isTimeBetween = true
  39. }
  40. if req.DateType == 5 {
  41. isTimeBetween = true
  42. }
  43. edbInfo, e := edbInfoModel.GetEdbInfoById(req.EdbInfoId)
  44. if e != nil {
  45. if e == utils.ErrNoRow {
  46. response.FailMsg("获取失败", "指标不存在,EdbInfoId:"+strconv.Itoa(req.EdbInfoId), c)
  47. return
  48. }
  49. response.FailMsg("获取失败", "获取指标信息失败,Err:"+e.Error(), c)
  50. return
  51. }
  52. startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, edbInfo.LatestDate)
  53. if endDate == "" {
  54. endDate = time.Now().Format(utils.FormatDate)
  55. }
  56. if req.DateType == 10 {
  57. startDate = ""
  58. endDate = ""
  59. }
  60. dataList, _, _, e, _ := chart.GetPredictDataListByPredictEdbInfo(edbInfo, startDate, endDate, isTimeBetween)
  61. if e != nil {
  62. response.FailMsg("获取失败", "获取预测指标数据失败, Err: "+e.Error(), c)
  63. return
  64. }
  65. // 季节性图、公历、农历处理
  66. resultDataList, err := chart.GetChartDataList(dataList, req.ChartType, req.Calendar, edbInfo.LatestDate.Format(utils.FormatDate), startDate)
  67. if err != nil {
  68. response.FailMsg("获取失败", "季节性图、公历、农历处理失败, Err: "+e.Error(), c)
  69. return
  70. }
  71. type PredictEdbInfoDataResp struct {
  72. EdbInfo *edbInfoModel.EdbInfo
  73. DataList interface{}
  74. }
  75. resp := new(PredictEdbInfoDataResp)
  76. resp.EdbInfo = edbInfo
  77. resp.DataList = resultDataList
  78. response.OkData("获取成功", resp, c)
  79. }