Browse Source

fix:预测指标新增年度预测

Roc 2 years ago
parent
commit
eb49aa03c2
3 changed files with 34 additions and 2 deletions
  1. 16 2
      logic/predict_edb.go
  2. 7 0
      models/edb_info.go
  3. 11 0
      utils/common.go

+ 16 - 2
logic/predict_edb.go

@@ -32,8 +32,8 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName string, ruleList
 			err = errors.New(errMsg)
 			return
 		}
-		if !utils.InArrayByStr([]string{"日度", "周度", "月度"}, sourceEdbInfo.Frequency) {
-			errMsg = "预测指标只支持选择日度、周度、月度的指标"
+		if !utils.InArrayByStr([]string{"日度", "周度", "月度", "年度"}, sourceEdbInfo.Frequency) {
+			errMsg = "预测指标只支持选择日度、周度、月度、年度的指标"
 			err = errors.New(errMsg)
 			return
 		}
@@ -154,6 +154,13 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName string, ruleList
 			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, 9, 11, 12}, v.RuleType) {
+			errMsg = "环比、环差、动态环差、季节性、移动平均同比不支持年度指标"
+			err = errors.New(errMsg)
+			return
+		}
 		switch v.RuleType {
 		case 8: //N期段线性外推值
 			valInt, tmpErr := strconv.Atoi(v.Value)
@@ -434,6 +441,13 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName string, ruleList []mo
 			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, 9, 11, 12}, v.RuleType) {
+			errMsg = "环比、环差、动态环差、季节性、移动平均同比不支持年度指标"
+			err = errors.New(errMsg)
+			return
+		}
 		switch v.RuleType {
 		case 8: //N期段线性外推值
 			valInt, tmpErr := strconv.Atoi(v.Value)

+ 7 - 0
models/edb_info.go

@@ -673,6 +673,13 @@ func getPredictEdbDayList(startDate, endDate time.Time, frequency string) (dayLi
 			}
 			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) {
+				dayList = append(dayList, currDate)
+			}
+		}
 	}
 	return
 }

+ 11 - 0
utils/common.go

@@ -1076,6 +1076,17 @@ func InArrayByStr(idStrList []string, searchId string) (has bool) {
 	return
 }
 
+// InArrayByInt php中的in_array(判断Int类型的切片中是否存在该Int值)
+func InArrayByInt(idStrList []int, searchId int) (has bool) {
+	for _, id := range idStrList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}
+
 // GetOrmInReplace 获取orm的in查询替换?的方法
 func GetOrmInReplace(num int) string {
 	template := make([]string, num)