Forráskód Böngészése

文档管理-文档列表

gmy 7 hónapja
szülő
commit
fdcd4356ea

+ 10 - 0
models/classify.go

@@ -584,3 +584,13 @@ func GetClassifyListByIdList(classifyIdList []int) (items []*Classify, err error
 	_, err = o.Raw(sql, classifyIdList).QueryRows(&items)
 	return
 }
+
+// GetClassifyListByParentId 查询父分类下所有的子分类
+func GetClassifyListByParentId(parentId int) (items []*Classify, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM classify WHERE parent_id = ? `
+
+	_, err = o.Raw(sql, parentId).QueryRows(&items)
+
+	return items, err
+}

+ 33 - 0
services/document_manage_service/document_manage_service.go

@@ -9,6 +9,7 @@ import (
 	"github.com/beego/beego/v2/core/logs"
 	"github.com/google/uuid"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"strconv"
 )
 
 func DocumentClassifyList() ([]models.ClassifyVO, error) {
@@ -123,6 +124,14 @@ func DocumentReportList(documentType int, chartPermissionIdList []string, classi
 		condition = ` and t1.source!=3`
 	}
 	if len(classifyIdList) > 0 {
+		// 递归查询子分类
+		for classifyId := range classifyIdList {
+			childenClassifyIdList, err := GetAllClassifyIdsByParentId(classifyId)
+			if err != nil {
+				return nil, err
+			}
+			classifyIdList = append(classifyIdList, childenClassifyIdList...)
+		}
 		condition += ` and t1.classify_id in (` + utils.GetOrmInReplace(len(classifyIdList)) + `)`
 		for _, classifyId := range classifyIdList {
 			pars = append(pars, classifyId)
@@ -167,6 +176,30 @@ func DocumentReportList(documentType int, chartPermissionIdList []string, classi
 	return &reportPage, nil
 }
 
+// GetAllClassifyIdsByParentId 递归查询子分类
+func GetAllClassifyIdsByParentId(parentId int) ([]string, error) {
+	var classifyIdList []string
+
+	// 获取子分类
+	classifyList, err := models.GetClassifyListByParentId(parentId)
+	if err != nil {
+		return nil, err
+	}
+
+	// 遍历子分类
+	for _, classify := range classifyList {
+		classifyIdList = append(classifyIdList, strconv.Itoa(classify.Id))
+		// 递归调用
+		subClassifyIds, err := GetAllClassifyIdsByParentId(classify.Id)
+		if err != nil {
+			return nil, err
+		}
+		classifyIdList = append(classifyIdList, subClassifyIds...)
+	}
+
+	return classifyIdList, nil
+}
+
 func RuiSiReportList(classifyIdFirst, classifyIdSecond, classifyIdThird int, keyword string, orderField, orderType string, startSize, pageSize int) (*models.ReportListResp, error) {
 	logs.Info("RuiSiReportList")