|
@@ -12,7 +12,8 @@ import (
|
|
|
|
|
|
type InterpolateStrategy struct{}
|
|
|
|
|
|
-func (i *InterpolateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList) (err error) {
|
|
|
+// Deal 空值填充:插值法填充
|
|
|
+func (i *InterpolateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList, startDate string, endDate string) (err error) {
|
|
|
for _, v := range edbDataList {
|
|
|
if v.EdbInfoId != tmpConfig.StandardEdbInfoId {
|
|
|
if dataList, ok := v.DataList.([]*data_manage.EdbDataList); ok {
|
|
@@ -108,11 +109,44 @@ func (i *InterpolateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataL
|
|
|
|
|
|
type FillWithPreviousStrategy struct{}
|
|
|
|
|
|
-func (f *FillWithPreviousStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList) (err error) {
|
|
|
+// Deal 空值填充:前值填充
|
|
|
+func (f *FillWithPreviousStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList, startDate string, endDate string) (err error) {
|
|
|
// 按自然日补充,再根据基准指标取对应数据
|
|
|
for _, v := range edbDataList {
|
|
|
if v.EdbInfoId != tmpConfig.StandardEdbInfoId {
|
|
|
if dataList, ok := v.DataList.([]*data_manage.EdbDataList); ok {
|
|
|
+ // 存放补充数据
|
|
|
+ var replenishDataList []*data_manage.EdbDataList
|
|
|
+
|
|
|
+ // 处理从 startDate 到第一个数据的日期补充
|
|
|
+ if len(dataList) > 0 {
|
|
|
+ firstData := dataList[0]
|
|
|
+ // 将 startDate 到第一个数据日期之间的自然日填充补充数据,值为 0
|
|
|
+ startDataTime, _ := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
|
|
|
+ firstDataTime, _ := time.ParseInLocation(utils.FormatDate, firstData.DataTime, time.Local)
|
|
|
+
|
|
|
+ // 计算两个日期之间的天数差
|
|
|
+ for startDataTime.Before(firstDataTime) {
|
|
|
+ // 补充数据
|
|
|
+ nextDay := startDataTime.Format(utils.FormatDate)
|
|
|
+
|
|
|
+ // 生成补充数据,值为 0
|
|
|
+ replenishIndexData := data_manage.EdbDataList{
|
|
|
+ EdbInfoId: v.EdbInfoId,
|
|
|
+ DataTime: nextDay,
|
|
|
+ DataTimestamp: startDataTime.UnixMilli(),
|
|
|
+ Value: 0,
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将补充数据加入补充数据列表
|
|
|
+ replenishDataList = append(replenishDataList, &replenishIndexData)
|
|
|
+
|
|
|
+ // 更新 startDataTime 到下一个日期
|
|
|
+ startDataTime = startDataTime.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理指标中空值数据
|
|
|
for index := 0; index < len(dataList)-1; index++ {
|
|
|
// 获取当前数据和下一个数据
|
|
|
beforeIndexData := dataList[index]
|
|
@@ -121,6 +155,7 @@ func (f *FillWithPreviousStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edb
|
|
|
for utils.IsMoreThanOneDay(beforeIndexData.DataTime, afterIndexData.DataTime) {
|
|
|
// 创建补充数据
|
|
|
nextDay := utils.GetNextDay(beforeIndexData.DataTime)
|
|
|
+
|
|
|
toTime := utils.StringToTime(nextDay)
|
|
|
replenishIndexData := data_manage.EdbDataList{
|
|
|
EdbInfoId: v.EdbInfoId,
|
|
@@ -130,13 +165,47 @@ func (f *FillWithPreviousStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edb
|
|
|
}
|
|
|
|
|
|
// 将补充数据加入补充数据列表
|
|
|
- dataList = append(dataList[:index+1], append([]*data_manage.EdbDataList{&replenishIndexData}, dataList[index+1:]...)...)
|
|
|
+ replenishDataList = append(replenishDataList, &replenishIndexData)
|
|
|
+ //dataList = append(dataList[:index+1], append([]*data_manage.EdbDataList{&replenishIndexData}, dataList[index+1:]...)...)
|
|
|
|
|
|
// 更新 beforeIndexData 为新创建的补充数据
|
|
|
beforeIndexData = &replenishIndexData
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 处理从最后一个数据到 endDate 的日期补充
|
|
|
+ if len(dataList) > 0 {
|
|
|
+ lastData := dataList[len(dataList)-1]
|
|
|
+ // 将最后一个数据日期到 endDate 之间的自然日填充补充数据,值为 0
|
|
|
+ lastDataTime, _ := time.ParseInLocation(utils.FormatDate, lastData.DataTime, time.Local)
|
|
|
+ endDataTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
|
|
|
+
|
|
|
+ // 如果 lastDataTime 不等于 endDate,进行补充
|
|
|
+ if !lastDataTime.Equal(endDataTime) {
|
|
|
+ // 补充数据直到 endDate
|
|
|
+ for !lastDataTime.After(endDataTime) {
|
|
|
+ // 补充数据
|
|
|
+ nextDay := lastDataTime.Format(utils.FormatDate)
|
|
|
+
|
|
|
+ // 生成补充数据,值为 0
|
|
|
+ replenishIndexData := data_manage.EdbDataList{
|
|
|
+ EdbInfoId: v.EdbInfoId,
|
|
|
+ DataTime: nextDay,
|
|
|
+ DataTimestamp: lastDataTime.UnixMilli(),
|
|
|
+ Value: 0,
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将补充数据加入补充数据列表
|
|
|
+ replenishDataList = append(replenishDataList, &replenishIndexData)
|
|
|
+
|
|
|
+ // 更新 lastDataTime 到下一个日期
|
|
|
+ lastDataTime = lastDataTime.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dataList = append(dataList, replenishDataList...)
|
|
|
+
|
|
|
// 根据基准指标筛选出符合数据
|
|
|
var resultDataList []*data_manage.EdbDataList
|
|
|
for _, dataObject := range dataList {
|
|
@@ -161,7 +230,8 @@ func (f *FillWithPreviousStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edb
|
|
|
|
|
|
type FillWithNextStrategy struct{}
|
|
|
|
|
|
-func (f *FillWithNextStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList) (err error) {
|
|
|
+// Deal 空值填充:后值填充
|
|
|
+func (f *FillWithNextStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList, startDate string, endDate string) (err error) {
|
|
|
// 按自然日补充,再根据基准指标取对应数据
|
|
|
for _, v := range edbDataList {
|
|
|
if v.EdbInfoId != tmpConfig.StandardEdbInfoId {
|
|
@@ -217,7 +287,8 @@ func (f *FillWithNextStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbData
|
|
|
|
|
|
type SetToZeroStrategy struct{}
|
|
|
|
|
|
-func (s *SetToZeroStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList) (err error) {
|
|
|
+// Deal 空值填充:设为0
|
|
|
+func (s *SetToZeroStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList, startDate string, endDate string) (err error) {
|
|
|
// 按自然日补充,再根据基准指标取对应数据
|
|
|
for _, v := range edbDataList {
|
|
|
if v.EdbInfoId != tmpConfig.StandardEdbInfoId {
|
|
@@ -270,7 +341,8 @@ func (s *SetToZeroStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataLis
|
|
|
|
|
|
type DeleteDateStrategy struct{}
|
|
|
|
|
|
-func (d *DeleteDateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList) error {
|
|
|
+// Deal 删除日期
|
|
|
+func (d *DeleteDateStrategy) Deal(tmpConfig data_manage.AreaExtraConf, edbDataList []*data_manage.ChartEdbInfoMapping, standardIndexMap map[string]*data_manage.EdbDataList, startDate string, endDate string) error {
|
|
|
// 取所有指标的时间交集
|
|
|
for _, v := range edbDataList {
|
|
|
if dataList, ok := v.DataList.([]*data_manage.EdbDataList); ok {
|