Просмотр исходного кода

计算指标映射关系去重复

kobe6258 6 дней назад
Родитель
Сommit
b9a97d3fda
1 измененных файлов с 15 добавлено и 1 удалено
  1. 15 1
      logic/predict_edb.go

+ 15 - 1
logic/predict_edb.go

@@ -483,10 +483,23 @@ func AddPredictEdbInfo(sourceEdbInfoId, classifyId int, edbName, dataDateType st
 
 
 		predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)
 		predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)
 	}
 	}
+	//calculateMappingList是映射关系,只需要记录一条,因此对list需要去重复
+	calculateMappingList = RemoveDuplicateCalculateMappingList(calculateMappingList)
 	err, errMsg = models.AddPredictEdb(edbInfo, calculateMappingList, predictEdbConfList, calculateRuleMap)
 	err, errMsg = models.AddPredictEdb(edbInfo, calculateMappingList, predictEdbConfList, calculateRuleMap)
 
 
 	return
 	return
 }
 }
+func RemoveDuplicateCalculateMappingList(list []*models.EdbInfoCalculateMapping) (newList []*models.EdbInfoCalculateMapping) {
+	newList = make([]*models.EdbInfoCalculateMapping, 0)
+	tmpMap := make(map[int]bool)
+	for _, v := range list {
+		if _, ok := tmpMap[v.FromEdbInfoId]; !ok {
+			tmpMap[v.FromEdbInfoId] = true
+			newList = append(newList, v)
+		}
+	}
+	return
+}
 
 
 // EditPredictEdbInfo 编辑预测指标
 // EditPredictEdbInfo 编辑预测指标
 func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string, endDateType int, ruleList []models.RuleConfig, minValue, maxValue float64, lang string) (edbInfo *models.EdbInfo, err error, errMsg string) {
 func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string, endDateType int, ruleList []models.RuleConfig, minValue, maxValue float64, lang string) (edbInfo *models.EdbInfo, err error, errMsg string) {
@@ -956,7 +969,8 @@ func EditPredictEdbInfo(edbInfoId, classifyId int, edbName, dataDateType string,
 
 
 		predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)
 		predictEdbConfList = append(predictEdbConfList, tmpPredictEdbConf)
 	}
 	}
-
+	//编辑的时候也需要去重复calcuateMappingList
+	calculateMappingList = RemoveDuplicateCalculateMappingList(calculateMappingList)
 	err, errMsg = models.EditPredictEdb(edbInfo, updateEdbInfoCol, calculateMappingList, predictEdbConfList, calculateRuleMap)
 	err, errMsg = models.EditPredictEdb(edbInfo, updateEdbInfoCol, calculateMappingList, predictEdbConfList, calculateRuleMap)
 
 
 	return
 	return