Browse Source

对数据进行排序

xyxie 10 tháng trước cách đây
mục cha
commit
d08fbddf0f

+ 6 - 0
controllers/data_manage/excel/balance_table.go

@@ -20,6 +20,7 @@ import (
 	"github.com/tealeg/xlsx"
 	"io/ioutil"
 	"os"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -982,6 +983,11 @@ func (c *ExcelInfoController) BalanceSeasonChartLegendPreview() {
 		dataList = append(dataList, tmp)
 	}
 
+	// 对dataList 根据dataTimestamp 进行排序
+	sort.Slice(dataList, func(i, j int) bool {
+		return dataList[i].DataTimestamp < dataList[j].DataTimestamp
+	})
+
 	list, err, errMsg := data.GetBalanceExcelSeasonChartLegendPreview(dataList, req.Calendar, req.SeasonExtraConfig)
 	if err != nil {
 		if errMsg != "" {

+ 5 - 0
services/data/chart_info_excel_balance.go

@@ -12,6 +12,7 @@ import (
 	"eta/eta_api/utils"
 	"fmt"
 	"math"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -884,6 +885,10 @@ func GetBalanceExcelEdbDataMapList(chartInfoId, chartType int, calendar, startDa
 		dataListTmp, ok := dataListMap[v.EdbInfoId]
 		if ok {
 			dataList = dataListTmp
+			// 对dataList 根据dataTimestamp 进行排序
+			sort.Slice(dataList, func(i, j int) bool {
+				return dataList[i].DataTimestamp < dataList[j].DataTimestamp
+			})
 		} else {
 			//err = errors.New(fmt.Sprint("获取失败,指标类型异常", v.EdbInfoId))
 			utils.FileLog.Info(fmt.Sprintf("获取失败,指标数据异常 %d", v.EdbInfoId))