edb_data.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package services
  2. import (
  3. "eta/eta_forum_admin/models"
  4. "eta/eta_forum_admin/models/mgodb"
  5. "eta/eta_forum_admin/utils"
  6. "fmt"
  7. "time"
  8. )
  9. // GetEdbDataList 获取指标的数据(日期正序返回)
  10. func GetEdbDataList(endInfoId, edbType int, startDate, endDate string) (list []*models.EdbDataList, err error) {
  11. dataList := make([]*mgodb.EdbDataBase, 0)
  12. var startDateT, endDateT time.Time
  13. if startDate != "" {
  14. startDateT, err = time.Parse(utils.FormatDate, startDate)
  15. if err != nil {
  16. err = fmt.Errorf("日期格式错误 error, %v", err)
  17. return
  18. }
  19. }
  20. if endDate != "" {
  21. endDateT, err = time.Parse(utils.FormatDate, endDate)
  22. if err != nil {
  23. err = fmt.Errorf("日期格式错误 error, %v", err)
  24. return
  25. }
  26. }
  27. if edbType == 1 {
  28. dataList, err = mgodb.GetEdbDataList(endInfoId, startDateT, endDateT)
  29. if err != nil {
  30. err = fmt.Errorf("查询指标数据出错 error, %v", err)
  31. return
  32. }
  33. } else {
  34. dataList, err = mgodb.GetEdbCalculateDataList(endInfoId, startDateT, endDateT)
  35. if err != nil {
  36. err = fmt.Errorf("查询指标数据出错 error, %v", err)
  37. return
  38. }
  39. }
  40. list = make([]*models.EdbDataList, 0)
  41. for _, v := range dataList {
  42. // 字符串转成浮点数
  43. list = append(list, &models.EdbDataList{
  44. EdbInfoId: v.EdbInfoId,
  45. DataTime: v.DataTime.Format(utils.FormatDate),
  46. DataTimestamp: v.DataTimestamp,
  47. Value: v.Value,
  48. },
  49. )
  50. }
  51. return
  52. }