فهرست منبع

Merge branch 'feature/eta1.9.6_chart_series' of eta_forum/eta_forum_admin into master

xyxie 6 ماه پیش
والد
کامیت
c55b913085
2فایلهای تغییر یافته به همراه71 افزوده شده و 30 حذف شده
  1. 14 3
      models/chart_info.go
  2. 57 27
      services/chart_extra_config.go

+ 14 - 3
models/chart_info.go

@@ -2214,10 +2214,21 @@ 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     []*EdbDateConfDateChange
+	DateChange     []*ChartSectionDateChange
+}
+
+// 截面组合图引用日期配置
+type ChartSectionDateChange struct {
+	Year         int
+	Month        int
+	Day          int
+	Frequency    string `description:"频度变换"`
+	FrequencyDay string `description:"频度的固定日期"`
+	ChangeType   int    `description:"日期变换类型1日期位移,2指定频率"`
 }
 
 type MarkersLine struct {
@@ -2320,7 +2331,7 @@ type ChartSectionCombineDataResp struct {
 // 系列里的指标日期配置
 type ChartSectionSeriesDateConfItem struct {
 	MoveForward int `description:"前移的期数"`
-	DateChange  []*EdbDateConfDateChange
+	DateChange  []*ChartSectionDateChange
 }
 
 // PreviewSectionCombineChartReq 预览截面组合图的请求

+ 57 - 27
services/chart_extra_config.go

@@ -102,18 +102,34 @@ func GetChartSectionCombineData(chartInfo *models.ChartInfo, mappingList []*mode
 				}
 				// todo 根据日期变换得到最终日期
 				edbDataListTmp := make([]*models.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)
@@ -199,9 +215,26 @@ func GetChartSectionCombineData(chartInfo *models.ChartInfo, mappingList []*mode
 		err = fmt.Errorf("基准系列不存在")
 		return
 	}
+	defaultIndexXDataList := make([]int, 0)       //默认排序时的横轴
+	defaultXDataMap := make(map[int]models.XData) //默认排序时的横轴单位
+	for index, item := range baseSeries.EdbInfoList {
+		if index == 0 {
+			firstUnit = &models.XData{
+				Name:   item.Unit,
+				NameEn: item.UnitEn,
+			}
+		}
+
+		tmp := models.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 {
@@ -212,28 +245,24 @@ func GetChartSectionCombineData(chartInfo *models.ChartInfo, mappingList []*mode
 				extraConfig.SeriesList[k].NoDataEdbIndex = noIndex
 			}
 		}
+		defaultIndexXDataList = newIndexXDataList
 	}
 
 	xDataList := make([]models.XData, 0)
-	for index, item := range baseSeries.EdbInfoList {
-		if index == 0 {
-			firstUnit = &models.XData{
-				Name:   item.Unit,
-				NameEn: item.UnitEn,
-			}
-		}
-		tmp := models.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
 
@@ -308,7 +337,6 @@ func GetChartSectionCombineData(chartInfo *models.ChartInfo, mappingList []*mode
 					extraConfig.DateConfList[i].Frequency = edbItem.Frequency
 					extraConfig.DateConfList[i].EndDate = edbItem.EndDate
 				}
-
 			}
 		}
 	}
@@ -323,7 +351,7 @@ func GetChartSectionCombineData(chartInfo *models.ChartInfo, mappingList []*mode
 }
 
 // GetChartSectionSeriesDateByDateChange 获取日期变换后的日期edbInfoId 1指标日期,2 系统日期
-func GetChartSectionSeriesDateByDateChange(edbInfoId int, dataList []*models.EdbDataList, dateChange []*models.EdbDateConfDateChange, moveForward int) (newDate string, err error) {
+func GetChartSectionSeriesDateByDateChange(edbInfoId int, dataList []*models.EdbDataList, dateChange []*models.ChartSectionDateChange, moveForward int) (newDate string, err error) {
 	if edbInfoId > 0 { //指标日期
 		newDate = GetEdbDateByMoveForward(moveForward, dataList)
 	} else {
@@ -359,7 +387,7 @@ func GetEdbDateByMoveForwardByDateList(moveForward int, dateList []string) (date
 }
 
 // HandleChartSectionSeriesDateChange 处理日期变换
-func HandleChartSectionSeriesDateChange(date string, dateChange []*models.EdbDateConfDateChange) (newDate string, err error) {
+func HandleChartSectionSeriesDateChange(date string, dateChange []*models.ChartSectionDateChange) (newDate string, err error) {
 	newDate = date
 	if newDate != "" {
 		if len(dateChange) > 0 {
@@ -521,7 +549,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)
 
@@ -560,6 +588,7 @@ func SortChartSeriesDataSet(baseName string, baseDataList []float64, baseSeriesN
 				newDataListMap[k][i] = dataListMap[k][idx]
 			}
 		}
+
 		dataListMap = newDataListMap
 		noDataListIndexMap = newNoDataListIndexMap
 		newDataListMap = make(map[string][]float64)
@@ -611,5 +640,6 @@ func SortChartSeriesDataSet(baseName string, baseDataList []float64, baseSeriesN
 			newDataListMap[k][i] = dataListMap[k][idx]
 		}
 	}
+	newIndexXDataList = newIndices
 	return
 }