@Override
public String getNamePath(List<PlaceVo> placeTreeList, Long placeId) {
if (CollectionUtils.isEmpty(placeTreeList)) {
placeTreeList = listTreeAll2();
}
return getNamePath2(placeTreeList, placeId);
}
private String getNamePath2(List<PlaceVo> placeTreeList, Long placeId) {
if (CollectionUtils.isEmpty(placeTreeList)) {
return null;
}
String tempNamePath = "";
for (PlaceVo one : placeTreeList) {
if (one.getPlaceId().equals(placeId)) {
tempNamePath = one.getPlaceName();
break;
}
if (CollectionUtils.isEmpty(one.getSubList())) {
continue;
}
String subNamePath = getNamePath2(one.getSubList(), placeId);
if (StringUtils.isNotEmpty(subNamePath)) {
tempNamePath = one.getPlaceName() + "/" + subNamePath;
break;
}
}
return tempNamePath;
}
@Override
public List<PlaceVo> listTreeAll2() {
List<PlaceVo> placeVos = baseMapper.listTreeAll(0L);
if (CollectionUtils.isNotEmpty(placeVos)) {
return arrangePlaceVo(placeVos);
}
return placeVos;
}
private List<PlaceVo> arrangePlaceVo(List<PlaceVo> voList) {
List<PlaceVo> newListVo = new ArrayList<>(voList.size());
voList.forEach(one -> {
PlaceVo placeVo = new PlaceVo(one.getPlaceId(), one.getPlaceName(), one.getPlaceType());
if (CollectionUtils.isNotEmpty(one.getSubList())) {
placeVo.getSubList().addAll(arrangePlaceVo(one.getSubList()));
}
if (CollectionUtils.isNotEmpty(one.getPrimaryDeviceList())) {
placeVo.getSubList().addAll(arrangePrimaryDeviceVo(one.getPrimaryDeviceList()));
}
newListVo.add(placeVo);
});
return newListVo;
}
private List<PlaceVo> arrangePrimaryDeviceVo(List<PrimaryDeviceVo> voList) {
List<PlaceVo> newListVo = new ArrayList<>(voList.size());
voList.forEach(one -> {
PlaceVo placeVo = new PlaceVo(one.getId(), one.getName(), one.getPlaceTpye());
if (CollectionUtils.isNotEmpty(one.getPartsList())) {
one.getPartsList().forEach(one2 -> {
PlaceVo placeVo2 = new PlaceVo(one2.getId(), one2.getName(), one2.getPlaceTpye());
placeVo.getSubList().add(placeVo2);
});
}
newListVo.add(placeVo);
});
return newListVo;
}
private List<PlaceVo> arrangePartsVo(List<PartsVo> voList) {
List<PlaceVo> newListVo = new ArrayList<>(voList.size());
voList.forEach(one -> {
PlaceVo placeVo = new PlaceVo(one.getId(), one.getName(), one.getPlaceTpye());
newListVo.add(placeVo);
});
return newListVo;
}