Browse Source

查询是否被平衡表引用

xyxie 9 months ago
parent
commit
5ecf0d75e8
2 changed files with 21 additions and 14 deletions
  1. 8 3
      models/data_manage/excel/excel_edb_mapping.go
  2. 13 11
      services/data/edb_classify.go

+ 8 - 3
models/data_manage/excel/excel_edb_mapping.go

@@ -96,12 +96,17 @@ func GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId int) (count int, err erro
 	return
 }
 
-func GetNoCustomAnalysisExcelEdbMapping(edbInfoId int) (ids []int, err error) {
+type ExcelEdbMappingWithParentIdItem struct {
+	ExcelInfoId int
+	ParentId    int
+}
+
+func GetNoCustomAnalysisExcelEdbMapping(edbInfoId int) (items []ExcelEdbMappingWithParentIdItem, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT b.excel_info_id FROM excel_edb_mapping a 
+	sql := ` SELECT b.excel_info_id, b.parent_id FROM excel_edb_mapping a 
                           join excel_info b on a.excel_info_id=b.excel_info_id
                           WHERE edb_info_id=? AND a.source != 4 AND b.is_delete = 0`
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&ids)
+	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
 	return
 }
 

+ 13 - 11
services/data/edb_classify.go

@@ -557,7 +557,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 			}
 			if calculateCount > 0 {
 				deleteStatus = 4
-				tipsMsg = "当前指标已用作指标运算,不可删除"
+				tipsMsg = "当前指标已用作指标运算,不可删除"
 				return
 			}
 		}
@@ -579,7 +579,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 
 		// 判断指标是否用作表格引用
 		{
-			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
+			tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
@@ -590,9 +590,17 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
 			//3、删除失败:Deletion failed
 			//4、知道了:Understood
-			if len(excelIds) > 0 {
+			if len(tableItems) > 0 {
 				deleteStatus = 6
 				tipsMsg = "当前指标已被表格引用,不可删除"
+				var excelIds []int
+				for _, tableItem := range tableItems {
+					if tableItem.ParentId > 0 {
+						excelIds = append(excelIds, tableItem.ParentId)
+					} else {
+						excelIds = append(excelIds, tableItem.ExcelInfoId)
+					}
+				}
 				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
 				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 					errMsg = "删除失败"
@@ -769,7 +777,7 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 
 		// 判断指标是否用作表格引用
 		{
-			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
+			tableItems, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
@@ -780,14 +788,8 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
 			//3、删除失败:Deletion failed
 			//4、知道了:Understood
-			if len(excelIds) > 0 {
+			if len(tableItems) > 0 {
 				errMsg = "当前指标已被表格引用,不可删除"
-				/*tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
-				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
-					errMsg = "删除失败"
-					err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
-					return
-				}*/
 				return
 			}
 		}