handle_data.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package data_manage
  2. import (
  3. "hongze/hz_crm_api/utils"
  4. "time"
  5. )
  6. // HandleDataByPreviousData 当前日期无值时,用上一个日期的数据补充当前日期的数据
  7. func HandleDataByPreviousData(edbInfoDataList []*EdbDataList, handleDataMap map[string]float64) (err error) {
  8. if len(edbInfoDataList) < 2 {
  9. return
  10. }
  11. var startEdbInfoData *EdbDataList
  12. for _, v := range edbInfoDataList {
  13. handleDataMap[v.DataTime] = v.Value
  14. // 第一个数据就给过滤了,给后面的试用
  15. if startEdbInfoData == nil {
  16. startEdbInfoData = v
  17. continue
  18. }
  19. // 获取两条数据之间相差的天数
  20. startDataTime, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local)
  21. currDataTime, _ := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local)
  22. betweenHour := int(currDataTime.Sub(startDataTime).Hours())
  23. betweenDay := betweenHour / 24
  24. // 如果相差一天,那么过滤
  25. if betweenDay <= 1 {
  26. startEdbInfoData = v
  27. continue
  28. }
  29. // 生成对应的值
  30. {
  31. for i := 1; i < betweenDay; i++ {
  32. tmpDataTime := startDataTime.AddDate(0, 0, i)
  33. handleDataMap[tmpDataTime.Format(utils.FormatDate)] = startEdbInfoData.Value
  34. }
  35. }
  36. startEdbInfoData = v
  37. }
  38. return
  39. }