Procházet zdrojové kódy

Merge branch '15.3' into debug

Roc před 1 rokem
rodič
revize
7c3491f77d

+ 1 - 0
models/chart.go

@@ -114,6 +114,7 @@ type EdbDataList struct {
 	Value         float64 `description:"数据值"`
 }
 
+// GetEdbDataList 获取指标的数据(日期正序返回)
 func GetEdbDataList(source, endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
 	tableName := GetEdbDataTableName(source)
 	if tableName == "" {

+ 1 - 1
models/request/excel_info.go

@@ -18,7 +18,7 @@ type EdbInfoData struct {
 }
 
 type ManualDataReq struct {
-	DataType            int               `description:"数据类型,1:普通的,2:插值法,3:手动输入,4:公式计算"`
+	DataType            int               `description:"数据类型,1:普通的,2:插值法,3:手动输入,4:公式计算,5:预测值"`
 	DataTime            string            `description:"所属日期"`
 	DataTimeType        int               `description:"日期类型,1:实际日期;2:未来日期"`
 	ShowValue           string            `description:"展示值"`

+ 53 - 7
services/data/excel_info.go

@@ -74,9 +74,17 @@ func GetFirstEdbDataList(edbInfo *data_manage.EdbInfo, num int, manualDateList [
 		num = lenData
 	}
 
+	latestDateTime, _ := time.ParseInLocation(utils.FormatDate, edbInfo.LatestDate, time.Local)
 	for i := 1; i <= num; i++ {
+		dataTime, _ := time.ParseInLocation(utils.FormatDate, dataList[lenData-i].DataTime, time.Local)
+		dataType := 1
+		// 如果是预测指标,且当前值的日期,晚于实际日期,那么是预测值
+		if edbInfo.EdbInfoType == 1 && dataTime.After(latestDateTime) {
+			dataType = 5
+		}
+
 		resultDataList = append(resultDataList, request.ManualDataReq{
-			DataType:     1,
+			DataType:     dataType,
 			DataTime:     dataList[lenData-i].DataTime,
 			ShowValue:    fmt.Sprint(dataList[lenData-i].Value),
 			Value:        fmt.Sprint(dataList[lenData-i].Value),
@@ -162,11 +170,19 @@ func GetOtherEdbDataList(edbInfo *data_manage.EdbInfo, dateList []string) (resul
 	if err != nil {
 		return
 	}
+
+	latestDateTime, _ := time.ParseInLocation(utils.FormatDate, edbInfo.LatestDate, time.Local)
 	// 对于不存在的数据做补充
 	for _, date := range sortDateList {
 		dataType := 1
 		if _, ok := realValMap[date]; !ok {
 			dataType = 2
+		} else {
+			dataTime, _ := time.ParseInLocation(utils.FormatDate, date, time.Local)
+			// 如果是预测指标,且当前值的日期,晚于实际日期,那么是预测值
+			if edbInfo.EdbInfoType == 1 && dataTime.After(latestDateTime) {
+				dataType = 5
+			}
 		}
 		var value, showValue string
 		if tmpVal, ok := handleDataMap[date]; ok {
@@ -223,9 +239,17 @@ func GetFirstHistoryEdbDataList(edbInfo *data_manage.EdbInfo, num int, endDate s
 		num = lenData
 	}
 
+	latestDateTime, _ := time.ParseInLocation(utils.FormatDate, edbInfo.LatestDate, time.Local)
 	for i := 1; i <= num; i++ {
+		dataTime, _ := time.ParseInLocation(utils.FormatDate, dataList[lenData-i].DataTime, time.Local)
+		dataType := 1
+		// 如果是预测指标,且当前值的日期,晚于实际日期,那么是预测值
+		if edbInfo.EdbInfoType == 1 && dataTime.After(latestDateTime) {
+			dataType = 5
+		}
+
 		resultDataList = append(resultDataList, request.ManualDataReq{
-			DataType:  1,
+			DataType:  dataType,
 			DataTime:  dataList[lenData-i].DataTime,
 			ShowValue: fmt.Sprint(dataList[lenData-i].Value),
 			Value:     fmt.Sprint(dataList[lenData-i].Value),
@@ -743,8 +767,8 @@ func handleTable(tagEdbInfoIdMap map[string]int, lastRealDateTime time.Time, sor
 			continue
 		}
 
-		// 如果该单元格实际有数据,或者插值法补充了数据的话,那么就不用手动填入的数据
-		if tmpData.DataType == 1 || tmpData.DataType == 2 {
+		// 如果该单元格实际有数据(包含预测值),或者插值法补充了数据的话,那么就不用手动填入的数据
+		if utils.InArrayByInt([]int{1, 2, 5}, tmpData.DataType) {
 			continue
 		}
 
@@ -1120,6 +1144,8 @@ func GetMixedTableCellData(config [][]request.MixedTableCellDataReq) (newMixedTa
 	edbInfoMap := make(map[int]*data_manage.EdbInfo)
 	// 指标数据map
 	edbDataListMap := make(map[int]map[string]float64)
+	// 月度指标数据map
+	edbMonthDataListMap := make(map[int]map[string]float64)
 	for _, edbInfo := range edbInfoList {
 		edbInfoMap[edbInfo.EdbInfoId] = edbInfo
 
@@ -1134,10 +1160,18 @@ func GetMixedTableCellData(config [][]request.MixedTableCellDataReq) (newMixedTa
 		}
 
 		dateValMap := make(map[string]float64)
+		monthValMap := make(map[string]float64)
 		for _, data := range dataList {
+			// 日度数据
 			dateValMap[data.DataTime] = data.Value
+			// 月度数据(取该月份的第一个数据)
+			yearMonth := strings.Join(strings.Split(data.DataTime, "-")[0:2], "-")
+			if _, ok := monthValMap[yearMonth]; !ok {
+				monthValMap[yearMonth] = data.Value
+			}
 		}
 		edbDataListMap[edbInfo.EdbInfoId] = dateValMap
+		edbMonthDataListMap[edbInfo.EdbInfoId] = monthValMap
 	}
 
 	for k, row := range newMixedTableCellDataList {
@@ -1147,10 +1181,22 @@ func GetMixedTableCellData(config [][]request.MixedTableCellDataReq) (newMixedTa
 					cell.ShowValue = edbInfo.EdbName
 				}
 			} else if cell.DataType == 4 {
-				if dateValMap, ok := edbDataListMap[cell.EdbInfoId]; ok {
-					if val, ok2 := dateValMap[cell.DataTime]; ok2 {
-						cell.ShowValue = fmt.Sprint(val)
+				tmpDateList := strings.Split(cell.DataTime, "-")
+				tmpDateValMap := make(map[string]float64)
+				if len(tmpDateList) == 2 {
+					//月度数据
+					if dateValMap, ok := edbMonthDataListMap[cell.EdbInfoId]; ok {
+						tmpDateValMap = dateValMap
 					}
+				} else {
+					// 日度数据
+					if dateValMap, ok := edbDataListMap[cell.EdbInfoId]; ok {
+						tmpDateValMap = dateValMap
+					}
+
+				}
+				if val, ok2 := tmpDateValMap[cell.DataTime]; ok2 {
+					cell.ShowValue = fmt.Sprint(val)
 				}
 			}
 

+ 2 - 2
services/data/predict_edb_info.go

@@ -82,7 +82,7 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
 	return
 }
 
-// GetPredictDataListByPredictEdbInfoId 根据预测指标id获取预测指标的数据
+// GetPredictDataListByPredictEdbInfoId 根据预测指标id获取预测指标的数据(日期正序返回)
 func GetPredictDataListByPredictEdbInfoId(edbInfoId int, startDate, endDate string, isTimeBetween bool) (edbInfo *data_manage.EdbInfo, dataList []*models.EdbDataList, sourceEdbInfoItem *data_manage.EdbInfo, predictEdbConf *data_manage.PredictEdbConf, err error, errMsg string) {
 	edbInfo, err = data_manage.GetEdbInfoById(edbInfoId)
 	if err != nil {
@@ -152,7 +152,7 @@ func GetPredictDataListByPredictEdbInfo(edbInfo *data_manage.EdbInfo, startDate,
 
 	endDateStr := edbInfo.EndDate //预测指标的结束日期
 
-	if isTimeBetween { //如果是时间区间,那么
+	if isTimeBetween && endDate != `` { //如果是时间区间,同时截止日期不为空的情况,那么
 		reqEndDateTime, _ := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
 		endDateTime, _ := time.ParseInLocation(utils.FormatDate, edbInfo.EndDate, time.Local)
 		// 如果选择的时间区间结束日期 晚于 当天,那么预测数据截止到当天