|
@@ -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
|
|
|
+}
|