Jelajahi Sumber

Merge branch 'bug/7288' into debug

Roc 1 Minggu lalu
induk
melakukan
53d107ba70

+ 22 - 10
controller/chart/chart_info.go

@@ -184,15 +184,27 @@ func GetChartInfoDetail(c *gin.Context) {
 			}
 		}
 
-		yearMax := 0
-		if dateType == utils.DateTypeNYears {
-			for _, v := range mappingList {
-				if v.LatestDate.Year() > yearMax {
-					yearMax = v.LatestDate.Year()
+		var dateMax time.Time
+		for _, v := range mappingList {
+			// 得到指标更新的最新的年份
+			if dateType == utils.DateTypeNYears && !v.LatestDate.IsZero() {
+				if v.LatestDate.After(dateMax) {
+					dateMax = v.LatestDate
 				}
 			}
 		}
-		startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+
+		if chartType == utils.CHART_TYPE_SEASON && dateType == utils.DateTypeNYears {
+			// 季节性图表,要特殊处理起始日期, 最近N年
+			dateMax = time.Date(dateMax.Year()+1, 1, 1, 0, 0, 0, 0, time.Local)
+		}
+
+		// 开始/结束日期
+		startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
+		if startDate == "" {
+			response.FailMsg("获取失败", "时间格式错误", c)
+			return
+		}
 
 		// 图表额外数据参数
 		extraConfigStr := chartInfo.ExtraConfig
@@ -313,15 +325,15 @@ func getChartInfoDetail(chartInfo *chartInfoModel.ChartInfoView, myChartClassify
 		errMsg = "获取图表指标信息失败4001, Err:" + err.Error()
 		return
 	}
-	yearMax := 0
+	var dateMax time.Time
 	if dateType == utils.DateTypeNYears {
 		for _, v := range mappingList {
-			if v.LatestDate.Year() > yearMax {
-				yearMax = v.LatestDate.Year()
+			if !v.LatestDate.IsZero() && v.LatestDate.After(dateMax) {
+				dateMax = v.LatestDate
 			}
 		}
 	}
-	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
+	startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, dateMax)
 	//fmt.Println("start_date:", startDate)
 	//fmt.Println("end_date:", endDate)
 

+ 2 - 5
controller/edb_info/edb_info.go

@@ -37,12 +37,9 @@ func EdbData(c *gin.Context) {
 		response.FailMsg("获取失败", "获取指标信息失败,Err:"+e.Error(), c)
 		return
 	}
-	maxYear := 0
-	if !edbInfo.LatestDate.IsZero() {
-		maxYear = edbInfo.LatestDate.Year()
-	}
+
 	dataList := make([]*edb_data.EdbDataList, 0)
-	startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, maxYear)
+	startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, edbInfo.LatestDate)
 	dataList, e = edb_data.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, req.EdbInfoId, startDate, endDate)
 	if e != nil {
 		response.FailMsg("获取失败", "获取指标数据失败, Err: "+e.Error(), c)

+ 1 - 5
controller/edb_info/predict_edb_info.go

@@ -53,11 +53,7 @@ func PredictEdbData(c *gin.Context) {
 		response.FailMsg("获取失败", "获取指标信息失败,Err:"+e.Error(), c)
 		return
 	}
-	maxYear := 0
-	if !edbInfo.LatestDate.IsZero() {
-		maxYear = edbInfo.LatestDate.Year()
-	}
-	startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, maxYear)
+	startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, edbInfo.LatestDate)
 	if endDate == "" {
 		endDate = time.Now().Format(utils.FormatDate)
 	}

+ 40 - 6
utils/common.go

@@ -1370,7 +1370,7 @@ func removeDecimalPoint(str string) string {
 	return str
 }
 
-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 {
@@ -1405,16 +1405,46 @@ 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 = ""
+	case DateTypeOneWeek:
+		//if startDate != "" {
+		//	st, e := time.ParseInLocation(FormatDate, startDate, time.Local)
+		//	if e != nil {
+		//		FileLog.Info(fmt.Sprintf("日期格式解析失败, %s, %v", startDate, e))
+		//		return
+		//	}
+		//	startDate = st.AddDate(0, 0, -7).Format(FormatDate)
+		//}
+		startDate = time.Now().AddDate(0, 0, -7).Format(FormatDate)
+		endDate = ""
+	case DateTypeOneMonth:
+		startDate = time.Now().AddDate(0, -1, 0).Format(FormatDate)
+		endDate = ""
+	case DateTypeTwoMonth:
+		startDate = time.Now().AddDate(0, -2, 0).Format(FormatDate)
+		endDate = ""
+	case DateTypeThreeMonth:
+		startDate = time.Now().AddDate(0, -3, 0).Format(FormatDate)
+		endDate = ""
+	case DateTypeNMonth:
+		if startYear == 0 {
+			startYear = 6
+		}
+		startDate = time.Now().AddDate(0, -startYear, 0).Format(FormatDate)
 		endDate = ""
 	}
 
@@ -1424,7 +1454,11 @@ func GetDateByDateTypeV2(dateType int, tmpStartDate, tmpEndDate string, startYea
 			startDate = startDate + "-01"
 		}
 		if strings.Count(endDate, "-") == 1 {
-			endDate = endDate + "-01"
+			endTime, err := time.Parse(FormatYearMonthDate, endDate)
+			if err != nil {
+				return
+			}
+			endDate = endTime.AddDate(0, 1, -1).Format(FormatDate)
 		}
 	}
 

+ 31 - 18
utils/constants.go

@@ -2,18 +2,25 @@ package utils
 
 // 常量定义
 const (
-	FormatTime            = "15:04:05"                //时间格式
-	FormatDate            = "2006-01-02"              //日期格式
-	FormatDateCN          = "2006年01月02日"             //日期格式(中文)
-	FormatDateUnSpace     = "20060102"                //日期格式
-	FormatDateTime        = "2006-01-02 15:04:05"     //完整时间格式
-	HlbFormatDateTime     = "2006-01-02_15:04:05.999" //完整时间格式
-	FormatDateTimeUnSpace = "20060102150405"          //完整时间格式
-	PageSize15            = 15                        //列表页每页数据量
-	PageSize5             = 5
-	PageSize10            = 10
-	PageSize20            = 20
-	PageSize30            = 30
+	FormatTime                 = "15:04:05"                  //时间格式
+	FormatDate                 = "2006-01-02"                //日期格式
+	FormatDateCN               = "2006年01月02日"               //日期格式(中文)
+	FormatDateUnSpace          = "20060102"                  //日期格式
+	FormatDateTime             = "2006-01-02 15:04:05"       //完整时间格式
+	HlbFormatDateTime          = "2006-01-02_15:04:05.999"   //完整时间格式
+	FormatDateTimeUnSpace      = "20060102150405"            //完整时间格式
+	FormatShortDateTimeUnSpace = "060102150405"              //省去开头两位年份的时间格式
+	EmptyDateTimeStr           = "0000-00-00 00:00:00"       //DateTime零值字符串
+	EmptyDateStr               = "0000-00-00"                //Date零值字符串
+	FormatMonthDayUnSpace      = "0102"                      //日期格式
+	FormatMonthDay             = "01-02"                     //日期格式
+	FormatYearMonthDate        = "2006-01"                   //日期格式
+	FormatDateWallWithLoc      = "2006-01-02T15:04:05-07:00" //日期格式
+	PageSize15                 = 15                          //列表页每页数据量
+	PageSize5                  = 5
+	PageSize10                 = 10
+	PageSize20                 = 20
+	PageSize30                 = 30
 )
 
 const DateTypeNYears = 20 //时间类型为最近N年
@@ -209,12 +216,6 @@ const (
 	HzCompanyId = 16      // 弘则研究公司ID
 )
 
-// 图表样式类型
-const (
-	CHART_TYPE_RADAR           = 11 //雷达图
-	CHART_TYPE_SECTION_COMBINE = 14 //截面组合图
-)
-
 // 报告
 const (
 	DEFAULT_REPORT_SHARE_BG_IMG = "https://hzstatic.hzinsights.com/static/icon/hzyb/rddp-share-bg.png" // 分享默认背景图
@@ -337,8 +338,12 @@ const (
 // 图表样式类型
 const (
 	CHART_TYPE_CURVE           = 1  //曲线图
+	CHART_TYPE_SEASON          = 2  //季节性图
+	CHART_TYPE_AREA            = 3  // 面积图
 	CHART_TYPE_BAR             = 7  //柱形图
 	CHART_TYPE_SECTION_SCATTER = 10 //截面散点图样式
+	CHART_TYPE_RADAR           = 11 //雷达图
+	CHART_TYPE_SECTION_COMBINE = 14 //截面组合图
 )
 
 // FrequencyDaysMap 频度日期的map关系
@@ -385,3 +390,11 @@ const APPLY_VARIETY_IMG_DEFAULT = "https://hzstatic.hzinsights.com/static/yb_var
 const (
 	FiccProductId = 1 // FICC标识ID
 )
+
+const (
+	DateTypeOneWeek    = 21 // 时间类型-近1周
+	DateTypeOneMonth   = 22 // 时间类型-近1月
+	DateTypeTwoMonth   = 23 // 时间类型-近2月
+	DateTypeThreeMonth = 24 // 时间类型-近3月
+	DateTypeNMonth     = 25 // 时间类型-近N月
+)