xyxie 1 maand geleden
bovenliggende
commit
7cec5bfccd
3 gewijzigde bestanden met toevoegingen van 58 en 11 verwijderingen
  1. 9 4
      controllers/chart_info.go
  2. 40 6
      utils/common.go
  3. 9 1
      utils/constants.go

+ 9 - 4
controllers/chart_info.go

@@ -461,7 +461,7 @@ func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfoView, key strin
 			dateType = 3
 		}
 	}
-	yearMax := 0
+	var dateMax time.Time
 	if dateType == utils.DateTypeNYears {
 		for _, v := range mappingList {
 			if v.LatestDate != "" {
@@ -471,13 +471,18 @@ func GetChartInfoDetailFromUniqueCode(chartInfo *models.ChartInfoView, key strin
 					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 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 chartInfo.ChartType == 2 {
 		chartInfo.StartDate = startDate
 		chartInfo.EndDate = endDate

+ 40 - 6
utils/common.go

@@ -1213,7 +1213,7 @@ func GetLikeKeyword(keyword string) string {
 	return `%` + keyword + `%`
 }
 
-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 {
@@ -1248,16 +1248,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 = ""
 	}
 
@@ -1267,7 +1297,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)
 		}
 	}
 

+ 9 - 1
utils/constants.go

@@ -19,7 +19,15 @@ const (
 	PageSize20                 = 20
 	PageSize30                 = 30
 )
-const DateTypeNYears = 20 //时间类型为最近N年
+const (
+	DateTypeNYears     = 20 //时间类型为最近N年
+	DateTypeOneWeek    = 21 // 时间类型-近1周
+	DateTypeOneMonth   = 22 // 时间类型-近1月
+	DateTypeTwoMonth   = 23 // 时间类型-近2月
+	DateTypeThreeMonth = 24 // 时间类型-近3月
+	DateTypeNMonth     = 25 // 时间类型-近N月
+)
+
 // 数据来源渠道
 const (
 	DATA_SOURCE_THS                                  = iota + 1 //同花顺