zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.jeecg.modules.hrm.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.model.DepartOrgVo;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysUserDepartService;
import org.jeecg.modules.system.vo.SysDepartVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.stream.Collectors;
 
@Api(tags = "hrm_board")
@RestController
@RequestMapping("/hrm/board")
public class HrmBoardController {
    @Autowired
    private ISysDepartService sysDepartService;
    @Autowired
    private ISysUserDepartService sysUserDepartService;
 
    @RequestMapping(value = "/departUserList", method = RequestMethod.GET)
    public Result<List<SysDepartVo>> queryTreeList(@RequestParam(name = "departName", required = true) String departName) {
        Result<List<SysDepartVo>> result = new Result<>();
        QueryWrapper<SysDepart> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
        queryWrapper.lambda().eq(SysDepart::getDepartName, departName);
        SysDepart depart = sysDepartService.getOne(queryWrapper);
        if (depart == null) {
            return result.error500("查询部门不存在!");
        }
        String orgCode = depart.getOrgCode();
        queryWrapper.clear();
        queryWrapper.lambda().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
        queryWrapper.lambda().likeRight(SysDepart::getOrgCode, orgCode);
        queryWrapper.lambda().orderByAsc(SysDepart::getOrgType);
        queryWrapper.lambda().orderByAsc(SysDepart::getDepartOrder);
        List<SysDepart> departList = sysDepartService.list(queryWrapper);
        //转换vo
        List<SysDepartVo> departVoList = departList.stream().map(d -> {
            SysDepartVo vo = new SysDepartVo();
            BeanUtils.copyProperties(d, vo);
            //查询部门用户
            List<SysUser> sysUsers = sysUserDepartService.queryUserByDepCode(d.getOrgCode(),null);
            vo.setUserList(sysUsers);
            return vo;
        }).collect(Collectors.toList());
 
        result.setResult(departVoList);
 
        return result;
    }
 
}