Browse Source

删除指标检测表格

xyxie 9 months ago
parent
commit
2ca386f0c7

+ 3 - 2
controllers/data_manage/edb_classify.go

@@ -356,7 +356,7 @@ func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
 		br.IsSendEmail = false
 		return
 	}
-	deleteStatus, tipsMsg, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
+	deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.ErrMsg = errMsg
@@ -429,6 +429,7 @@ func (this *EdbClassifyController) DeleteEdbClassifyCheck() {
 	resp := new(data_manage.ClassifyDeleteCheckResp)
 	resp.DeleteStatus = deleteStatus
 	resp.TipsMsg = tipsMsg
+	resp.TableList = tableList
 	br.Ret = 200
 	br.Msg = "检测成功"
 	br.Success = true
@@ -467,7 +468,7 @@ func (this *EdbClassifyController) DeleteEdbClassify() {
 		return
 	}
 
-	nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
+	nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.ErrMsg = errMsg

+ 3 - 2
controllers/data_manage/predict_edb_classify.go

@@ -302,7 +302,7 @@ func (this *PredictEdbClassifyController) DeleteCheck() {
 		return
 	}
 
-	deleteStatus, tipsMsg, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
+	deleteStatus, tipsMsg, tableList, err, errMsg := data.DeleteCheck(req.ClassifyId, req.EdbInfoId, this.SysUser)
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.ErrMsg = errMsg
@@ -317,6 +317,7 @@ func (this *PredictEdbClassifyController) DeleteCheck() {
 	resp := new(data_manage.ClassifyDeleteCheckResp)
 	resp.DeleteStatus = deleteStatus
 	resp.TipsMsg = tipsMsg
+	resp.TableList = tableList
 	br.Ret = 200
 	br.Msg = "检测成功"
 	br.Success = true
@@ -356,7 +357,7 @@ func (this *PredictEdbClassifyController) Delete() {
 		return
 	}
 
-	nextItem, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
+	nextItem, _, err, errMsg := data.Delete(req.ClassifyId, req.EdbInfoId, sysUser, string(this.Ctx.Input.RequestBody), this.Ctx.Input.URI())
 	if errMsg != `` {
 		br.Msg = errMsg
 		br.ErrMsg = errMsg

+ 4 - 2
models/data_manage/edb_classify.go

@@ -1,6 +1,7 @@
 package data_manage
 
 import (
+	"eta/eta_api/models/data_manage/excel"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
@@ -298,8 +299,9 @@ type EdbClassifyListResp struct {
 }
 
 type ClassifyDeleteCheckResp struct {
-	DeleteStatus int    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:若目录关联指标不可删除,2:确认删除当前目录及包含的子目录吗,3:当前指标已用作画图,不可删除"`
-	TipsMsg      string `description:"提示信息"`
+	DeleteStatus int                    `description:"检测状态:0:默认值,如果为0,继续走其他校验,1:若目录关联指标不可删除,2:确认删除当前目录及包含的子目录吗,3:当前指标已用作画图,不可删除"`
+	TipsMsg      string                 `description:"提示信息"`
+	TableList    []*excel.ExcelBaseInfo `description:"关联的表格"`
 }
 
 type ClassifyDeleteCheckReq struct {

+ 9 - 0
models/data_manage/excel/excel_edb_mapping.go

@@ -89,6 +89,15 @@ func GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId int) (count int, err erro
 	return
 }
 
+func GetNoCustomAnalysisExcelEdbMapping(edbInfoId int) (ids []int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT b.excel_info_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)
+	return
+}
+
 // GetAllExcelEdbMappingByExcelInfoId 根据excel的id获取所有的指标
 func GetAllExcelEdbMappingByExcelInfoId(excelInfoId int) (items []*ExcelEdbMapping, err error) {
 	o := orm.NewOrmUsingDB("data")

+ 23 - 0
models/data_manage/excel/excel_info.go

@@ -52,6 +52,17 @@ type MyExcelInfoList struct {
 	HaveOperaAuth    bool      `description:"是否有数据权限"`
 }
 
+type ExcelBaseInfo struct {
+	ExcelInfoId     int    `orm:"column(excel_info_id);pk"`
+	Source          int    `description:"表格来源,1:excel插件的表格,2:自定义表格,3:混合表格,4:自定义分析,默认:1"`
+	ExcelType       int    `description:"表格类型,1:指标列,2:日期列,默认:1"`
+	ExcelName       string `description:"表格名称"`
+	UniqueCode      string `description:"表格唯一编码"`
+	ExcelClassifyId int    `description:"表格分类id"`
+	SysUserId       int    `description:"操作人id"`
+	SysUserRealName string `description:"操作人真实姓名"`
+}
+
 // AddExcelInfo 新增表格
 func AddExcelInfo(excelInfo *ExcelInfo, excelEdbMappingList []*ExcelEdbMapping) (err error) {
 	o, err := orm.NewOrmUsingDB("data").Begin()
@@ -623,3 +634,15 @@ func ModifyExcelInfoUserIdByOldUserId(oldUserIdList []int, userId int, userName
 	_, err = o.Raw(sql, userId, userName, oldUserIdList).Exec()
 	return
 }
+
+func GetExcelBaseInfoByExcelInfoIdList(excelInfoIdList []int) (items []*ExcelBaseInfo, err error) {
+	num := len(excelInfoIdList)
+	if num <= 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name FROM excel_info WHERE excel_info_id in (` + utils.GetOrmInReplace(num) + `) order by excel_info_id DESC `
+	_, err = o.Raw(sql, excelInfoIdList).QueryRows(&items)
+
+	return
+}

+ 30 - 8
services/data/edb_classify.go

@@ -449,7 +449,7 @@ func EditEdbClassify(classifyId int, classifyName, lang string, sysUser *system.
 }
 
 // DeleteCheck 删除检测
-func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, err error, errMsg string) {
+func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus int, tipsMsg string, tableList []*excel.ExcelBaseInfo, err error, errMsg string) {
 	//删除分类
 	if classifyId > 0 && edbInfoId == 0 {
 		// 查找分类
@@ -579,15 +579,26 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 
 		// 判断指标是否用作表格引用
 		{
-			calculateCount, tmpErr := excel.GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId)
+			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
 				return
 			}
-			if calculateCount > 0 {
+			//英文翻译:
+			//1、当前指标已用作画图,不可删除:The current metric is in use for charting and cannot be deleted
+			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
+			//3、删除失败:Deletion failed
+			//4、知道了:Understood
+			if len(excelIds) > 0 {
 				deleteStatus = 3
-				tipsMsg = "当前指标已添加到表格,不可删除"
+				tipsMsg = "当前指标已被表格引用,不可删除"
+				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
+				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+					errMsg = "删除失败"
+					err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
+					return
+				}
 				return
 			}
 		}
@@ -611,7 +622,7 @@ func DeleteCheck(classifyId, edbInfoId int, sysUser *system.Admin) (deleteStatus
 }
 
 // Delete 删除分类/指标
-func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, err error, errMsg string) {
+func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, requestUrl string) (nextItem *data_manage.EdbInfo, tableList []*excel.ExcelBaseInfo, err error, errMsg string) {
 	//删除分类
 	if classifyId > 0 && edbInfoId == 0 {
 		// 查找分类
@@ -733,14 +744,25 @@ func Delete(classifyId, edbInfoId int, sysUser *system.Admin, requestBody, reque
 
 		// 判断指标是否用作表格引用
 		{
-			calculateCount, tmpErr := excel.GetNoCustomAnalysisExcelEdbMappingCount(edbInfoId)
+			excelIds, tmpErr := excel.GetNoCustomAnalysisExcelEdbMapping(edbInfoId)
 			if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
 				errMsg = "删除失败"
 				err = errors.New("判断指标是否用作表格引用,GetNoCustomAnalysisExcelEdbMappingCount Err:" + tmpErr.Error())
 				return
 			}
-			if calculateCount > 0 {
-				errMsg = "当前指标已添加到表格,不可删除"
+			//英文翻译:
+			//1、当前指标已用作画图,不可删除:The current metric is in use for charting and cannot be deleted
+			//2、当前指标已被表格引用,不可删除:The current metric is referenced by a table and cannot be deleted
+			//3、删除失败:Deletion failed
+			//4、知道了:Understood
+			if len(excelIds) > 0 {
+				errMsg = "当前指标已被表格引用,不可删除"
+				tableList, tmpErr = excel.GetExcelBaseInfoByExcelInfoIdList(excelIds)
+				if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
+					errMsg = "删除失败"
+					err = errors.New("判断指标是否用作表格引用,GetExcelBaseInfoByExcelInfoIdList Err:" + tmpErr.Error())
+					return
+				}
 				return
 			}
 		}

+ 3 - 1
static/ErrMsgConfig.json

@@ -50,5 +50,7 @@
   "系统处理中,请稍后重试!": "The system is processing, please try again later!",
   "固定日期不可为空": "The fixed date cannot be empty",
   "日期数量已达上限!": "The number of dates has reached the limit!",
-  "该品种已在指标库生成指标,不可删除": "This variety has already generated indicators in the index library and cannot be deleted"
+  "该品种已在指标库生成指标,不可删除": "This variety has already generated indicators in the index library and cannot be deleted",
+  "当前指标已用作画图,不可删除": "The current metric is in use for charting and cannot be deleted",
+  "当前指标已被表格引用,不可删除":"The current metric is referenced by a table and cannot be deleted"
 }