Sfoglia il codice sorgente

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

xyxie 1 giorno fa
parent
commit
399fe79a11

+ 151 - 70
controllers/data_manage/predict_edb_info.go

@@ -427,31 +427,56 @@ func (this *PredictEdbInfoController) Add() {
 	ruleList := make([]request.RuleConfig, 0)
 	{
 		ruleMap := make(map[string]request.RuleConfig)
+		ruleEndNumSortMap := make(map[int]request.RuleConfig)
 		dateIntList := make([]int64, 0)
+		endNumList := make([]int, 0)
 		for _, v := range req.RuleList {
-			confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
-			if err != nil {
-				br.Msg = "配置项中时间异常,请重新选择"
-				br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
-				br.IsSendEmail = false
-				return
+			if req.EndDateType == 0 {
+				confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
+				if err != nil {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
+					br.IsSendEmail = false
+					return
+				}
+				dateIntList = append(dateIntList, confEndDate.Unix())
+				ruleMap[v.EndDate] = v
+			} else {
+				if _, ok := ruleEndNumSortMap[v.EndNum]; ok {
+					br.Msg = "所选期数不能和其他时间段相同"
+					return
+				}
+				endNumList = append(endNumList, v.EndNum)
+				ruleEndNumSortMap[v.EndNum] = v
 			}
-			dateIntList = append(dateIntList, confEndDate.Unix())
-			ruleMap[v.EndDate] = v
-		}
-		sort.Slice(dateIntList, func(i, j int) bool {
-			return dateIntList[i] < dateIntList[j]
-		})
-		for _, dateInt := range dateIntList {
-			currDateTime := time.Unix(dateInt, 0)
-			item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
-			if !ok {
-				br.Msg = "配置项中时间异常,请重新选择"
-				br.ErrMsg = "配置项中时间异常,请重新选择"
-				br.IsSendEmail = false
-				return
+		}
+		if req.EndDateType == 0 {
+			sort.Slice(dateIntList, func(i, j int) bool {
+				return dateIntList[i] < dateIntList[j]
+			})
+			for _, dateInt := range dateIntList {
+				currDateTime := time.Unix(dateInt, 0)
+				item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
+				if !ok {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择"
+					br.IsSendEmail = false
+					return
+				}
+				ruleList = append(ruleList, item)
+			}
+		} else {
+			sort.Ints(endNumList)
+			for _, endNum := range endNumList {
+				item, ok := ruleEndNumSortMap[endNum]
+				if !ok {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择"
+					br.IsSendEmail = false
+					return
+				}
+				ruleList = append(ruleList, item)
 			}
-			ruleList = append(ruleList, item)
 		}
 	}
 	req.RuleList = ruleList
@@ -616,31 +641,56 @@ func (this *PredictEdbInfoController) Edit() {
 	ruleList := make([]request.RuleConfig, 0)
 	{
 		ruleMap := make(map[string]request.RuleConfig)
+		ruleEndNumSortMap := make(map[int]request.RuleConfig)
 		dateIntList := make([]int64, 0)
+		endNumList := make([]int, 0)
 		for _, v := range req.RuleList {
-			confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
-			if err != nil {
-				br.Msg = "配置项中时间异常,请重新选择"
-				br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
-				br.IsSendEmail = false
-				return
+			if req.EndDateType == 0 {
+				confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
+				if err != nil {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
+					br.IsSendEmail = false
+					return
+				}
+				dateIntList = append(dateIntList, confEndDate.Unix())
+				ruleMap[v.EndDate] = v
+			} else {
+				if _, ok := ruleEndNumSortMap[v.EndNum]; ok {
+					br.Msg = "所选期数不能和其他时间段相同"
+					return
+				}
+				endNumList = append(endNumList, v.EndNum)
+				ruleEndNumSortMap[v.EndNum] = v
 			}
-			dateIntList = append(dateIntList, confEndDate.Unix())
-			ruleMap[v.EndDate] = v
-		}
-		sort.Slice(dateIntList, func(i, j int) bool {
-			return dateIntList[i] < dateIntList[j]
-		})
-		for _, dateInt := range dateIntList {
-			currDateTime := time.Unix(dateInt, 0)
-			item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
-			if !ok {
-				br.Msg = "配置项中时间异常,请重新选择"
-				br.ErrMsg = "配置项中时间异常,请重新选择"
-				br.IsSendEmail = false
-				return
+		}
+		if req.EndDateType == 0 {
+			sort.Slice(dateIntList, func(i, j int) bool {
+				return dateIntList[i] < dateIntList[j]
+			})
+			for _, dateInt := range dateIntList {
+				currDateTime := time.Unix(dateInt, 0)
+				item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
+				if !ok {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择"
+					br.IsSendEmail = false
+					return
+				}
+				ruleList = append(ruleList, item)
+			}
+		} else {
+			sort.Ints(endNumList)
+			for _, endNum := range endNumList {
+				item, ok := ruleEndNumSortMap[endNum]
+				if !ok {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择"
+					br.IsSendEmail = false
+					return
+				}
+				ruleList = append(ruleList, item)
 			}
-			ruleList = append(ruleList, item)
 		}
 	}
 	req.RuleList = ruleList
@@ -927,6 +977,7 @@ func (this *PredictEdbInfoController) Detail() {
 				ModifyTime:       v.ModifyTime,
 				CreateTime:       v.CreateTime,
 				CalculateList:    tmpPredictEdbConfCalculateMappingDetail,
+				EndNum:           v.EndNum,
 			}
 			predictEdbConfList = append(predictEdbConfList, tmp)
 		}
@@ -1549,31 +1600,56 @@ func (this *PredictEdbInfoController) ChartDataList() {
 	ruleList := make([]request.RuleConfig, 0)
 	{
 		ruleMap := make(map[string]request.RuleConfig)
+		ruleEndNumSortMap := make(map[int]request.RuleConfig)
 		dateIntList := make([]int64, 0)
+		endNumList := make([]int, 0)
 		for _, v := range req.RuleList {
-			confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
-			if err != nil {
-				br.Msg = "配置项中时间异常,请重新选择"
-				br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
-				br.IsSendEmail = false
-				return
+			if req.EndDateType == 0 {
+				confEndDate, err := time.Parse(utils.FormatDate, v.EndDate)
+				if err != nil {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
+					br.IsSendEmail = false
+					return
+				}
+				dateIntList = append(dateIntList, confEndDate.Unix())
+				ruleMap[v.EndDate] = v
+			} else {
+				if _, ok := ruleEndNumSortMap[v.EndNum]; ok {
+					br.Msg = "所选期数不能和其他时间段相同"
+					return
+				}
+				endNumList = append(endNumList, v.EndNum)
+				ruleEndNumSortMap[v.EndNum] = v
 			}
-			dateIntList = append(dateIntList, confEndDate.Unix())
-			ruleMap[v.EndDate] = v
-		}
-		sort.Slice(dateIntList, func(i, j int) bool {
-			return dateIntList[i] < dateIntList[j]
-		})
-		for _, dateInt := range dateIntList {
-			currDateTime := time.Unix(dateInt, 0)
-			item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
-			if !ok {
-				br.Msg = "配置项中时间异常,请重新选择"
-				br.ErrMsg = "配置项中时间异常,请重新选择"
-				br.IsSendEmail = false
-				return
+		}
+		if req.EndDateType == 0 {
+			sort.Slice(dateIntList, func(i, j int) bool {
+				return dateIntList[i] < dateIntList[j]
+			})
+			for _, dateInt := range dateIntList {
+				currDateTime := time.Unix(dateInt, 0)
+				item, ok := ruleMap[currDateTime.Format(utils.FormatDate)]
+				if !ok {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择"
+					br.IsSendEmail = false
+					return
+				}
+				ruleList = append(ruleList, item)
+			}
+		} else {
+			sort.Ints(endNumList)
+			for _, endNum := range endNumList {
+				item, ok := ruleEndNumSortMap[endNum]
+				if !ok {
+					br.Msg = "配置项中时间异常,请重新选择"
+					br.ErrMsg = "配置项中时间异常,请重新选择"
+					br.IsSendEmail = false
+					return
+				}
+				ruleList = append(ruleList, item)
 			}
-			ruleList = append(ruleList, item)
 		}
 	}
 
@@ -1582,13 +1658,17 @@ func (this *PredictEdbInfoController) ChartDataList() {
 
 	endDateStr := `` //数据的结束日期
 	for _, v := range ruleList {
-		endDateStr = v.EndDate //预测指标的结束日期
-		confEndDate, err := time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
-		if err != nil {
-			br.Msg = "配置项中时间异常,请重新选择"
-			br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
-			return
+		var confEndDate time.Time
+		if v.EndDate != "" {
+			endDateStr = v.EndDate //预测指标的结束日期
+			confEndDate, err = time.ParseInLocation(utils.FormatDate, v.EndDate, time.Local)
+			if err != nil {
+				br.Msg = "配置项中时间异常,请重新选择"
+				br.ErrMsg = "配置项中时间异常,请重新选择,err:" + err.Error()
+				return
+			}
 		}
+
 		// 没有数据,自己瞎测试
 		//switch v.RuleType {
 		//case 3: //3:同比
@@ -1649,6 +1729,7 @@ func (this *PredictEdbInfoController) ChartDataList() {
 			FixedValue:       0,
 			Value:            v.Value,
 			EndDate:          confEndDate,
+			EndNum:           v.EndNum,
 			ModifyTime:       time.Now(),
 			CreateTime:       time.Now(),
 			DataList:         tmpDataList,
@@ -1722,7 +1803,7 @@ func (this *PredictEdbInfoController) ChartDataList() {
 		// 获取预测数据
 		var predictMinValue, predictMaxValue float64
 
-		predictDataList, predictMinValue, predictMaxValue, err, errMsg := data.GetChartPredictEdbInfoDataListByConfList(predictEdbConfAndDataList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, sourceEdbInfoItem.Frequency, req.DataDateType, allDataList)
+		predictDataList, predictMinValue, predictMaxValue, err, errMsg := data.GetChartPredictEdbInfoDataListByConfList(predictEdbConfAndDataList, startDate, sourceEdbInfoItem.LatestDate, endDateStr, req.EndDateType, sourceEdbInfoItem.Frequency, req.DataDateType, allDataList)
 		if err != nil {
 			br.Msg = "获取预测指标数据失败"
 			if errMsg != `` {

+ 1 - 0
models/data_manage/edb_info.go

@@ -68,6 +68,7 @@ type EdbInfo struct {
 	IsJoinPermission int       `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
 	IsStaticData     int       `description:"是否是静态指标,0否,1是"`
 	SetUpdateTime    time.Time `description:"设置启用/禁用刷新状态的时间"`
+	EndDateType      int       `description:"预测指标截止日期类型:0:未来日期,1未来期数"`
 }
 
 type EdbInfoFullClassify struct {

+ 3 - 0
models/data_manage/predict_edb_conf.go

@@ -19,6 +19,7 @@ type PredictEdbConf struct {
 	EndDate          time.Time `description:"截止日期"`
 	ModifyTime       time.Time `description:"修改时间"`
 	CreateTime       time.Time `description:"添加时间"`
+	EndNum           int       `description:"截止期数"`
 }
 
 // PredictEdbConfDetail 预测规则 和 规则相关联的指标
@@ -35,6 +36,7 @@ type PredictEdbConfDetail struct {
 	ModifyTime       time.Time                               `description:"修改时间"`
 	CreateTime       time.Time                               `description:"添加时间"`
 	CalculateList    []*PredictEdbConfCalculateMappingDetail `description:"配置与指标的关联信息"`
+	EndNum           int                                     `description:"截止期数"`
 }
 
 // PredictEdbConfAndData 预测规则和其对应的动态数据
@@ -46,6 +48,7 @@ type PredictEdbConfAndData struct {
 	FixedValue       float64        `description:"固定值"`
 	Value            string         `description:"配置的值"`
 	EndDate          time.Time      `description:"截止日期"`
+	EndNum           int            `description:"截止期数"`
 	ModifyTime       time.Time      `description:"修改时间"`
 	CreateTime       time.Time      `description:"添加时间"`
 	DataList         []*EdbDataList `description:"动态数据"`

+ 9 - 7
models/data_manage/request/predict_edb_info.go

@@ -18,6 +18,7 @@ type PredictEdbInfoChartDataReq struct {
 	RuleList     []RuleConfig `description:"配置规则列表"`
 	DataDateType string       `description:"数据日期类型,枚举值:交易日、自然日"`
 	StartYear    int          `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
+	EndDateType  int          `description:"截止日期类型:0:未来日期,1未来期数"`
 }
 
 // AddPredictEdbInfoReq 添加预测指标请求
@@ -29,13 +30,13 @@ type AddPredictEdbInfoReq struct {
 	RuleType        int          `description:"预测规则,1:最新,2:固定值"`
 	FixedValue      float64      `description:"固定值"`
 	RuleList        []RuleConfig `description:"配置规则列表"`
-
-	DataDateType string  `description:"日期类型,枚举值:交易日、自然日"`
-	MaxValue     float64 `description:"最大值"`
-	MinValue     float64 `description:"最小值"`
-	EdbInfoId    int     `description:"指标ID"`
-	AdminId      int     `description:"添加人id"`
-	AdminName    string  `description:"添加人名称"`
+	DataDateType    string       `description:"日期类型,枚举值:交易日、自然日"`
+	MaxValue        float64      `description:"最大值"`
+	MinValue        float64      `description:"最小值"`
+	EdbInfoId       int          `description:"指标ID"`
+	AdminId         int          `description:"添加人id"`
+	AdminName       string       `description:"添加人名称"`
+	EndDateType     int          `description:"截止日期类型:0:未来日期,1未来期数"`
 }
 
 // RuleConfig 预测规则配置
@@ -45,6 +46,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 []data_manage.EdbInfoFromTag `description:"指标信息"`
 }
 

+ 138 - 55
services/data/predict_edb_info.go

@@ -571,10 +571,14 @@ func MovePredictEdbInfo(edbInfoId, classifyId, prevEdbInfoId, nextEdbInfoId int,
 }
 
 // GetChartPredictEdbInfoDataListByConfList 获取图表的预测指标的未来数据
-func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []data_manage.PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr, frequency, dataDateType string, realPredictEdbInfoData []*data_manage.EdbDataList) (predictEdbInfoData []*data_manage.EdbDataList, minValue, maxValue float64, err error, errMsg string) {
-	endDate, err := time.ParseInLocation(utils.FormatDate, endDateStr, time.Local)
-	if err != nil {
-		return
+func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []data_manage.PredictEdbConfAndData, filtrateStartDateStr, latestDateStr, endDateStr string, endDateType int, frequency, dataDateType string, realPredictEdbInfoData []*data_manage.EdbDataList) (predictEdbInfoData []*data_manage.EdbDataList, minValue, maxValue float64, err error, errMsg string) {
+	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)
@@ -612,13 +616,18 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []data_manage.P
 
 	for _, predictEdbConf := range predictEdbConfList {
 		dataEndTime := endDate
-		if predictEdbConf.EndDate.Before(dataEndTime) {
+		if !predictEdbConf.EndDate.IsZero() && predictEdbConf.EndDate.Before(dataEndTime) {
 			dataEndTime = predictEdbConf.EndDate
 		}
 
 		var tmpMinValue, tmpMaxValue float64 // 当前预测结果中的最大/最小值
+		endNum := predictEdbConf.EndNum - hasEndNum
+		if endNum <= 0 && endDateType == 1 {
+			err = fmt.Errorf("预测期数不能小于等于0")
+			return
+		}
+		dayList := getPredictEdbDayList(startDate, dataEndTime, frequency, dataDateType, endDateType, endNum)
 
-		dayList := getPredictEdbDayList(startDate, dataEndTime, frequency, dataDateType)
 		if len(dayList) <= 0 { // 如果未来没有日期的话,那么就退出当前循环,进入下一个循环
 			continue
 		}
@@ -811,6 +820,9 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []data_manage.P
 		{
 			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
@@ -830,70 +842,141 @@ func GetChartPredictEdbInfoDataListByConfList(predictEdbConfList []data_manage.P
 }
 
 // GetPredictEdbDayList 获取预测指标日期列表
-func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType string) (dayList []time.Time) {
-	//if !utils.InArrayByStr([]string{"日度", "周度", "月度"}, frequency)
+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)
 			}
 		}

+ 7 - 2
services/data/predict_edb_info_rule.go

@@ -1221,6 +1221,7 @@ type RuleLineNhConf struct {
 	EndDate   string `description:"结束日期"`
 	MoveDay   int    `description:"移动天数"`
 	EdbInfoId int    `description:"指标id"`
+	DateType  int    `description:"时间类型:0:开始日期至截止日期,1开始日期-至今"`
 }
 
 //	GetChartPredictEdbInfoDataListByRuleLineNh 根据 一元线性拟合 的计算规则获取预测数据
@@ -1277,8 +1278,12 @@ func getCalculateNhccData(secondDataList []*data_manage.EdbDataList, ruleConf Ru
 	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 := data_manage.GetEdbInfoById(firstEdbInfoId)
 	if err != nil {