12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package eta_training_video
- import (
- "hongze/hz_crm_api/models/eta_training_video"
- )
- // GetClassifyTreeRecursive 递归菜单树
- func GetClassifyTreeRecursive(list []*eta_training_video.EtaTrainingVideoClassifyItem, parentId int) []*eta_training_video.EtaTrainingVideoClassifyItem {
- res := make([]*eta_training_video.EtaTrainingVideoClassifyItem, 0)
- for _, v := range list {
- if v.ParentId == parentId {
- v.Children = GetClassifyTreeRecursive(list, v.ClassifyId)
- res = append(res, v)
- }
- }
- return res
- }
- // GetClassifyChildrenIdsRecursive 遍历子菜单IDs
- func GetClassifyChildrenIdsRecursive(list []*eta_training_video.EtaTrainingVideoClassify, parentId int) []int {
- res := make([]int, 0)
- for _, v := range list {
- if v.ParentId == parentId {
- ids := GetClassifyChildrenIdsRecursive(list, v.EtaTrainingVideoClassifyId)
- res = append(res, v.EtaTrainingVideoClassifyId)
- res = append(res, ids...)
- }
- }
- return res
- }
- // GetClassifyParentsRecursive 遍历子分类的所有父级分类
- func GetClassifyParentsRecursive(list []*eta_training_video.EtaTrainingVideoClassify, parentId int) []*eta_training_video.EtaTrainingVideoClassify {
- res := make([]*eta_training_video.EtaTrainingVideoClassify, 0)
- for _, v := range list {
- if v.EtaTrainingVideoClassifyId == parentId {
- res = append(res, v)
- parents := make([]*eta_training_video.EtaTrainingVideoClassify, 0)
- if v.ParentId > 0 {
- parents = GetClassifyParentsRecursive(list, v.ParentId)
- }
- res = append(res, parents...)
- }
- }
- return res
- }
|