Ver Fonte

Merge branch 'feature/eta1.2.0_edb_calculate' into debug

xyxie há 1 ano atrás
pai
commit
567d25bdba
2 ficheiros alterados com 21 adições e 26 exclusões
  1. 21 11
      controllers/base_from_predict_calculate.go
  2. 0 15
      models/base_from_calculate.go

+ 21 - 11
controllers/base_from_predict_calculate.go

@@ -106,11 +106,18 @@ func addPredictCalculate(br *models.BaseResponse, req models.EdbInfoCalculateSav
 		formulaStr += v.FromTag + ","
 		edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
 	}
-	formulaMap := utils.CheckFormula(req.CalculateFormula)
-	for _, v := range formulaMap {
-		if !strings.Contains(formulaStr, v) {
-			br.Msg = "公式错误,请重新填写"
-			return
+	formulaSlice, err := utils.CheckFormulaJson(req.CalculateFormula)
+	if err != nil {
+		br.Msg = "公式格式错误,请重新填写"
+		return
+	}
+	for _, formula := range formulaSlice {
+		formulaMap := utils.CheckFormula(formula)
+		for _, v := range formulaMap {
+			if !strings.Contains(formulaStr, v) {
+				br.Msg = "公式错误,请重新填写"
+				return
+			}
 		}
 	}
 
@@ -173,11 +180,14 @@ func addPredictCalculate(br *models.BaseResponse, req models.EdbInfoCalculateSav
 		}
 	}
 
-	//预先计算,判断公式是否正常
-	ok, _ := models.CheckFormula2(edbInfoList, formulaMap, calculateFormula, edbInfoIdBytes)
-	if !ok {
-		br.Msg = "生成计算指标失败,请使用正确的计算公式"
-		return
+	for _, v := range formulaSlice {
+		formulaMap := utils.CheckFormula(v)
+		//预先计算,判断公式是否正常
+		ok, _ := models.CheckFormula2(edbInfoList, formulaMap, v, edbInfoIdBytes)
+		if !ok {
+			br.Msg = "生成计算指标失败,请使用正确的计算公式"
+			return
+		}
 	}
 
 	// 指标入库
@@ -309,7 +319,7 @@ func editPredictCalculate(br *models.BaseResponse, req models.EdbInfoCalculateSa
 	isExist := utils.Rc.IsExist(redisKey)
 	if isExist {
 		br.Msg = "指标正在处理,请勿重复提交"
-		return
+		//	return
 	} else {
 		//设置3分钟缓存
 		utils.Rc.SetNX(redisKey, 1, time.Second*300)

+ 0 - 15
models/base_from_calculate.go

@@ -859,21 +859,6 @@ func handleDateDataMapZero(saveDataMap map[string]map[int]float64, date string,
 	return
 }
 
-func GetFormulaMaxMinReplace(index, edbInfoId int, formulaStr string, edbInfoIdBytes []string, formulaMap map[string]string, valArr map[int]float64) (formulaResult string, isReplace bool) {
-	formulaStr = GetMaxMinEdbInfo(formulaStr)
-	formulaResult = formulaStr
-	dKey := edbInfoIdBytes[index]
-	if _, ok := formulaMap[dKey]; ok { //公式中存在
-		// todo 判断公式中存在max、min,如果存在,则值从valArrMax中获取,其余的值从valArr中获取
-		if val, valOk := valArr[edbInfoId]; valOk { //值存在
-			dvStr := fmt.Sprintf("%v", val)
-			formulaResult = strings.Replace(formulaStr, dKey, dvStr, -1)
-			isReplace = true
-		}
-	}
-	return
-}
-
 func GetMaxMinEdbInfo(formula string) string {
 	//formula := "A+min(A,B,max(A,C))"
 	// todo 无法处理max里嵌套max或者min的情况