Ver código fonte

add:相关性分析只看我

zqbao 1 mês atrás
pai
commit
d2b55cdd2e

+ 9 - 0
controllers/data_manage/correlation/correlation_chart_classify.go

@@ -7,6 +7,7 @@ import (
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/system"
 	"eta/eta_api/services/data"
+	"eta/eta_api/services/data/correlation"
 	correlationServ "eta/eta_api/services/data/correlation"
 	"eta/eta_api/services/data/data_manage_permission"
 	"eta/eta_api/utils"
@@ -135,6 +136,14 @@ func (this *CorrelationChartClassifyController) ChartClassifyList() {
 			return nodeAll[i].Sort < nodeAll[j].Sort
 		})
 	}
+	if isShowMe {
+		nodeAll, err = correlation.GetCorrelationClassifyByIsMe(this.SysUser.AdminId, parentId, nodeAll)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取我的分类失败,Err:" + err.Error()
+			return
+		}
+	}
 
 	resp.AllNodes = nodeAll
 	br.Ret = 200

+ 110 - 0
services/data/correlation/correlation_chart_classify.go

@@ -0,0 +1,110 @@
+package correlation
+
+import (
+	"errors"
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/utils"
+)
+
+func GetCorrelationClassifyByIsMe(adminId, parentId int, classifyList []*data_manage.ChartClassifyItems) (list []*data_manage.ChartClassifyItems, err error) {
+	chartInfoList, err := data_manage.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_CORRELATION}, adminId)
+	if err != nil {
+		return
+	}
+	classifyIdList := make([]int, 0)
+	for _, chartInfo := range chartInfoList {
+		if chartInfo.ChartClassifyId > 0 {
+			classifyIdList = append(classifyIdList, chartInfo.ChartClassifyId)
+		}
+	}
+	if parentId > 0 {
+		for _, v := range classifyList {
+			if v.ChartClassifyId > 0 && v.ChartInfoId == 0 {
+				classifyItems, _, er := GetChildClassifyByClassifyId(v.ChartClassifyId)
+				if er != nil {
+					err = er
+					return
+				}
+				existClassifyMap := make(map[int]struct{})
+				for _, classify := range classifyItems {
+					existClassifyMap[classify.ChartClassifyId] = struct{}{}
+				}
+				for _, chart := range chartInfoList {
+					if _, ok := existClassifyMap[chart.ChartClassifyId]; ok {
+						list = append(list, v)
+						break
+					}
+				}
+			} else {
+				list = append(list, v)
+			}
+		}
+	} else {
+		chartClassifyList, er := data_manage.GetChartClassifyByIdList(classifyIdList)
+		if er != nil {
+			err = er
+			return
+		}
+
+		existClassifyIdMap := make(map[int]struct{})
+		for _, classify := range chartClassifyList {
+			existClassifyIdMap[classify.RootId] = struct{}{}
+		}
+
+		for _, classify := range classifyList {
+			if _, ok := existClassifyIdMap[classify.ChartClassifyId]; ok {
+				list = append(list, classify)
+			}
+		}
+	}
+	return
+}
+
+func GetChildClassifyByClassifyId(targetClassifyId int) (targetList []*data_manage.ChartClassifyItems, errMsg string, err error) {
+	//判断是否是挂在顶级目录下
+	targetClassify, err := data_manage.GetChartClassifyById(targetClassifyId)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			errMsg = "当前分类不存在"
+			err = errors.New(errMsg)
+			return
+		}
+		errMsg = "获取失败"
+		err = errors.New("获取分类信息失败,Err:" + err.Error())
+		return
+	}
+	orderStr := ` order by level asc, sort asc, classify_id asc`
+	tmpList, err := data_manage.GetChartClassifyByRootIdLevel(targetClassify.RootId, targetClassify.Source, orderStr)
+	if err != nil {
+		errMsg = "获取失败"
+		err = errors.New("获取数据失败,Err:" + err.Error())
+		return
+	}
+	idMap := make(map[int]struct{})
+	if len(tmpList) > 0 {
+		for _, v := range tmpList {
+			if v.ChartClassifyId == targetClassify.ChartClassifyId {
+				idMap[v.ChartClassifyId] = struct{}{}
+			}
+		}
+		for _, v := range tmpList {
+			if _, ok := idMap[v.ParentId]; ok {
+				idMap[v.ChartClassifyId] = struct{}{}
+			}
+		}
+		for _, v := range tmpList {
+			if _, ok := idMap[v.ChartClassifyId]; ok {
+				targetItem := new(data_manage.ChartClassifyItems)
+				targetItem.ChartClassifyId = v.ChartClassifyId
+				targetItem.ParentId = v.ParentId
+				targetItem.UniqueCode = v.UniqueCode
+				targetItem.Level = v.Level
+				targetItem.ChartClassifyName = v.ChartClassifyName
+				targetItem.IsJoinPermission = v.IsJoinPermission
+				targetList = append(targetList, targetItem)
+			}
+		}
+	}
+
+	return
+}