Forráskód Böngészése

Merge branch 'feature/eta2.2.8_predit_date' of eta_server/eta_index_lib into master

xyxie 2 hete
szülő
commit
5c18027da1

+ 2 - 2
controllers/base_from_predict.go

@@ -59,7 +59,7 @@ func addPredict(br *models.BaseResponse, req models.AddPredictEdbInfoReq, lang s
 	}
 
 	// 添加指标
-	edbInfo, err, errMsg := logic.AddPredictEdbInfo(req.SourceEdbInfoId, req.ClassifyId, req.EdbName, req.DataDateType, req.RuleList, req.MinValue, req.MaxValue, req.AdminId, req.AdminName, lang)
+	edbInfo, err, errMsg := logic.AddPredictEdbInfo(req.SourceEdbInfoId, req.ClassifyId, req.EdbName, req.DataDateType, req.EndDateType, req.RuleList, req.MinValue, req.MaxValue, req.AdminId, req.AdminName, lang)
 	if err != nil {
 		br.Msg = "保存失败"
 		if errMsg != `` {
@@ -97,7 +97,7 @@ func editPredict(br *models.BaseResponse, req models.AddPredictEdbInfoReq, lang
 	}
 
 	// 编辑指标
-	edbInfo, err, errMsg := logic.EditPredictEdbInfo(req.EdbInfoId, req.ClassifyId, req.EdbName, req.DataDateType, req.RuleList, req.MinValue, req.MaxValue, lang)
+	edbInfo, err, errMsg := logic.EditPredictEdbInfo(req.EdbInfoId, req.ClassifyId, req.EdbName, req.DataDateType, req.EndDateType, req.RuleList, req.MinValue, req.MaxValue, lang)
 	if err != nil {
 		br.Msg = "保存失败"
 		if errMsg != `` {

+ 62 - 20
logic/predict_edb.go

@@ -11,7 +11,7 @@ import (
 )
 
 // AddPredictEdbInfo 新增预测指标
-func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType string, ruleList []models.RuleConfig, minValue, maxValue float64, sysUserId int, sysUserName, lang string) (edbInfo *models.EdbInfo, err error, errMsg string) {
+func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType string, endDateType int, ruleList []models.RuleConfig, minValue, maxValue float64, sysUserId int, sysUserName, lang string) (edbInfo *models.EdbInfo, err error, errMsg string) {
 	var sourceEdbInfo *models.EdbInfo
 	// 来源指标信息校验
 	{
@@ -82,6 +82,7 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType st
 	if dataDateType == `` {
 		dataDateType = `自然日`
 	}
+
 	edbInfo = &models.EdbInfo{
 		//EdbInfoId:   0,
 		EdbInfoType:      1,
@@ -114,6 +115,7 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType st
 		UnitEn:        sourceEdbInfo.UnitEn,
 		DataDateType:  dataDateType,
 		Sort:          models.GetAddEdbMaxSortByClassifyId(classifyId, utils.PREDICT_EDB_INFO_TYPE),
+		EndDateType:   endDateType,
 	}
 
 	// 关联关系表
@@ -145,13 +147,22 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType st
 
 	// 预测指标配置
 	predictEdbConfList := make([]*models.PredictEdbConf, 0)
+	var ruleEndDate time.Time
 	for ruleIndex, v := range ruleList {
-		// 预测指标配置
-		ruleEndDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
-		if tmpErr != nil {
-			errMsg = "规则配置的截止日期异常,请重新填写"
-			err = errors.New(errMsg)
-			return
+		if endDateType == 0 {
+			// 预测指标配置
+			ruleEndDate, err = time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
+			if err != nil {
+				errMsg = "规则配置的截止日期异常,请重新填写"
+				err = errors.New(errMsg)
+				return
+			}
+		} else {
+			if v.EndNum <= 0 {
+				errMsg = "截止期数不正确,请输入大于等于1的整数"
+				err = errors.New(errMsg)
+				return
+			}
 		}
 		//1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值,9:动态环差,10:根据 给定终值后插值 规则获取预测数据,11:根据 季节性 规则获取预测数据,12:根据 移动平均同比 规则获取预测数据
 		// 环比、环差、动态环差、季节性、移动平均同比不支持年度
@@ -161,6 +172,11 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType st
 			return
 		}
 
+		if v.RuleType == 16 && endDateType != 1 {
+			errMsg = "年度值倒推不支持截止期数"
+			err = errors.New(errMsg)
+			return
+		}
 		switch v.RuleType {
 		case 8: //N期段线性外推值
 			valInt, tmpErr := strconv.Atoi(v.Value)
@@ -386,12 +402,16 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType st
 			SourceEdbInfoId:  sourceEdbInfoId,
 			RuleType:         v.RuleType,
 			//FixedValue:       v.Value,
-			Value:      v.Value,
-			EndDate:    ruleEndDate,
+			Value: v.Value,
+			//EndDate:    ruleEndDate,
 			ModifyTime: time.Now(),
 			CreateTime: time.Now(),
+			EndNum:     v.EndNum,
 		}
-
+		if endDateType == 0 {
+			tmpPredictEdbConf.EndDate = ruleEndDate
+		}
+		//todo 指标最终的截止日期的更新
 		edbInfo.EndDate = v.EndDate
 
 		predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)
@@ -402,7 +422,7 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType st
 }
 
 // EditPredictEdbInfo 编辑预测指标
-func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string, ruleList []models.RuleConfig, minValue, maxValue float64, lang string) (edbInfo *models.EdbInfo, err error, errMsg string) {
+func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string, endDateType int, ruleList []models.RuleConfig, minValue, maxValue float64, lang string) (edbInfo *models.EdbInfo, err error, errMsg string) {
 	// 指标信息校验
 	{
 		edbInfo, err = models.GetEdbInfoById(edbInfoId)
@@ -458,6 +478,7 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 	if dataDateType == `` {
 		dataDateType = `自然日`
 	}
+
 	switch lang {
 	case utils.EnLangVersion:
 		edbInfo.EdbNameEn = edbName
@@ -471,7 +492,8 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 	edbInfo.MaxValue = maxValue
 	edbInfo.DataDateType = dataDateType
 	edbInfo.ModifyTime = time.Now()
-	updateEdbInfoCol := []string{"EdbName", "EdbNameEn", "EdbNameSource", "ClassifyId", "EndDate", "MinValue", "MaxValue", "DataDateType", "ModifyTime"}
+	edbInfo.EndDateType = endDateType
+	updateEdbInfoCol := []string{"EdbName", "EdbNameEn", "EdbNameSource", "ClassifyId", "EndDate", "MinValue", "MaxValue", "DataDateType", "ModifyTime", "EndDateType"}
 
 	var sourceEdbInfo *models.EdbInfo
 	// 来源指标信息校验
@@ -531,13 +553,23 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 	// 预测指标配置
 	predictEdbConfList := make([]*models.PredictEdbConf, 0)
 	for ruleIndex, v := range ruleList {
-		// 预测指标配置
-		ruleEndDate, tmpErr := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
-		if tmpErr != nil {
-			errMsg = "规则配置的截止日期异常,请重新填写"
-			err = errors.New(errMsg)
-			return
+		var ruleEndDate time.Time
+		if endDateType == 0 {
+			// 预测指标配置
+			ruleEndDate, err = time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
+			if err != nil {
+				errMsg = "规则配置的截止日期异常,请重新填写"
+				err = errors.New(errMsg)
+				return
+			}
+		} else {
+			if v.EndNum <= 0 {
+				errMsg = "截止期数不正确,请输入大于等于1的整数"
+				err = errors.New(errMsg)
+				return
+			}
 		}
+
 		//1:最新,2:固定值,3:同比,4:同差,5:环比,6:环差,7:N期移动均值,8:N期段线性外推值,9:动态环差,10:根据 给定终值后插值 规则获取预测数据,11:根据 季节性 规则获取预测数据,12:根据 移动平均同比 规则获取预测数据
 		// 环比、环差、动态环差、季节性、移动平均同比不支持年度
 		if sourceEdbInfo.Frequency == "年度" && utils.InArrayByInt([]int{5, 6, 11, 12}, v.RuleType) {
@@ -545,6 +577,11 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 			err = errors.New(errMsg)
 			return
 		}
+		if v.RuleType == 16 && endDateType != 1 {
+			errMsg = "年度值倒推不支持截止期数"
+			err = errors.New(errMsg)
+			return
+		}
 		switch v.RuleType {
 		case 8: //N期段线性外推值
 			valInt, tmpErr := strconv.Atoi(v.Value)
@@ -754,7 +791,7 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 				}
 				trendsMappingList = append(trendsMappingList, tmpPredictEdbConfCalculateMapping)
 			}
-
+			// todo
 			calculateRuleMap[ruleIndex] = models.CalculateRule{
 				TrendsCalculateMappingList: trendsMappingList,
 				EdbInfoList:                edbInfoList,
@@ -764,6 +801,7 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 				EndDate:      v.EndDate,
 				EdbInfoIdArr: v.EdbInfoIdArr,
 			}
+
 		}
 
 		tmpPredictEdbConf := &models.PredictEdbConf{
@@ -773,10 +811,14 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 			//FixedValue:       v.Value,
 			Value:      v.Value,
 			EndDate:    ruleEndDate,
+			EndNum:     v.EndNum,
 			ModifyTime: time.Now(),
 			CreateTime: time.Now(),
 		}
-
+		if endDateType == 0 {
+			tmpPredictEdbConf.EndDate = ruleEndDate
+		}
+		// todo
 		edbInfo.EndDate = v.EndDate
 
 		predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)

+ 137 - 58
models/edb_info.go

@@ -65,6 +65,7 @@ type EdbInfo struct {
 	StockCode        string  `description:"证券代码"`
 	Extra            string  `description:"指标的额外配置"`
 	IsStaticData     int     `description:"是否是静态指标,0否,1是"`
+	EndDateType      int     `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
 }
 
 func (e *EdbInfo) Add() (err error) {
@@ -741,17 +742,20 @@ func UnifiedModifyPredictEdbInfoMaxAndMinInfo(edbInfo *EdbInfo, latestDateStr st
 }
 
 // GetChartPredictEdbInfoDataListByConfList 获取图表的预测指标的未来数据
-func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr, frequency, dataDateType string, realPredictEdbInfoData []*EdbInfoSearchData) (predictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
-	endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
-	if err != nil {
-		return
+func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr, frequency, dataDateType string, endDateType int, realPredictEdbInfoData []*EdbInfoSearchData) (predictEdbInfoData []*EdbInfoSearchData, minValue, maxValue float64, err error) {
+	hasEndNum := 0 //如果选择了未来期数,用来保存已经预测过的期数
+	var endDate time.Time
+	if endDateStr != `` {
+		endDate, err = time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
+		if err != nil {
+			return
+		}
 	}
 
 	latestDate, err := time.ParseInLocation(utils.FormatDate, latestDateStr, time.Local)
 	if err != nil {
 		return
 	}
-
 	// 开始预测数据的时间
 	startDate := latestDate
 
@@ -785,13 +789,14 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 		//if predictEdbConf.EndDate.Before(dataEndTime) {
 		//	dataEndTime = predictEdbConf.EndDate
 		//}
-		endDate = predictEdbConf.EndDate
+		//endDate = predictEdbConf.EndDate
 		var tmpMinValue, tmpMaxValue float64 // 当前预测结果中的最大/最小值
-
-		dayList := getPredictEdbDayList(startDate, endDate, frequency, dataDateType)
+		endNum := predictEdbConf.EndNum - hasEndNum
+		dayList := getPredictEdbDayList(startDate, predictEdbConf.EndDate, frequency, dataDateType, endDateType, endNum)
 		if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
 			continue
 		}
+		endDate = dayList[len(dayList)-1]
 
 		switch predictEdbConf.RuleType {
 		case 1: //1:最新
@@ -868,7 +873,6 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 			}
 		case 9: //9:动态环差”预测规则;
 			hcDataMap := make(map[string]float64) //规则计算的环差值map
-
 			if predictEdbConf.PredictEdbInfoId > 0 {
 				tmpPredictEdbRuleDataList, tmpErr := GetPredictEdbRuleDataItemList(predictEdbConf.PredictEdbInfoId, predictEdbConf.ConfigId, startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
 				if tmpErr != nil {
@@ -998,6 +1002,9 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []*PredictEdbCo
 		{
 			lenPredictEdbInfoData := len(predictEdbInfoData)
 			if lenPredictEdbInfoData > 0 {
+				if endDateType == 1 {
+					hasEndNum = predictEdbConf.EndNum
+				}
 				tmpDataEndTime, _ := time.ParseInLocation(utils.FormatDate, predictEdbInfoData[lenPredictEdbInfoData-1].DataTime, time.Local)
 				if startDate.Before(tmpDataEndTime) {
 					startDate = tmpDataEndTime
@@ -1019,69 +1026,141 @@ 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) {
-				// 季度日期就写入,否则不写入
-				if currDate.Month() == 3 || currDate.Month() == 6 || currDate.Month() == 9 || currDate.Month() == 12 {
+		case "周度":
+			for i := 1; i <= endNum; i++ {
+				currDate := startDate.AddDate(0, 0, i*7)
+				dayList = append(dayList, currDate)
+			}
+		case "旬度":
+			currDate := startDate
+			for i := 1; len(dayList) < endNum; i++ {
+				currDate = currDate.AddDate(0, 0, 1)
+				nextDate := currDate.AddDate(0, 0, 1)
+				//每个月的10号、20号、最后一天,那么就写入
+				if nextDate.Day() == 11 || nextDate.Day() == 21 || nextDate.Day() == 1 {
 					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 {
+		case "月度":
+			currDate := startDate
+			for i := 0; i <= endNum; i++ {
+				currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+				if !currDate.Equal(startDate) {
 					dayList = append(dayList, currDate)
 				}
+				currDate = currDate.AddDate(0, 0, 1)
 			}
-			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 "季度":
+			currDate := startDate
+			endNum = endNum * 3
+			for i := 0; i <= endNum; i++ {
+				currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+				if currDate.After(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 "半年度":
+			currDate := startDate
+			endNum = endNum * 6
+			for i := 0; i <= endNum; i++ {
+				currDate = time.Date(currDate.Year(), currDate.Month(), 1, 0, 0, 0, 0, time.Now().Location()).AddDate(0, 1, -1)
+				if currDate.After(startDate) {
+					// 季度日期就写入,否则不写入
+					if currDate.Month() == 6 || currDate.Month() == 12 {
+						dayList = append(dayList, currDate)
+					}
+				}
+				currDate = currDate.AddDate(0, 0, 1)
+			}
+		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)
 			}
 		}
@@ -1154,7 +1233,7 @@ func GetPredictDataListByPredictEdbConfList(edbInfo, sourceEdbInfoItem *EdbInfo,
 	var predictMinValue, predictMaxValue float64
 	// 如果有配置的预测规则,那么就进行预测
 	if len(predictEdbConfList) > 0 {
-		predictDataList, predictMinValue, predictMaxValue, err = GetChartPredictEdbInfoDataListByConfList(predictEdbConfList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, edbInfo.Frequency, edbInfo.DataDateType, allDataList)
+		predictDataList, predictMinValue, predictMaxValue, err = GetChartPredictEdbInfoDataListByConfList(predictEdbConfList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, edbInfo.Frequency, edbInfo.DataDateType, edbInfo.EndDateType, allDataList)
 		if err != nil {
 			return
 		}

+ 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, predictEdbInfo.EndDateType, rule.EndNum)
 		if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
 			return
 		}

+ 4 - 0
models/predict_edb_conf.go

@@ -18,6 +18,7 @@ type AddPredictEdbInfoReq struct {
 	MaxValue        float64      `description:"最大值"`
 	MinValue        float64      `description:"最小值"`
 	DataDateType    string       `description:"日期类型,枚举值:交易日、自然日"`
+	EndDateType     int          `description:"截止日期类型:0:未来日期,1未来期数"`
 }
 
 // RuleConfig 预测规则配置
@@ -27,6 +28,7 @@ type RuleConfig struct {
 	EmptyType    int              `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
 	MaxEmptyType int              `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
 	EndDate      string           `description:"截止日期"`
+	EndNum       int              `description:"截止期数"`
 	EdbInfoIdArr []EdbInfoFromTag `description:"指标信息"`
 }
 
@@ -48,6 +50,7 @@ type PredictEdbConf struct {
 	EmptyType        int       `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
 	MaxEmptyType     int       `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
 	EndDate          time.Time `description:"截止日期"`
+	EndNum           int       `description:"截止期数"`
 	ModifyTime       time.Time `description:"修改时间"`
 	CreateTime       time.Time `description:"添加时间"`
 }
@@ -63,6 +66,7 @@ type PredictEdbConfAndData struct {
 	EmptyType        int                  `description:"空值处理类型(0查找前后35天,1不计算,2前值填充,3后值填充,4等于0)"`
 	MaxEmptyType     int                  `description:"MAX、MIN公式空值处理类型(1、等于0;2、跳过空值)"`
 	EndDate          time.Time            `description:"截止日期"`
+	EndNum           int                  `description:"截止期数"`
 	ModifyTime       time.Time            `description:"修改时间"`
 	CreateTime       time.Time            `description:"添加时间"`
 	DataList         []*EdbInfoSearchData `description:"动态数据"`

+ 1 - 0
models/predict_edb_data_base.go

@@ -129,6 +129,7 @@ func AddPredictEdb(item *EdbInfo, calculateMappingList []*EdbInfoCalculateMappin
 			FixedValue:       v.FixedValue,
 			Value:            v.Value,
 			EndDate:          v.EndDate,
+			EndNum:           v.EndNum,
 			ModifyTime:       v.ModifyTime,
 			CreateTime:       v.CreateTime,
 			DataList:         resultDataList,

+ 7 - 1
models/predict_edb_info_rule.go

@@ -1193,6 +1193,7 @@ type RuleLineNhConf struct {
 	EndDate   string `description:"结束日期"`
 	MoveDay   int    `description:"移动天数"`
 	EdbInfoId int    `description:"指标id"`
+	DateType  int    `description:"时间类型:0:开始日期至截止日期,1开始日期-至今"`
 }
 
 //	GetChartPredictEdbInfoDataListByRuleLineNh 根据 一元线性拟合 的计算规则获取预测数据
@@ -1249,7 +1250,12 @@ func getCalculateNhccData(secondDataList []*EdbInfoSearchData, ruleConf RuleLine
 	firstEdbInfoId := ruleConf.EdbInfoId
 	moveDay := ruleConf.MoveDay
 	startDate, _ := time.ParseInLocation(utils.FormatDate, ruleConf.StartDate, time.Local)
-	endDate, _ := time.ParseInLocation(utils.FormatDate, ruleConf.EndDate, time.Local)
+	var endDate time.Time
+	if ruleConf.DateType == 0 {
+		endDate, _ = time.ParseInLocation(utils.FormatDate, ruleConf.EndDate, time.Local)
+	} else {
+		endDate, _ = time.ParseInLocation(utils.FormatDate, time.Now().Format(utils.FormatDate), time.Local)
+	}
 
 	//查询当前指标现有的数据
 	edbInfo, err := GetEdbInfoById(firstEdbInfoId)