Browse Source

Merge branch 'dm' into debug

xyxie 1 month ago
parent
commit
86b71a3b27

+ 2 - 2
controllers/data_manage/cross_variety/tag.go

@@ -50,7 +50,7 @@ func (c *TagController) Add() {
 		br.ErrMsg = "添加失败,Err:" + err.Error()
 		return
 	}
-	if item != nil {
+	if item != nil && item.ChartTagId > 0 {
 		br.Msg = "添加失败,标签名称不能重复"
 		br.IsSendEmail = false
 		return
@@ -115,7 +115,7 @@ func (c *TagController) Edit() {
 		br.ErrMsg = "添加失败,Err:" + err.Error()
 		return
 	}
-	if item != nil && item.ChartTagId != req.ChartTagId {
+	if item != nil && item.ChartTagId != req.ChartTagId && item.ChartTagId > 0 {
 		br.Msg = "添加失败,标签名称不能重复"
 		br.IsSendEmail = false
 		return

+ 2 - 2
controllers/data_manage/cross_variety/variety.go

@@ -49,7 +49,7 @@ func (c *VarietyController) Add() {
 		br.ErrMsg = "添加失败,Err:" + err.Error()
 		return
 	}
-	if item != nil {
+	if item != nil && item.ChartVarietyId > 0 {
 		br.Msg = "添加失败,品种名称不能重复"
 		br.IsSendEmail = false
 		return
@@ -114,7 +114,7 @@ func (c *VarietyController) Edit() {
 		br.ErrMsg = "添加失败,Err:" + err.Error()
 		return
 	}
-	if item != nil && item.ChartVarietyId != req.ChartVarietyId {
+	if item != nil && item.ChartVarietyId != req.ChartVarietyId && item.ChartVarietyId > 0 {
 		br.Msg = "添加失败,品种名称不能重复"
 		br.IsSendEmail = false
 		return

+ 1 - 1
controllers/data_manage/supply_analysis/variety.go

@@ -224,7 +224,7 @@ func (this *VarietyController) Edit() {
 		br.ErrMsg = "添加失败,Err:" + err.Error()
 		return
 	}
-	if item != nil && item.VarietyId != req.VarietyId {
+	if item != nil && item.VarietyId != req.VarietyId && item.VarietyId > 0 {
 		br.Msg = "添加失败,品种名称不能重复"
 		br.IsSendEmail = false
 		return

+ 21 - 19
models/sandbox/sandbox_classify.go

@@ -129,25 +129,27 @@ func GetSandboxInfoCountByClassifyId(classifyId int) (count int, err error) {
 	var sql string
 	var pars []interface{}
 	if utils.DbDriverName == utils.DbDriverByDm {
-		sql = `WITH RECURSIVE sandbox_classify_cte (sandbox_classify_id, parent_id) AS (
-			SELECT sandbox_classify_id, parent_id
-			FROM sandbox_classify
-			WHERE parent_id = ?
-			UNION ALL
-			SELECT c.sandbox_classify_id, c.parent_id
-			FROM sandbox_classify c
-			INNER JOIN sandbox_classify_cte ct ON c.parent_id = ct.sandbox_classify_id
-		)
-		SELECT COUNT(1) AS count
-		FROM sandbox a
-		WHERE a.sandbox_classify_id IN (
-			SELECT sandbox_classify_id
-			FROM sandbox_classify_cte
-			UNION
-			SELECT sandbox_classify_id
-			FROM sandbox_classify
-			WHERE sandbox_classify_id = ?
-		)`
+		sql = `WITH RECURSIVE classify_tree AS (
+    -- 基础查询:获取起始节点
+    SELECT sandbox_classify_id, parent_id, 1 as level
+    FROM sandbox_classify
+    WHERE sandbox_classify_id = ?
+    
+    UNION ALL
+    
+    -- 递归查询:获取所有子节点
+    SELECT c.sandbox_classify_id, c.parent_id, t.level + 1
+    FROM sandbox_classify c
+    INNER JOIN classify_tree t ON c.parent_id = t.sandbox_classify_id
+    WHERE c.parent_id IS NOT NULL
+)
+SELECT COUNT(1) AS count 
+FROM sandbox a
+WHERE a.sandbox_classify_id IN (
+    SELECT sandbox_classify_id 
+    FROM classify_tree
+) 
+AND a.is_delete = 0`
 		pars = append(pars, classifyId, classifyId)
 	}else{
 		sql = ` SELECT COUNT(1) AS count FROM sandbox AS a