| | |
| | | package com.ycl.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.common.base.Result; |
| | | import com.ycl.domain.entity.FlowableType; |
| | | import com.ycl.framework.utils.PageUtil; |
| | | import com.ycl.mapper.FlowableTypeMapper; |
| | | import com.ycl.service.FlowableTypeService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | public List<FlowableType> selectTypeList(FlowableType flowableType) { |
| | | return baseMapper.selectTypeList(flowableType); |
| | | } |
| | | |
| | | @Override |
| | | public List<FlowableType> buildTreeSelect(List<FlowableType> list) { |
| | | List<FlowableType> returnList = new ArrayList<FlowableType>(); |
| | | List<Integer> tempList = list.stream().map(FlowableType::getId).collect(Collectors.toList()); |
| | | for (Iterator<FlowableType> iterator = list.iterator(); iterator.hasNext();) |
| | | { |
| | | FlowableType type = (FlowableType) iterator.next(); |
| | | // 如果是顶级节点, 遍历该父节点的所有子节点 |
| | | if (!tempList.contains(type.getParentId())) |
| | | { |
| | | recursionFn(list, type); |
| | | returnList.add(type); |
| | | } |
| | | } |
| | | if (returnList.isEmpty()) |
| | | { |
| | | returnList = list; |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | private void recursionFn(List<FlowableType> list, FlowableType t) |
| | | { |
| | | // 得到子节点列表 |
| | | List<FlowableType> childList = getChildList(list, t); |
| | | t.setChildren(childList); |
| | | for (FlowableType tChild : childList) |
| | | { |
| | | if (hasChild(list, tChild)) |
| | | { |
| | | recursionFn(list, tChild); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 得到子节点列表 |
| | | */ |
| | | private List<FlowableType> getChildList(List<FlowableType> list, FlowableType t) |
| | | { |
| | | List<FlowableType> tlist = new ArrayList<FlowableType>(); |
| | | Iterator<FlowableType> it = list.iterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | FlowableType n = (FlowableType) it.next(); |
| | | if (n.getParentId().longValue() == t.getId().longValue()) |
| | | { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | return tlist; |
| | | } |
| | | |
| | | /** |
| | | * 判断是否有子节点 |
| | | */ |
| | | private boolean hasChild(List<FlowableType> list, FlowableType t) |
| | | { |
| | | return getChildList(list, t).size() > 0; |
| | | } |
| | | |
| | | } |