Jelajahi Sumber

删除分类

xyxie 1 bulan lalu
induk
melakukan
bc7cc87f30

+ 28 - 4
controllers/material/material.go

@@ -273,9 +273,21 @@ func (this *MaterialController) DeleteMaterialClassifyCheck() {
 		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
 		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
 		return
 		return
 	}
 	}
-	classifyIds := strings.Split(classifyInfo.LevelPath, ",")
+	// 查找当前分类以及子分类, 截取分类ID之后的字符串
+	// 获取所有子分类
+	childList, e := material.GetMaterialClassifyByLevelPath(classifyInfo.LevelPath)
+	if e != nil {
+		err = fmt.Errorf("保存分类失败,Err:" + e.Error())
+		return
+	}
+	classifyIds := make([]int, 0)
+	if len(childList) > 0 {
+		for _, item := range childList {
+			classifyIds = append(classifyIds, item.ClassifyId)
+		}
+	}
+
 	if len(classifyIds) > 0 {
 	if len(classifyIds) > 0 {
-		//判断素材库分类下,是否含有素材库
 		count, e := material.GetMaterialInfoCountByClassifyIds(classifyIds)
 		count, e := material.GetMaterialInfoCountByClassifyIds(classifyIds)
 		if e != nil {
 		if e != nil {
 			br.Msg = "删除失败"
 			br.Msg = "删除失败"
@@ -349,9 +361,21 @@ func (this *MaterialController) DeleteMaterialClassify() {
 		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
 		br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
 		return
 		return
 	}
 	}
-	classifyIds := strings.Split(classifyInfo.LevelPath, ",")
+	// 查找当前分类以及子分类, 截取分类ID之后的字符串
+	// 获取所有子分类
+	childList, e := material.GetMaterialClassifyByLevelPath(classifyInfo.LevelPath)
+	if e != nil {
+		err = fmt.Errorf("保存分类失败,Err:" + e.Error())
+		return
+	}
+	classifyIds := make([]int, 0)
+	if len(childList) > 0 {
+		for _, item := range childList {
+			classifyIds = append(classifyIds, item.ClassifyId)
+		}
+	}
+
 	if len(classifyIds) > 0 {
 	if len(classifyIds) > 0 {
-		//判断素材库分类下,是否含有素材库
 		count, e := material.GetMaterialInfoCountByClassifyIds(classifyIds)
 		count, e := material.GetMaterialInfoCountByClassifyIds(classifyIds)
 		if e != nil {
 		if e != nil {
 			br.Msg = "删除失败"
 			br.Msg = "删除失败"

+ 1 - 1
models/material/material.go

@@ -202,7 +202,7 @@ type RenameMaterialReq struct {
 	MaterialName string `description:"素材名称"`
 	MaterialName string `description:"素材名称"`
 }
 }
 
 
-func GetMaterialInfoCountByClassifyIds(classifyIds []string) (count int, err error) {
+func GetMaterialInfoCountByClassifyIds(classifyIds []int) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	o := orm.NewOrmUsingDB("rddp")
 	sql := ` SELECT COUNT(1) AS count FROM material WHERE classify_id in(` + utils.GetOrmInReplace(len(classifyIds)) + `)`
 	sql := ` SELECT COUNT(1) AS count FROM material WHERE classify_id in(` + utils.GetOrmInReplace(len(classifyIds)) + `)`
 	err = o.Raw(sql, classifyIds).QueryRow(&count)
 	err = o.Raw(sql, classifyIds).QueryRow(&count)

+ 1 - 1
models/material/material_classify.go

@@ -129,7 +129,7 @@ type DeleteMaterialClassifyReq struct {
 	//	MaterialId int `description:"素材id"`
 	//	MaterialId int `description:"素材id"`
 }
 }
 
 
-func DeleteMaterialClassify(classifyIds []string) (err error) {
+func DeleteMaterialClassify(classifyIds []int) (err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	o := orm.NewOrmUsingDB("rddp")
 	sql := ` DELETE FROM material_classify WHERE classify_id IN(` + utils.GetOrmInReplace(len(classifyIds)) + `) `
 	sql := ` DELETE FROM material_classify WHERE classify_id IN(` + utils.GetOrmInReplace(len(classifyIds)) + `) `
 	_, err = o.Raw(sql, classifyIds).Exec()
 	_, err = o.Raw(sql, classifyIds).Exec()