12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package data
- import (
- "eta_gn/eta_api/models/data_manage"
- "eta_gn/eta_api/utils"
- "fmt"
- "strconv"
- "strings"
- )
- // GetEdbCollectClassifyTreeRecursive 递归获取分类树形结构
- func GetEdbCollectClassifyTreeRecursive(list []*data_manage.EdbCollectClassifyItem, parentId int) []*data_manage.EdbCollectClassifyItem {
- res := make([]*data_manage.EdbCollectClassifyItem, 0)
- for _, v := range list {
- if v.ParentId == parentId {
- t := GetEdbCollectClassifyTreeRecursive(list, v.ClassifyId)
- if len(t) > 0 {
- v.Children = t
- }
- res = append(res, v)
- }
- }
- return res
- }
- // GetEdbCollectClassifyChildIds 获取分类的子分类IDs
- func GetEdbCollectClassifyChildIds(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.EdbCollectClassify)
- 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.EdbCollectClassifyId] {
- continue
- }
- pathArr := strings.Split(v.LevelPath, ",")
- if len(pathArr) > 0 && utils.InArrayByStr(pathArr, strClassifyId) {
- classifyIds = append(classifyIds, v.EdbCollectClassifyId)
- exists[v.EdbCollectClassifyId] = true
- }
- }
- return
- }
|