|
@@ -6,8 +6,6 @@ import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.website.domain.SiteCategory;
|
|
|
import com.usky.website.mapper.SiteCategoryMapper;
|
|
|
import com.usky.website.service.SiteCategoryService;
|
|
|
-import com.usky.website.service.vo.SiteCategoryVo;
|
|
|
-import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -24,17 +22,31 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class SiteCategoryServiceImpl extends AbstractCrudService<SiteCategoryMapper, SiteCategory> implements SiteCategoryService {
|
|
|
|
|
|
- public void siteCategoryList() {
|
|
|
+ @Override
|
|
|
+ public List<SiteCategory> siteCategoryList() {
|
|
|
LambdaQueryWrapper<SiteCategory> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(SiteCategory::getStatus, 1)
|
|
|
.orderByAsc(SiteCategory::getSortindex);
|
|
|
List<SiteCategory> list = this.list(queryWrapper);
|
|
|
- //把EduSubject的数组entities包装成SubjectVO数组
|
|
|
- List<SiteCategoryVo> subjectVOS = list.stream().map(subject -> {
|
|
|
- SiteCategoryVo subjectVO = new SiteCategoryVo();
|
|
|
-// BeanUtils.copyProperties(subject, subjectVO);
|
|
|
+ //取得所有parentId为0的数据,也就是一级目录
|
|
|
+ //用于封装数据,取得他的孩子(也就是下级目录)的数据
|
|
|
+ List<SiteCategory> list1 = list.stream().filter(subjectVO ->
|
|
|
+ subjectVO.getPid() == 0
|
|
|
+ ).map((menu) -> {
|
|
|
+ menu.setChildren(getChildrenData(menu, list));
|
|
|
+ return menu;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return list1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SiteCategory> getChildrenData(SiteCategory root, List<SiteCategory> all) {
|
|
|
+ List<SiteCategory> children = all.stream().filter(subjectVO ->
|
|
|
+ subjectVO.getPid() == root.getId() && !root.getCategoryName().equals("产品服务")
|
|
|
+ ).map(subjectVO -> {
|
|
|
+ subjectVO.setChildren(getChildrenData(subjectVO, all));
|
|
|
return subjectVO;
|
|
|
}).collect(Collectors.toList());
|
|
|
+ return children;
|
|
|
}
|
|
|
|
|
|
}
|