فهرست منبع

fix:图库日期范围

zqbao 2 ماه پیش
والد
کامیت
c579841bed
4فایلهای تغییر یافته به همراه27 افزوده شده و 23 حذف شده
  1. 4 4
      controllers/chart.go
  2. 4 4
      services/data/chart_info_excel_balance.go
  3. 10 10
      services/data/range_analysis/chart_info.go
  4. 9 5
      utils/common.go

+ 4 - 4
controllers/chart.go

@@ -443,7 +443,7 @@ func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (
 		errMsg = "获取图表,指标信息失败,Err:" + err.Error()
 		return
 	}
-	yearMax := 0
+	var dateMax time.Time
 	if dateType == utils.DateTypeNYears {
 		for _, v := range mappingList {
 			if v.LatestDate != "" {
@@ -453,13 +453,13 @@ func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfo, key string) (
 					errMsg = "获取图表日期信息失败,Err:" + tErr.Error()
 					return
 				}
-				if lastDateT.Year() > yearMax {
-					yearMax = lastDateT.Year()
+				if lastDateT.After(dateMax) {
+					dateMax = lastDateT
 				}
 			}
 		}
 	}
-	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
 
 	extraConfigStr := chartInfo.ExtraConfig
 	// 柱方图的一些配置

+ 4 - 4
services/data/chart_info_excel_balance.go

@@ -63,7 +63,7 @@ func GetBalanceExcelChartDetail(chartInfo *models.ChartInfo, mappingListTmp []*e
 			dateType = 3
 		}
 	}
-	yearMax := 0
+	var dateMax time.Time
 	if dateType == utils.DateTypeNYears {
 		for _, v := range mappingList {
 			if v.LatestDate != "" {
@@ -73,13 +73,13 @@ func GetBalanceExcelChartDetail(chartInfo *models.ChartInfo, mappingListTmp []*e
 					err = fmt.Errorf("获取图表日期信息失败,Err:" + tErr.Error())
 					return
 				}
-				if lastDateT.Year() > yearMax {
-					yearMax = lastDateT.Year()
+				if lastDateT.After(dateMax) {
+					dateMax = lastDateT
 				}
 			}
 		}
 	}
-	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
 
 	if chartInfo.ChartType == 2 {
 		chartInfo.StartDate = startDate

+ 10 - 10
services/data/range_analysis/chart_info.go

@@ -9,9 +9,10 @@ import (
 	"eta/eta_chart_lib/services/data"
 	"eta/eta_chart_lib/utils"
 	"fmt"
-	"github.com/shopspring/decimal"
 	"math"
 	"time"
+
+	"github.com/shopspring/decimal"
 )
 
 // GetAutoCalculateDateDataList 获取当前时间相关的区间作为计算依据
@@ -447,7 +448,7 @@ func GetChartDataByEdbInfoList(chartInfoId int, dateType, startYear int, startDa
 		xEdbIdValue = append(xEdbIdValue, edbInfoMapping.EdbInfoId)
 	}
 	//根据时间类型来筛选最终的数据
-	yearMax := 0
+	var dateMax time.Time
 	if dateType == utils.DateTypeNYears {
 		for _, v := range edbInfoMappingList {
 			dataList := v.DataList.([]*models.EdbDataList)
@@ -457,16 +458,15 @@ func GetChartDataByEdbInfoList(chartInfoId int, dateType, startYear int, startDa
 					lastDateT, tErr := time.Parse(utils.FormatDate, latestDate)
 					if tErr != nil {
 						err = fmt.Errorf("获取图表日期信息失败,Err:" + tErr.Error())
-						return
 					}
-					if lastDateT.Year() > yearMax {
-						yearMax = lastDateT.Year()
+					if lastDateT.After(dateMax) {
+						dateMax = lastDateT
 					}
 				}
 			}
 		}
 	}
-	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
 
 	if startDate != "" {
 		for k, v := range edbInfoMappingList {
@@ -579,7 +579,7 @@ func GetChartDataByEdbInfoListBySeries(chartInfoId int, dateType, startYear int,
 		edbInfoMapping.MinData = minData
 		xEdbIdValue = append(xEdbIdValue, edbInfoMapping.EdbInfoId)
 	}
-	yearMax := 0
+	var dateMax time.Time
 	if dateType == utils.DateTypeNYears {
 		for _, v := range edbInfoMappingList {
 			dataList := v.DataList.([]*models.EdbDataList)
@@ -590,13 +590,13 @@ func GetChartDataByEdbInfoListBySeries(chartInfoId int, dateType, startYear int,
 					err = fmt.Errorf("获取图表日期信息失败,Err:" + tErr.Error())
 					return
 				}
-				if lastDateT.Year() > yearMax {
-					yearMax = lastDateT.Year()
+				if lastDateT.After(dateMax) {
+					dateMax = lastDateT
 				}
 			}
 		}
 	}
-	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
 
 	if startDate != "" {
 		for k, v := range edbInfoMappingList {

+ 9 - 5
utils/common.go

@@ -1008,7 +1008,7 @@ func GetLocalIP() (ip string, err error) {
 	return
 }
 
-func GetDateByDateTypeV2(dateType int, tmpStartDate, tmpEndDate string, startYear, yearMax int) (startDate, endDate string) {
+func GetDateByDateTypeV2(dateType int, tmpStartDate, tmpEndDate string, startYear int, latestDate time.Time) (startDate, endDate string) {
 	startDate = tmpStartDate
 	endDate = tmpEndDate
 	switch dateType {
@@ -1043,16 +1043,20 @@ func GetDateByDateTypeV2(dateType int, tmpStartDate, tmpEndDate string, startYea
 	case 11:
 		startDate = "2022-01-01"
 		endDate = ""
+	case 12:
+		startDate = "2023-01-01"
+		endDate = ""
+	case 13:
+		startDate = "2024-01-01"
+		endDate = ""
 	case DateTypeNYears:
 		if startYear == 0 { //默认取最近5年
 			startYear = 5
 		}
-		if yearMax == 0 {
+		if latestDate.IsZero() {
 			return
 		}
-		startYear = startYear - 1
-		baseDate, _ := time.Parse(FormatDate, fmt.Sprintf("%d-01-01", yearMax))
-		startDate = baseDate.AddDate(-startYear, 0, 0).Format(FormatDate)
+		startDate = latestDate.AddDate(-startYear, 0, 0).Format(FormatDate)
 		endDate = ""
 	}