edb_collect.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package data
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "strconv"
  7. "strings"
  8. )
  9. func GetEdbCollectClassifyTreeRecursive(list []*data_manage.EdbCollectClassifyItem, parentId int) []*data_manage.EdbCollectClassifyItem {
  10. res := make([]*data_manage.EdbCollectClassifyItem, 0)
  11. for _, v := range list {
  12. if v.ParentId == parentId {
  13. t := GetEdbCollectClassifyTreeRecursive(list, v.ClassifyId)
  14. if len(t) > 0 {
  15. v.Children = t
  16. }
  17. res = append(res, v)
  18. }
  19. }
  20. return res
  21. }
  22. func GetEdbCollectClassifyChildIds(classifyId, adminId int, selfInclude bool) (classifyIds []int, err error) {
  23. exists := make(map[int]bool)
  24. if selfInclude {
  25. exists[classifyId] = true
  26. classifyIds = append(classifyIds, classifyId)
  27. }
  28. classifyOb := new(data_manage.EdbCollectClassify)
  29. cond := fmt.Sprintf(` AND %s = ?`, classifyOb.Cols().SysUserId)
  30. pars := make([]interface{}, 0)
  31. pars = append(pars, adminId)
  32. list, e := classifyOb.GetItemsByCondition(cond, pars, []string{}, fmt.Sprintf(`%s ASC`, classifyOb.Cols().Sort))
  33. if e != nil {
  34. err = fmt.Errorf("获取用户收藏分类失败, %v", e)
  35. return
  36. }
  37. strClassifyId := strconv.Itoa(classifyId)
  38. for _, v := range list {
  39. if v.LevelPath == "" {
  40. continue
  41. }
  42. if exists[v.EdbCollectClassifyId] {
  43. continue
  44. }
  45. pathArr := strings.Split(v.LevelPath, ",")
  46. if len(pathArr) > 0 && utils.InArrayByStr(pathArr, strClassifyId) {
  47. classifyIds = append(classifyIds, v.EdbCollectClassifyId)
  48. exists[v.EdbCollectClassifyId] = true
  49. }
  50. }
  51. return
  52. }