2024-07-08 17:47:02 +08:00
|
|
|
package com.gunshi.project.xyt.service;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.gunshi.project.xyt.mapper.CctvBMenuMapper;
|
|
|
|
|
import com.gunshi.project.xyt.model.CctvBMenu;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2024-07-17 17:38:06 +08:00
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2024-07-08 17:47:02 +08:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
2024-07-17 17:38:06 +08:00
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述: 视频点目录
|
|
|
|
|
* author: xusan
|
|
|
|
|
* date: 2024-07-08 17:30:37
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class CctvBMenuService extends ServiceImpl<CctvBMenuMapper, CctvBMenu>
|
|
|
|
|
{
|
|
|
|
|
|
2024-07-17 17:38:06 +08:00
|
|
|
public List<CctvBMenu> tree() {
|
|
|
|
|
List<CctvBMenu> list = list(lambdaQuery().orderByDesc(CctvBMenu::getId));
|
|
|
|
|
if (CollectionUtils.isEmpty(list)){
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
Map<Long, List<CctvBMenu>> listMap = list.stream().collect(Collectors.groupingBy(CctvBMenu::getParentId));
|
|
|
|
|
|
|
|
|
|
list.forEach(o -> o.setChildren(listMap.get(o.getId())));
|
|
|
|
|
List<CctvBMenu> parentList = list.stream().filter(o -> Objects.isNull(o.getParentId())).collect(Collectors.toList());
|
|
|
|
|
return sorted(parentList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<CctvBMenu> sorted( List<CctvBMenu> tree) {
|
|
|
|
|
|
|
|
|
|
List<CctvBMenu> sorteds = null;
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(tree)){
|
|
|
|
|
sorteds = tree.stream().sorted(Comparator.comparing(CctvBMenu::getOrderIndex)
|
|
|
|
|
).collect(Collectors.toList());
|
|
|
|
|
sorteds.forEach(o->{
|
|
|
|
|
o.setChildren(sorted(o.getChildren()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sorteds;
|
|
|
|
|
}
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|