Browse Source

fix:个人名下,图表名称允许重复

Roc 1 week ago
parent
commit
9e9e84616f

+ 2 - 2
controllers/data_manage/future_good/future_good_profit_chart_info.go

@@ -742,8 +742,8 @@ func copyProfitChartInfo(oldChartInfo *data_manage.ChartInfo, chartClassifyId in
 	condition += " AND chart_classify_id=? "
 	pars = append(pars, chartClassifyId)
 
-	condition += " AND chart_name=? AND source = ? "
-	pars = append(pars, chartName, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT)
+	condition += " AND chart_name=? AND source = ?  AND sys_suer_id = ? "
+	pars = append(pars, chartName, utils.CHART_SOURCE_FUTURE_GOOD_PROFIT, sysUser.AdminId)
 
 	count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
 	if err != nil {

+ 106 - 6
services/data/chart_info.go

@@ -2224,11 +2224,11 @@ func AddChartInfo(req data_manage.AddChartInfoReq, sysUserId int, sysUserRealNam
 
 		switch lang {
 		case utils.EnLangVersion:
-			condition += " AND chart_name_en = ? AND source = ? "
+			condition += " AND chart_name_en = ? AND source = ? AND sys_suer_id = ? "
 		default:
-			condition += " AND chart_name = ? AND source = ? "
+			condition += " AND chart_name = ? AND source = ? AND sys_suer_id = ? "
 		}
-		pars = append(pars, req.ChartName, utils.CHART_SOURCE_DEFAULT)
+		pars = append(pars, req.ChartName, utils.CHART_SOURCE_DEFAULT, sysUserId)
 
 		count, err = data_manage.GetChartInfoCountByCondition(condition, pars)
 		if err != nil {
@@ -2661,11 +2661,11 @@ func EditChartInfo(req data_manage.EditChartInfoReq, sysUser *system.Admin, lang
 
 		switch lang {
 		case utils.EnLangVersion:
-			condition += " AND chart_name_en = ? AND source = ? "
+			condition += " AND chart_name_en = ? AND source = ? AND sys_suer_id = ? "
 		default:
-			condition += " AND chart_name = ? AND source = ? "
+			condition += " AND chart_name = ? AND source = ? AND sys_suer_id = ? "
 		}
-		pars = append(pars, req.ChartName, utils.CHART_SOURCE_DEFAULT)
+		pars = append(pars, req.ChartName, utils.CHART_SOURCE_DEFAULT, sysUser.AdminId)
 
 		count, err = data_manage.GetChartInfoCountByCondition(condition, pars)
 		if err != nil {
@@ -5034,3 +5034,103 @@ func CheckChartReferencedByOthers(chartInfoIdList []int, chartUniqueCodeList []s
 	noReferenced = true
 	return
 }
+
+// CheckExistByEdbNameAndEdbInfoId
+// @Description: 根据指标名称和指标ID校验库中是否还存在其他同名指标
+// @author: Roc
+// @datetime 2024-04-18 15:01:44
+// @param chartInfoType int
+// @param chartInfoId int
+// @param chartName string
+// @param lang string
+// @return has bool
+// @return err error
+func CheckExistByChartNameAndChartInfoId(source, chartInfoId, userId int, chartName, lang string) (has bool, err error) {
+	// 指标没有入库的情况
+	if chartInfoId == 0 {
+		return checkExistByChartName(source, userId, chartName, lang)
+	}
+
+	//指标已经入库的情况
+	return checkExistByChartNameAndChartInfoId(source, userId, chartInfoId, chartName, lang)
+}
+
+// checkExistByChartName
+// @Description: 根据指标名称校验该指标是否存在库中
+// @author: Roc
+// @datetime 2024-04-18 14:58:52
+// @param source int
+// @param chartName string
+// @param lang string
+// @return has bool
+// @return err error
+func checkExistByChartName(source, userId int, chartName, lang string) (has bool, err error) {
+	var condition string
+	var pars []interface{}
+
+	condition += " AND source=? AND sys_user_id=? "
+	pars = append(pars, source, userId)
+
+	switch lang {
+	case utils.EnLangVersion:
+		condition += " AND chart_name_en = ? "
+	default:
+		condition += " AND chart_name=? "
+	}
+
+	pars = append(pars, chartName)
+
+	count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
+	if err != nil {
+		return
+	}
+
+	if count > 0 {
+		has = true
+		return
+	}
+
+	return
+}
+
+// checkExistByChartNameAndChartInfoId
+// @Description: 根据指标名称和指标ID校验库中是否还存在其他同名指标
+// @author: Roc
+// @datetime 2024-04-18 15:00:19
+// @param source int
+// @param chartInfoId int
+// @param chartName string
+// @param lang string
+// @return has bool
+// @return err error
+func checkExistByChartNameAndChartInfoId(source, userId, chartInfoId int, chartName, lang string) (has bool, err error) {
+	var condition string
+	var pars []interface{}
+
+	condition += " AND source=? AND sys_user_id=? "
+	pars = append(pars, source, userId)
+
+	condition += " AND chart_info_id<>? "
+	pars = append(pars, chartInfoId)
+
+	switch lang {
+	case utils.EnLangVersion:
+		condition += " AND chart_name_en = ? "
+	default:
+		condition += " AND chart_name=? "
+	}
+
+	pars = append(pars, chartName)
+
+	count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
+	if err != nil {
+		return
+	}
+
+	if count > 0 {
+		has = true
+		return
+	}
+
+	return
+}

+ 5 - 5
services/data/correlation/chart_info.go

@@ -782,11 +782,11 @@ func AddChartInfo(req data_manage.AddChartInfoReq, source int, sysUser *system.A
 
 		switch lang {
 		case utils.EnLangVersion:
-			condition += " AND chart_name_en = ? AND source = ? "
+			condition += " AND chart_name_en = ? AND source = ? AND sys_suer_id = ? "
 		default:
-			condition += " AND chart_name=? AND source = ? "
+			condition += " AND chart_name=? AND source = ? AND sys_suer_id = ? "
 		}
-		pars = append(pars, req.ChartName, source)
+		pars = append(pars, req.ChartName, source, sysUser.AdminId)
 		count, tmpErr := data_manage.GetChartInfoCountByCondition(condition, pars)
 		if tmpErr != nil {
 			errMsg = "判断图表名称是否存在失败"
@@ -1034,8 +1034,8 @@ func EditChartInfo(req data_manage.EditChartInfoReq, sysUser *system.Admin, lang
 	{
 		var condition string
 		var pars []interface{}
-		condition += " AND chart_info_id <> ? "
-		pars = append(pars, req.ChartInfoId)
+		condition += " AND chart_info_id <> ? AND sys_suer_id = ? "
+		pars = append(pars, req.ChartInfoId, sysUser.AdminId)
 		switch lang {
 		case utils.EnLangVersion:
 			condition += " AND chart_name_en = ? AND source = ? "

+ 5 - 5
services/data/line_equation/chart_info.go

@@ -411,11 +411,11 @@ func BatchAddChartInfo(batchAddChartReq []request.AddChart, lineChartInfoConfig
 			var pars []interface{}
 			switch lang {
 			case utils.EnLangVersion:
-				condition += " AND chart_name_en = ? AND source = ? "
+				condition += " AND chart_name_en = ? AND source = ? AND sys_suer_id = ? "
 			default:
-				condition += " AND chart_name = ? AND source = ? "
+				condition += " AND chart_name = ? AND source = ? AND sys_suer_id = ?  "
 			}
-			pars = append(pars, v.ChartName, source)
+			pars = append(pars, v.ChartName, source, sysUser.AdminId)
 			count, tmpErr := data_manage.GetChartInfoCountByCondition(condition, pars)
 			if tmpErr != nil {
 				errMsg = "判断图表名称是否存在失败"
@@ -631,8 +631,8 @@ func BatchSaveChartInfo(multipleGraphConfigId int, batchAddChartReq []request.Ad
 		// 判断图表是否存在
 		var condition string
 		var pars []interface{}
-		condition += " AND chart_name=? AND source = ? "
-		pars = append(pars, v.ChartName, source)
+		condition += " AND chart_name=? AND source = ?  AND sys_suer_id = ? "
+		pars = append(pars, v.ChartName, source, sysUser.AdminId)
 
 		// 已经创建了图表的类型
 		if sourceChart, ok := existChartInfoMap[v.Source]; ok {

+ 5 - 5
services/data/line_feature/chart_info.go

@@ -460,11 +460,11 @@ func AddChartInfo(req data_manage.AddChartInfoReq, edbInfoMapping *data_manage.C
 
 		switch lang {
 		case utils.EnLangVersion:
-			condition += " AND chart_name_en = ? AND source = ? "
+			condition += " AND chart_name_en = ? AND source = ? AND sys_suer_id = ? "
 		default:
-			condition += " AND chart_name = ? AND source = ? "
+			condition += " AND chart_name = ? AND source = ? AND sys_suer_id = ? "
 		}
-		pars = append(pars, req.ChartName, source)
+		pars = append(pars, req.ChartName, source, sysUser.AdminId)
 		count, tmpErr := data_manage.GetChartInfoCountByCondition(condition, pars)
 		if tmpErr != nil {
 			errMsg = "判断图表名称是否存在失败"
@@ -610,8 +610,8 @@ func EditChartInfo(req data_manage.EditChartInfoReq, edbInfoMapping *data_manage
 	{
 		var condition string
 		var pars []interface{}
-		condition += " AND chart_info_id <> ? AND source = ?  "
-		pars = append(pars, req.ChartInfoId, chartItem.Source)
+		condition += " AND chart_info_id <> ? AND source = ? AND sys_suer_id = ?  "
+		pars = append(pars, req.ChartInfoId, chartItem.Source, sysUser.AdminId)
 
 		switch lang {
 		case utils.EnLangVersion:

+ 5 - 5
services/data/range_analysis/chart_info.go

@@ -1096,11 +1096,11 @@ func AddChartInfo(req data_manage.AddChartInfoReq, source int, sysUser *system.A
 
 		switch lang {
 		case utils.EnLangVersion:
-			condition += " AND chart_name_en = ? AND source = ? "
+			condition += " AND chart_name_en = ? AND source = ? AND sys_suer_id = ? "
 		default:
-			condition += " AND chart_name=? AND source = ? "
+			condition += " AND chart_name=? AND source = ? AND sys_suer_id = ? "
 		}
-		pars = append(pars, req.ChartName, source)
+		pars = append(pars, req.ChartName, source, sysUser.AdminId)
 		count, tmpErr := data_manage.GetChartInfoCountByCondition(condition, pars)
 		if tmpErr != nil {
 			errMsg = "判断图表名称是否存在失败"
@@ -1355,8 +1355,8 @@ func EditChartInfo(req data_manage.EditChartInfoReq, sysUser *system.Admin, lang
 	{
 		var condition string
 		var pars []interface{}
-		condition += " AND chart_info_id <> ? "
-		pars = append(pars, req.ChartInfoId)
+		condition += " AND chart_info_id <> ? AND sys_suer_id = ? "
+		pars = append(pars, req.ChartInfoId, sysUser.AdminId)
 		switch lang {
 		case utils.EnLangVersion:
 			condition += " AND chart_name_en = ? AND source = ? "