|
@@ -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)
|
|
|
}
|
|
|
}
|