Sfoglia il codice sorgente

Merge branch 'hotfix/239_chart_series' of hongze/hongze_yb into master

xyxie 4 mesi fa
parent
commit
a4bef72959

+ 2 - 1
models/response/chart_info/chart_info.go

@@ -122,7 +122,8 @@ type ChartSectionDateConfItem struct {
 	EdbInfoType    int    `description:"指标类型"`
 	Frequency      string `description:"频度"`
 	EndDate        string `description:"最新日期"`
-	DateType       int    `description:"日期类型:0 指标日期,1系统日期"`
+	StaticDate     string `description:"固定日期"`
+	DateType       int    `description:"日期类型:0 指标日期,1系统日期, 2固定日期"`
 	DateConfName   string `description:"引用日期名称"` // 引用日期名称不能重复
 	DateConfNameEn string `description:"引用日期英文名称"`
 	DateChange     []*ChartSectionDateChange

+ 54 - 24
services/chart/chart_extra_config.go

@@ -105,18 +105,34 @@ func GetChartSectionCombineData(chartInfo *chart_info.ChartInfo, mappingList []*
 				}
 				// todo 根据日期变换得到最终日期
 				edbDataListTmp := make([]*edbDataModel.EdbDataList, 0)
-				if dateConfItem.EdbInfoId > 0 {
-					edbDataListTmp, ok1 = edbDataListMap[dateConfItem.EdbInfoId]
-					if !ok1 {
-						err = fmt.Errorf("指标%d的日期数据不存在", dateConfItem.EdbInfoId)
+				if dateConfItem.DateType == 0 {
+					if dateConfItem.EdbInfoId > 0 {
+						edbDataListTmp, ok1 = edbDataListMap[dateConfItem.EdbInfoId]
+						if !ok1 {
+							err = fmt.Errorf("指标%d的日期数据不存在", dateConfItem.EdbInfoId)
+							return
+						}
+						findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
+						if err != nil {
+							err = fmt.Errorf("指标%d的日期变换处理失败", dateConfItem.EdbInfoId)
+							return
+						}
+					} else {
+						err = fmt.Errorf("请选择指标")
 						return
 					}
-				}
-
-				findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
-				if err != nil {
-					err = fmt.Errorf("指标%d的日期变换处理失败", dateConfItem.EdbInfoId)
-					return
+				} else if dateConfItem.DateType == 1 {
+					findDate, err = GetChartSectionSeriesDateByDateChange(dateConfItem.EdbInfoId, edbDataListTmp, dateConfItem.DateChange, dateConfItem.MoveForward)
+					if err != nil {
+						err = fmt.Errorf("指标%d的日期变换处理失败", dateConfItem.EdbInfoId)
+						return
+					}
+				} else if dateConfItem.DateType == 2 {
+					if dateConfItem.StaticDate == "" {
+						err = fmt.Errorf("请输入固定日期")
+						return
+					}
+					findDate = dateConfItem.StaticDate
 				}
 			}
 			findDateTime, _ := time.ParseInLocation(utils.FormatDate, findDate, time.Local)
@@ -202,9 +218,26 @@ func GetChartSectionCombineData(chartInfo *chart_info.ChartInfo, mappingList []*
 		err = fmt.Errorf("基准系列不存在")
 		return
 	}
+	defaultIndexXDataList := make([]int, 0)            //默认排序时的横轴
+	defaultXDataMap := make(map[int]chart_info2.XData) //默认排序时的横轴单位
+	for index, item := range baseSeries.EdbInfoList {
+		if index == 0 {
+			firstUnit = &chart_info2.XData{
+				Name:   item.Unit,
+				NameEn: item.UnitEn,
+			}
+		}
+
+		tmp := chart_info2.XData{
+			Name:   item.EdbName,
+			NameEn: item.EdbNameEn,
+		}
+		defaultXDataMap[index] = tmp
+		defaultIndexXDataList = append(defaultIndexXDataList, index)
+	}
 	// 处理系列排序
 	if extraConfig.SortType > 0 {
-		newSeriesDataListMap, newSeriesNoDataIndexMap := SortChartSeriesDataSet(baseSeries.SeriesName, baseSeries.DataList, baseSeries.NoDataEdbIndex, seriesDataListMap, seriesNoDataIndexMap, extraConfig.SortType)
+		newSeriesDataListMap, newSeriesNoDataIndexMap, newIndexXDataList := SortChartSeriesDataSet(baseSeries.SeriesName, baseSeries.DataList, baseSeries.NoDataEdbIndex, seriesDataListMap, seriesNoDataIndexMap, extraConfig.SortType)
 		for k, item := range extraConfig.SeriesList {
 			dataList, ok := newSeriesDataListMap[item.SeriesName]
 			if ok {
@@ -215,28 +248,24 @@ func GetChartSectionCombineData(chartInfo *chart_info.ChartInfo, mappingList []*
 				extraConfig.SeriesList[k].NoDataEdbIndex = noIndex
 			}
 		}
+		defaultIndexXDataList = newIndexXDataList
 	}
 
 	xDataList := make([]chart_info2.XData, 0)
-	for index, item := range baseSeries.EdbInfoList {
-		if index == 0 {
-			firstUnit = &chart_info2.XData{
-				Name:   item.Unit,
-				NameEn: item.UnitEn,
-			}
-		}
-		tmp := chart_info2.XData{
-			Name:   item.EdbName,
-			NameEn: item.EdbNameEn,
+	for index, itemIndex := range defaultIndexXDataList {
+		nameItem, ok := defaultXDataMap[itemIndex]
+		if !ok {
+			err = fmt.Errorf("单位不存在")
+			return
 		}
 		// 如果已经设置了横轴名称,则用设置的名称替换
 		if len(extraConfig.XDataList) > index {
 			newItem := extraConfig.XDataList[index]
 			if newItem.Name != "" {
-				tmp = newItem
+				nameItem = newItem
 			}
 		}
-		xDataList = append(xDataList, tmp)
+		xDataList = append(xDataList, nameItem)
 	}
 	dataListResp.XDataList = xDataList
 
@@ -524,7 +553,7 @@ func handleSystemAppointDateT(currDate time.Time, appointDay, frequency string)
 }
 
 // sortTripleDataSet 以第一组数据为基准,排序之后,空数组的位置也要同步变更
-func SortChartSeriesDataSet(baseName string, baseDataList []float64, baseSeriesNoDataIndexList []int, dataListMap map[string][]float64, noDataListIndexMap map[string][]int, asc int) (newDataListMap map[string][]float64, newNoDataListIndexMap map[string][]int) {
+func SortChartSeriesDataSet(baseName string, baseDataList []float64, baseSeriesNoDataIndexList []int, dataListMap map[string][]float64, noDataListIndexMap map[string][]int, asc int) (newDataListMap map[string][]float64, newNoDataListIndexMap map[string][]int, newIndexXDataList []int) {
 	newDataListMap = make(map[string][]float64)
 	newNoDataListIndexMap = make(map[string][]int)
 
@@ -614,5 +643,6 @@ func SortChartSeriesDataSet(baseName string, baseDataList []float64, baseSeriesN
 			newDataListMap[k][i] = dataListMap[k][idx]
 		}
 	}
+	newIndexXDataList = newIndices
 	return
 }