package data_manage import ( "hongze/hz_crm_api/utils" "time" ) // HandleDataByPreviousData 当前日期无值时,用上一个日期的数据补充当前日期的数据 func HandleDataByPreviousData(edbInfoDataList []*EdbDataList, handleDataMap map[string]float64) (err error) { if len(edbInfoDataList) < 2 { return } var startEdbInfoData *EdbDataList for _, v := range edbInfoDataList { handleDataMap[v.DataTime] = v.Value // 第一个数据就给过滤了,给后面的试用 if startEdbInfoData == nil { startEdbInfoData = v continue } // 获取两条数据之间相差的天数 startDataTime, _ := time.ParseInLocation(utils.FormatDate, startEdbInfoData.DataTime, time.Local) currDataTime, _ := time.ParseInLocation(utils.FormatDate, v.DataTime, time.Local) betweenHour := int(currDataTime.Sub(startDataTime).Hours()) betweenDay := betweenHour / 24 // 如果相差一天,那么过滤 if betweenDay <= 1 { startEdbInfoData = v continue } // 生成对应的值 { for i := 1; i < betweenDay; i++ { tmpDataTime := startDataTime.AddDate(0, 0, i) handleDataMap[tmpDataTime.Format(utils.FormatDate)] = startEdbInfoData.Value } } startEdbInfoData = v } return }