浏览代码

fix:修复拟合残差时,AB指标互换位置时的bug

Roc 2 年之前
父节点
当前提交
05b643dfb8
共有 1 个文件被更改,包括 21 次插入12 次删除
  1. 21 12
      models/edb_data_calculate_nhcc.go

+ 21 - 12
models/edb_data_calculate_nhcc.go

@@ -227,9 +227,9 @@ func EditCalculateNhcc(req *EdbInfoCalculateBatchEditReq, edbInfo, firstEdbInfo,
 	if req.Formula != nowEdbInfo.CalculateFormula {
 		isNeedCalculateData = true
 	}
-	//第一个指标数据
+	var isDeleteA, isDeleteB bool
+	// 如果指标变了,那么需要删除关系
 	{
-		// 如果指标变了,那么需要删除关系,并重新计算
 		if existItemA.FromEdbInfoId != firstEdbInfo.EdbInfoId {
 			//删除之前的A指标关联关系
 			sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id = ?`
@@ -238,7 +238,24 @@ func EditCalculateNhcc(req *EdbInfoCalculateBatchEditReq, edbInfo, firstEdbInfo,
 				err = fmt.Errorf("删除指标A关联关系失败,Err:" + err.Error())
 				return
 			}
-
+			isDeleteA = true
+		}
+		//并重新计算
+		if existItemB.FromEdbInfoId != secondEdbInfo.EdbInfoId {
+			//删除之前的B指标关联关系
+			sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id = ?`
+			_, err = to.Raw(sql, edbInfo.EdbInfoId, existItemB.FromEdbInfoId).Exec()
+			if err != nil {
+				err = fmt.Errorf("删除指标B关联关系失败,Err:" + err.Error())
+				return
+			}
+			isDeleteB = true
+		}
+	}
+	//第一个指标数据
+	{
+		// 如果指标变了,那么需要删除关系,并重新计算
+		if isDeleteA {
 			//添加新的指标关系
 			{
 				existItemA = &EdbInfoCalculateMapping{
@@ -282,15 +299,7 @@ func EditCalculateNhcc(req *EdbInfoCalculateBatchEditReq, edbInfo, firstEdbInfo,
 	//第二个指标数据
 	{
 		// 如果指标变了,那么需要删除关系,并重新计算
-		if existItemB.FromEdbInfoId != secondEdbInfo.EdbInfoId {
-			//删除之前的B指标关联关系
-			sql := ` DELETE FROM edb_info_calculate_mapping WHERE edb_info_id = ? and from_edb_info_id = ?`
-			_, err = to.Raw(sql, edbInfo.EdbInfoId, existItemB.FromEdbInfoId).Exec()
-			if err != nil {
-				err = fmt.Errorf("删除指标B关联关系失败,Err:" + err.Error())
-				return
-			}
-
+		if isDeleteB {
 			// 添加新的指标关联关系
 			existItemB = &EdbInfoCalculateMapping{
 				EdbInfoCalculateMappingId: 0,