Browse Source

日期修改

xyxie 4 months ago
parent
commit
1966e47892
3 changed files with 114 additions and 46 deletions
  1. 106 45
      models/edb_info.go
  2. 2 1
      models/predict_edb.go
  3. 6 0
      models/predict_edb_conf.go

+ 106 - 45
models/edb_info.go

@@ -788,7 +788,7 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 		endDate = predictEdbConf.EndDate
 		var tmpMinValue, tmpMaxValue float64 // 当前预测结果中的最大/最小值
 
-		dayList := getPredictEdbDayList(startDate, endDate, frequency, dataDateType)
+		dayList := getPredictEdbDayList(startDate, endDate, frequency, dataDateType, predictEdbConf.EndDateType, predictEdbConf.EndNum)
 		if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
 			continue
 		}
@@ -1019,69 +1019,130 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 // GetPredictEdbDayList 获取预测指标日期列表
 
 // GetPredictEdbDayList 获取预测指标日期列表
-func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType string) (dayList []time.Time) {
+func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType string, endDateType, endNum int) (dayList []time.Time) {
 	if dataDateType == `` {
 		dataDateType = `交易日`
 	}
-	switch frequency {
-	case "日度":
-		for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 1) {
-			// 如果日期类型是交易日的时候,那么需要将周六、日排除
-			if dataDateType == `交易日` && (currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday) {
-				continue
+	if endDateType == 0 { // 截止日期
+		switch frequency {
+		case "日度":
+			for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 1) {
+				// 如果日期类型是交易日的时候,那么需要将周六、日排除
+				if dataDateType == `交易日` && (currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday) {
+					continue
+				}
+				dayList = append(dayList, currDate)
 			}
-			dayList = append(dayList, currDate)
-		}
-	case "周度":
-		//nextDate := startDate.AddDate(0, 0, 7)
-		for currDate := startDate.AddDate(0, 0, 7); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 7) {
-			dayList = append(dayList, currDate)
-		}
-	case "旬度":
-		for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
-			nextDate := currDate.AddDate(0, 0, 1)
-			//每个月的10号、20号、最后一天,那么就写入
-			if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
+		case "周度":
+			//nextDate := startDate.AddDate(0, 0, 7)
+			for currDate := startDate.AddDate(0, 0, 7); currDate.Before(endDate) || currDate.Equal(endDate); currDate = currDate.AddDate(0, 0, 7) {
 				dayList = append(dayList, currDate)
 			}
-			currDate = nextDate
+		case "旬度":
+			for currDate := startDate.AddDate(0, 0, 1); currDate.Before(endDate) || currDate.Equal(endDate); {
+				nextDate := currDate.AddDate(0, 0, 1)
+				//每个月的10号、20号、最后一天,那么就写入
+				if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
+					dayList = append(dayList, currDate)
+				}
+				currDate = nextDate
+			}
+		case "月度":
+			for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
+				currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+				if !currDate.After(endDate) && !currDate.Equal(startDate) {
+					dayList = append(dayList, currDate)
+				}
+				currDate = currDate.AddDate(0, 0, 1)
+			}
+		case "季度":
+			for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
+				// 每月的最后一天
+				currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+				if !currDate.After(endDate) && !currDate.Equal(startDate) {
+					// 季度日期就写入,否则不写入
+					if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
+						dayList = append(dayList, currDate)
+					}
+				}
+				currDate = currDate.AddDate(0, 0, 1)
+			}
+		case "半年度":
+			for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
+				// 每月的最后一天
+				currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+				if !currDate.After(endDate) && !currDate.Equal(startDate) {
+					// 半年度日期就写入,否则不写入
+					if currDate.Month() == 6 || currDate.Month() == 12 {
+						dayList = append(dayList, currDate)
+					}
+				}
+				currDate = currDate.AddDate(0, 0, 1)
+			}
+		case "年度":
+			for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
+				currDate = time.Date(currDate.Year()+1, 12, 31, 0, 0, 0, 0, time.Now().Location())
+				if !currDate.After(endDate) && !currDate.Equal(startDate) {
+					dayList = append(dayList, currDate)
+				}
+			}
 		}
-	case "月度":
-		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
-			currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
-			if !currDate.After(endDate) && !currDate.Equal(startDate) {
+	} else { // 截止期数
+		switch frequency {
+		case "日度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(0, 0, i)
+				// 如果日期类型是交易日的时候,那么需要将周六、日排除
+				if dataDateType == `交易日` && (currDate.Weekday() == time.Sunday || currDate.Weekday() == time.Saturday) {
+					continue
+				}
 				dayList = append(dayList, currDate)
 			}
-			currDate = currDate.AddDate(0, 0, 1)
-		}
-	case "季度":
-		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
-			// 每月的最后一天
-			currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
-			if !currDate.After(endDate) && !currDate.Equal(startDate) {
+		case "周度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(0, 0, i*7)
+				dayList = append(dayList, currDate)
+			}
+		case "旬度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(0, 0, i*10)
+				nextDate := currDate.AddDate(0, 0, 1)
+				//每个月的10号、20号、最后一天,那么就写入
+				if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
+					dayList = append(dayList, currDate)
+				}
+			}
+		case "月度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(0, i, 0)
+				currDate, _ = time.ParseInLocation(utils.FormatDate, fmt.Sprintf(`%d-%d-01`, currDate.Year(), currDate.Month()+1), time.Local)
+				currDate = currDate.AddDate(0, i, -1)
+				dayList = append(dayList, currDate)
+			}
+		case "季度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(0, i*3, 0)
+				currDate, _ = time.ParseInLocation(utils.FormatDate, fmt.Sprintf(`%d-%d-01`, currDate.Year(), currDate.Month()+1), time.Local)
+				currDate = currDate.AddDate(0, i, -1)
 				// 季度日期就写入,否则不写入
 				if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
 					dayList = append(dayList, currDate)
 				}
 			}
-			currDate = currDate.AddDate(0, 0, 1)
-		}
-	case "半年度":
-		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
-			// 每月的最后一天
-			currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
-			if !currDate.After(endDate) && !currDate.Equal(startDate) {
+		case "半年度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(0, i*3, 0)
+				currDate, _ = time.ParseInLocation(utils.FormatDate, fmt.Sprintf(`%d-%d-01`, currDate.Year(), currDate.Month()+1), time.Local)
+				currDate = currDate.AddDate(0, i, -1)
 				// 半年度日期就写入,否则不写入
 				if currDate.Month() == 6 || currDate.Month() == 12 {
 					dayList = append(dayList, currDate)
 				}
 			}
-			currDate = currDate.AddDate(0, 0, 1)
-		}
-	case "年度":
-		for currDate := startDate; currDate.Before(endDate) || currDate.Equal(endDate); {
-			currDate = time.Date(currDate.Year()+1, 12, 31, 0, 0, 0, 0, time.Now().Location())
-			if !currDate.After(endDate) && !currDate.Equal(startDate) {
+		case "年度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(i, 0, 0)
+				currDate, _ = time.ParseInLocation(utils.FormatDate, fmt.Sprintf(`%d-12-31`, currDate.Year()), time.Local)
 				dayList = append(dayList, currDate)
 			}
 		}

+ 2 - 1
models/predict_edb.go

@@ -368,7 +368,8 @@ func CalculateByRuleByRuleLineNh(to orm.TxOrmer, predictEdbInfo EdbInfo, predict
 		startDate, _ := time.ParseInLocation(utils.FormatDate, startDateStr, time.Local)
 		//endDate, _ := time.ParseInLocation(utils.FormatDate, ruleConf.EndDate, time.Local)
 		endDate := rule.EndDate
-		dayList := getPredictEdbDayList(startDate, endDate, predictEdbInfo.Frequency, predictEdbInfo.DataDateType)
+		// todo 拟合时间配置
+		dayList := getPredictEdbDayList(startDate, endDate, predictEdbInfo.Frequency, predictEdbInfo.DataDateType, rule.EndDateType, rule.EndNum)
 		if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
 			return
 		}

+ 6 - 0
models/predict_edb_conf.go

@@ -27,6 +27,8 @@ type RuleConfig struct {
 	EmptyType    int              `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
 	MaxEmptyType int              `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
 	EndDate      string           `description:"截止日期"`
+	EndDateType  int              `description:"截止日期类型:0:未来时间,1未来期数"`
+	EndNum       int              `description:"截止期数"`
 	EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
 }
 
@@ -50,6 +52,8 @@ type PredictEdbConf struct {
 	EndDate          time.Time `description:"截止日期"`
 	ModifyTime       time.Time `description:"修改时间"`
 	CreateTime       time.Time `description:"添加时间"`
+	EndDateType      int       `description:"截止日期类型:0:未来时间,1未来期数"`
+	EndNum           int       `description:"截止期数"`
 }
 
 // PredictEdbConfAndData 预测规则和其对应的动态数据
@@ -66,6 +70,8 @@ type PredictEdbConfAndData struct {
 	ModifyTime       time.Time            `description:"修改时间"`
 	CreateTime       time.Time            `description:"添加时间"`
 	DataList         []*EdbInfoSearchData `description:"动态数据"`
+	EndDateType      int                  `description:"截止日期类型:0:未来时间,1未来期数"`
+	EndNum           int                  `description:"截止期数"`
 }
 
 // GetPredictEdbConfById 根据预测指标id获取预测指标配置信息