|
@@ -1128,53 +1128,66 @@ func GetChartClassifyChildrenRecursiveByParentIds(list []*data_manage.ChartClass
|
|
|
return res
|
|
|
}
|
|
|
|
|
|
-func GetChartClassifyByIsMe(adminId, parentId, source int, classifyList []*data_manage.ChartClassifyItems) (list []*data_manage.ChartClassifyItems, err error) {
|
|
|
- chartInfoList, err := data_manage.GetChartInfoByAdminId([]int{source}, adminId)
|
|
|
+// GetChartClassifyRelation 获取图库分类的父级关系 map[classifyId]map[parentId]struct{} classifyId为图库classify_id, map[parentId]struct{}为当前分类id中所有的父级id
|
|
|
+func GetChartClassifyRelation() (classifyRelationMap map[int]map[int]struct{}, err error) {
|
|
|
+ classifyAll, err := data_manage.GetChartClassifyBySource(utils.CHART_SOURCE_DEFAULT)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- classifyIdList := make([]int, 0)
|
|
|
- for _, chartInfo := range chartInfoList {
|
|
|
- if chartInfo.ChartClassifyId > 0 {
|
|
|
- classifyIdList = append(classifyIdList, chartInfo.ChartClassifyId)
|
|
|
+ classifyRelationMap = make(map[int]map[int]struct{})
|
|
|
+ for _, classify := range classifyAll {
|
|
|
+ if classify.ParentId == 0 {
|
|
|
+ classifyRelationMap[classify.ChartClassifyId] = make(map[int]struct{})
|
|
|
+ continue
|
|
|
}
|
|
|
- }
|
|
|
- if parentId > 0 {
|
|
|
- for _, v := range classifyList {
|
|
|
- if v.ChartClassifyId > 0 && v.ChartInfoId == 0 {
|
|
|
- classifyItems, er, _ := GetChildChartClassifyByClassifyId(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
|
|
|
- }
|
|
|
+ if parent, ok := classifyRelationMap[classify.ParentId]; !ok {
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ if _, ok := classifyRelationMap[classify.ChartClassifyId]; !ok {
|
|
|
+ classifyRelationMap[classify.ChartClassifyId] = make(map[int]struct{})
|
|
|
+ classifyRelationMap[classify.ChartClassifyId][classify.ParentId] = struct{}{}
|
|
|
+ for k, v := range parent {
|
|
|
+ classifyRelationMap[classify.ChartClassifyId][k] = v
|
|
|
}
|
|
|
} else {
|
|
|
- list = append(list, v)
|
|
|
+ classifyRelationMap[classify.ChartClassifyId][classify.ParentId] = struct{}{}
|
|
|
+ for k, v := range parent {
|
|
|
+ classifyRelationMap[classify.ChartClassifyId][k] = v
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- chartClassifyList, er := data_manage.GetChartClassifyByIdList(classifyIdList)
|
|
|
- if er != nil {
|
|
|
- err = er
|
|
|
- return
|
|
|
- }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func GetChartClassifyByIsMe(adminId, parentId, source int, classifyList []*data_manage.ChartClassifyItems) (list []*data_manage.ChartClassifyItems, err error) {
|
|
|
+ chartInfoList, err := data_manage.GetChartInfoByAdminId([]int{source}, adminId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- existClassifyIdMap := make(map[int]struct{})
|
|
|
- for _, classify := range chartClassifyList {
|
|
|
- existClassifyIdMap[classify.RootId] = struct{}{}
|
|
|
+ classifyRelation, err := GetChartClassifyRelation()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartInfoRelationClassifyMap := make(map[int]struct{})
|
|
|
+ for _, classify := range chartInfoList {
|
|
|
+ if classify.ChartClassifyId == 0 {
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ if relationClassify, ok := classifyRelation[classify.ChartClassifyId]; ok {
|
|
|
+ for k, v := range relationClassify {
|
|
|
+ chartInfoRelationClassifyMap[k] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- for _, classify := range classifyList {
|
|
|
- if _, ok := existClassifyIdMap[classify.ChartClassifyId]; ok {
|
|
|
+ for _, classify := range classifyList {
|
|
|
+ if classify.ChartInfoId > 0 {
|
|
|
+ list = append(list, classify)
|
|
|
+ } else {
|
|
|
+ if _, ok := chartInfoRelationClassifyMap[classify.ChartClassifyId]; ok {
|
|
|
list = append(list, classify)
|
|
|
}
|
|
|
}
|