package range_analysis import ( "eta/eta_api/models/data_manage" "eta/eta_api/services/data" ) func GetClassifyListByIsShowMe(adminId, parentId, source int, classifyList []*data_manage.ChartClassifyItems) (items []*data_manage.ChartClassifyItems, err error) { chartItems, err := data_manage.GetChartInfoBySourceAndAdminId(source, adminId) if err != nil { return } classifyIdList := make([]int, 0) for _, chart := range chartItems { if chart.ChartClassifyId > 0 { classifyIdList = append(classifyIdList, chart.ChartClassifyId) } } if parentId > 0 { for _, v := range classifyList { if v.ChartClassifyId > 0 && v.ChartInfoId == 0 { classifyItems, er, _ := data.GetChildChartClassifyByClassifyId(v.ChartClassifyId) if er != nil { err = er return } existClassifyMap := make(map[int]struct{}) for _, classify := range classifyItems { existClassifyMap[classify.ChartClassifyId] = struct{}{} } for _, edb := range chartItems { if _, ok := existClassifyMap[edb.ChartClassifyId]; ok { items = append(items, v) break } } } else { items = append(items, v) } } } else { tmpClassify, er := data_manage.GetChartClassifyByIdList(classifyIdList) if er != nil { err = er return } existClassifyIdMap := make(map[int]struct{}) for _, classify := range tmpClassify { existClassifyIdMap[classify.RootId] = struct{}{} } for _, classify := range classifyList { if _, ok := existClassifyIdMap[classify.ChartClassifyId]; ok { items = append(items, classify) } } } return }