浏览代码

获取预测指标日期

xyxie 5 月之前
父节点
当前提交
66cbd66e94
共有 1 个文件被更改,包括 31 次插入21 次删除
  1. 31 21
      models/edb_info.go

+ 31 - 21
models/edb_info.go

@@ -1104,8 +1104,9 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
 				dayList = append(dayList, currDate)
 			}
 		case "旬度":
-			for i := 1; i <= endNum; i++ {
-				currDate := startDate.AddDate(0, 0, i*10)
+			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 {
@@ -1113,31 +1114,40 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency, dataDateType
 				}
 			}
 		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)
+			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)
 			}
+
 		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 := 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 "半年度":
-			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 := 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++ {