xyxie 9 месяцев назад
Родитель
Сommit
42a706b602
2 измененных файлов с 46 добавлено и 8 удалено
  1. 32 0
      models/chart_series.go
  2. 14 8
      services/chart_extra_config.go

+ 32 - 0
models/chart_series.go

@@ -33,3 +33,35 @@ func GetChartSeriesByChartInfoId(chartInfoId int) (items []*ChartSeries, err err
 	_, err = o.Raw(sql, chartInfoId).QueryRows(&items)
 	return
 }
+
+type ChartSectionSeriesValSortAsc []ChartSectionSeriesValSort
+type ChartSectionSeriesValSortDesc []ChartSectionSeriesValSort
+
+type ChartSectionSeriesValSort struct {
+	Index int
+	Value float64
+}
+
+func (s ChartSectionSeriesValSortAsc) Len() int {
+	return len(s)
+}
+
+func (s ChartSectionSeriesValSortAsc) Less(i, j int) bool {
+	return s[i].Value < s[j].Value // 升序排序,如果想要降序则改为 s[i].Value > s[j].Value
+}
+
+func (s ChartSectionSeriesValSortAsc) Swap(i, j int) {
+	s[i], s[j] = s[j], s[i]
+}
+
+func (s ChartSectionSeriesValSortDesc) Len() int {
+	return len(s)
+}
+
+func (s ChartSectionSeriesValSortDesc) Less(i, j int) bool {
+	return s[i].Value > s[j].Value // 升序排序,如果想要降序则改为 s[i].Value > s[j].Value
+}
+
+func (s ChartSectionSeriesValSortDesc) Swap(i, j int) {
+	s[i], s[j] = s[j], s[i]
+}

+ 14 - 8
services/chart_extra_config.go

@@ -67,7 +67,7 @@ func GetChartSectionCombineData(chartInfo *models.ChartInfo, mappingList []*mode
 			}
 			seriesItem.EdbInfoList[index].EdbName = edbMappingInfo.EdbName
 			seriesItem.EdbInfoList[index].EdbNameEn = edbMappingInfo.EdbNameEn
-			seriesItem.EdbInfoList[index].EdbInfoType = edbMappingInfo.EdbInfoType
+			seriesItem.EdbInfoList[index].EdbInfoType = edbMappingInfo.EdbInfoCategoryType
 			seriesItem.EdbInfoList[index].Unit = edbMappingInfo.Unit
 			seriesItem.EdbInfoList[index].UnitEn = edbMappingInfo.UnitEn
 			if index == 0 {
@@ -575,15 +575,21 @@ func SortChartSeriesDataSet(baseName string, baseDataList []float64, baseSeriesN
 
 	}
 	length := len(indices)
-	// 根据Group1的数据进行排序,asc决定是升序还是降序
+	baseDataSortList := make([]models.ChartSectionSeriesValSort, length)
+	for i, value := range baseDataList {
+		if i < length {
+			baseDataSortList[i] = models.ChartSectionSeriesValSort{Index: i, Value: value}
+		}
+	}
 	if asc == 1 {
-		sort.Slice(indices, func(i, j int) bool {
-			return baseDataList[i] < baseDataList[j]
-		})
+		// 使用sort.Sort进行排序
+		sort.Sort(models.ChartSectionSeriesValSortAsc(baseDataSortList))
 	} else {
-		sort.Slice(indices, func(i, j int) bool {
-			return baseDataList[i] > baseDataList[j]
-		})
+		sort.Sort(models.ChartSectionSeriesValSortDesc(baseDataSortList))
+	}
+
+	for k, v := range baseDataSortList {
+		indices[k] = v.Index
 	}
 
 	for i := range newIndices {