无关风月
1 天以前 25b19e60e004290531f61fdf608d1adb5e531903
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TProjectDeptServiceImpl.java
@@ -1,10 +1,20 @@
package com.ruoyi.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.TProjectDeptMapper;
import com.ruoyi.system.model.TProjectDept;
import com.ruoyi.system.query.DeptListQuery;
import com.ruoyi.system.service.TProjectDeptService;
import com.ruoyi.system.vo.system.ProjectDeptListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
 * <p>
@@ -17,4 +27,25 @@
@Service
public class TProjectDeptServiceImpl extends ServiceImpl<TProjectDeptMapper, TProjectDept> implements TProjectDeptService {
    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public PageInfo<ProjectDeptListVO> pageList(DeptListQuery query) {
        List<SysUser> sysUsers = sysUserMapper.selectAllList();
        PageInfo<ProjectDeptListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
        List<ProjectDeptListVO> list = this.baseMapper.pageList(query,pageInfo);
        List<TProjectDept> projectDepts = this.baseMapper.selectList(new LambdaQueryWrapper<TProjectDept>()
                .ne(TProjectDept::getParentId, 0));
        for (ProjectDeptListVO projectDeptListVO : list) {
            List<TProjectDept> collect = projectDepts.stream().filter(e -> e.getParentId().equals(projectDeptListVO.getId()))
                    .collect(Collectors.toList());
            for (TProjectDept tProjectDept : collect) {
                List<SysUser> collect1 = sysUsers.stream().filter(e -> e.getDeptId().equals(tProjectDept.getId())).collect(Collectors.toList());
                tProjectDept.setUserCount(collect1.size());
            }
            projectDeptListVO.setChildren(collect);
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
}