xuhy
2 天以前 a86e349db12676d108cbb5014a6ef784a76f9403
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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>
 * 项目部 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2025-05-28
 */
@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;
    }
}