ソースを参照

Merge branch 'bzq/bug_6744_chart_save' of eta_server/eta_chart_lib into master

baoziqiang 2 ヶ月 前
コミット
3d0708a912

+ 8 - 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,17 @@ 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)
+	if chartInfo.DateType == utils.DateTypeNYears && chartInfo.ChartType == utils.CHART_TYPE_SEASON {
+		// 季节性图表,要特殊处理起始日期, 最近N年
+		dateMax = time.Date(dateMax.Year()+1, 1, 1, 0, 0, 0, 0, time.Local)
+	}
+	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 = ""
 	}
 

+ 1 - 0
utils/constants.go

@@ -160,6 +160,7 @@ const (
 // 图表样式类型
 const (
 	CHART_TYPE_CURVE           = 1  //曲线图
+	CHART_TYPE_SEASON          = 2  //季节性图
 	CHART_TYPE_BAR             = 7  //柱形图
 	CHART_TYPE_SECTION_SCATTER = 10 //截面散点图样式
 	CHART_TYPE_RADAR           = 11 //雷达图