Browse Source

删除指标时,增加判断是否被相关性图表引用

xyxie 4 months ago
parent
commit
0e5f69fcdd
2 changed files with 33 additions and 0 deletions
  1. 8 0
      models/data_manage/chart_info_correlation.go
  2. 25 0
      services/data/edb_classify.go

+ 8 - 0
models/data_manage/chart_info_correlation.go

@@ -398,3 +398,11 @@ type FactorCorrelationEditDetail struct {
 	CorrelationConfig CorrelationConfig                      `description:"相关性基础配置"`
 	CorrelationMatrix []FactorEdbSeriesCorrelationMatrixItem `description:"相关性矩阵"`
 }
+
+func (m *ChartInfoCorrelation) GetChartEdbMappingCount(edbInfoId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT COUNT(1) AS count FROM %s WHERE edb_info_id_first=? or edb_info_id_second=?`
+	sql = fmt.Sprintf(sql, m.TableName())
+	err = o.Raw(sql, edbInfoId, edbInfoId).QueryRow(&count)
+	return
+}

+ 25 - 0
services/data/edb_classify.go

@@ -593,6 +593,19 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 			tipsMsg = "当前指标已用作画图,不可删除"
 			return
 		}
+		// 查询是否用于相关性图表
+		correlationChart := new(data_manage.ChartInfoCorrelation)
+		correlationChartCount, tmpErr := correlationChart.GetChartEdbMappingCount(edbInfoId)
+		if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+			errMsg = "删除失败"
+			err = errors.New("判断指标是否被用于相关性图表失败,Err:" + tmpErr.Error())
+			return
+		}
+		if correlationChartCount > 0 {
+			deleteStatus = 3
+			tipsMsg = "当前指标已用作画图,不可删除"
+			return
+		}
 		//判断指标是否用于计算
 		{
 			calculateCount, tmpErr := data_manage.GetEdbInfoCalculateMappingCount(edbInfoId)
@@ -811,6 +824,18 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 			errMsg = "当前指标已用作画图,不可删除"
 			return
 		}
+		// 查询是否用于相关性图表
+		correlationChart := new(data_manage.ChartInfoCorrelation)
+		correlationChartCount, tmpErr := correlationChart.GetChartEdbMappingCount(edbInfoId)
+		if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+			errMsg = "删除失败"
+			err = errors.New("判断指标是否被用于相关性图表失败,Err:" + tmpErr.Error())
+			return
+		}
+		if correlationChartCount > 0 {
+			errMsg = "当前指标已用作画图,不可删除"
+			return
+		}
 
 		//如果是普通指标,那么还需要判断是否被预测指标作为源指标
 		if edbInfo.EdbInfoType == 0 {