package data import ( "eta_gn/eta_api/models/data_manage" "eta_gn/eta_api/utils" "fmt" "strconv" "strings" ) // GetChartCollectClassifyTreeRecursive 递归获取分类树形结构 func GetChartCollectClassifyTreeRecursive(list []*data_manage.ChartCollectClassifyItem, parentId int) []*data_manage.ChartCollectClassifyItem { res := make([]*data_manage.ChartCollectClassifyItem, 0) for _, v := range list { if v.ParentId == parentId { t := GetChartCollectClassifyTreeRecursive(list, v.ClassifyId) if len(t) > 0 { v.Children = t } res = append(res, v) } } return res } // GetChartCollectClassifyChildIds 获取分类的子分类IDs func GetChartCollectClassifyChildIds(classifyId, adminId int, selfInclude bool) (classifyIds []int, err error) { // DM就不用FIND_IN_SET去查了, 从分类的LevelPath中遍历出来 exists := make(map[int]bool) if selfInclude { exists[classifyId] = true classifyIds = append(classifyIds, classifyId) } classifyOb := new(data_manage.ChartCollectClassify) cond := fmt.Sprintf(` AND %s = ?`, classifyOb.Cols().SysUserId) pars := make([]interface{}, 0) pars = append(pars, adminId) list, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf(`%s ASC`, classifyOb.Cols().Sort)) if e != nil { err = fmt.Errorf("获取用户收藏分类失败, %v", e) return } strClassifyId := strconv.Itoa(classifyId) for _, v := range list { if v.LevelPath == "" { continue } if exists[v.ChartCollectClassifyId] { continue } pathArr := strings.Split(v.LevelPath, ",") if len(pathArr) > 0 && utils.InArrayByStr(pathArr, strClassifyId) { classifyIds = append(classifyIds, v.ChartCollectClassifyId) exists[v.ChartCollectClassifyId] = true } } return }