/**
* 获取监管组织树状结构
*/
@Override
public List<BasSupnOrgBDTO> getTree(){
QueryWrapper<BasSupnOrgBDO> childWrapper = new QueryWrapper<>();
childWrapper.eq("VALI_FLAG",1).orderByAsc("LV").orderByAsc("SEQ");
List<BasSupnOrgBDO> childrenBdoList = basSupnOrgBDAO.selectList(childWrapper);
List<BasSupnOrgBDTO> childrenDtoList = BasSupnOrgBDtoAssembler.toBasSupnOrgBDtoList(childrenBdoList);
return BasSupnOrgBDtoAssembler.buildDeptTree(childrenDtoList);
}
/**
* 转换成树状结构
* @param childrenDtoList
* @return
*/
public static List<BasSupnOrgBDTO> buildDeptTree(List<BasSupnOrgBDTO> childrenDtoList)
{
List<BasSupnOrgBDTO> returnList = new ArrayList<BasSupnOrgBDTO>();
List<String> tempList = new ArrayList<String>();
for (BasSupnOrgBDTO dto : childrenDtoList)
{
tempList.add(dto.getOrguntId());
}
for (Iterator<BasSupnOrgBDTO> iterator = childrenDtoList.iterator(); iterator.hasNext();)
{
BasSupnOrgBDTO dto = (BasSupnOrgBDTO) iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(dto.getPrntOrgId()))
{
recursionFn(childrenDtoList, dto);
returnList.add(dto);
}
}
if (returnList.isEmpty())
{
returnList = childrenDtoList;
}
return returnList;
}
private static void recursionFn(List<BasSupnOrgBDTO> list, BasSupnOrgBDTO t)
{
// 得到子节点列表
List<BasSupnOrgBDTO> childList = getChildList(list, t);
t.setChildren(childList);
for (BasSupnOrgBDTO tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
private static List<BasSupnOrgBDTO> getChildList(List<BasSupnOrgBDTO> list, BasSupnOrgBDTO t)
{
List<BasSupnOrgBDTO> tlist = new ArrayList<BasSupnOrgBDTO>();
Iterator<BasSupnOrgBDTO> it = list.iterator();
while (it.hasNext())
{
BasSupnOrgBDTO n = (BasSupnOrgBDTO) it.next();
if (StringUtils.isNotBlank(n.getPrntOrgId()) && n.getPrntOrgId().equals(t.getOrguntId()))
{
tlist.add(n);
}
}
return tlist;
}
private static boolean hasChild(List<BasSupnOrgBDTO> list, BasSupnOrgBDTO t)
{
return getChildList(list, t).size() > 0 ? true : false;
}