| | |
| | | import me.zhengjie.modules.system.domain.vo.UserPassVo; |
| | | import me.zhengjie.modules.system.service.DeptService; |
| | | import me.zhengjie.modules.system.service.RoleService; |
| | | import me.zhengjie.modules.system.service.dto.DeptDto; |
| | | import me.zhengjie.modules.system.service.dto.RoleSmallDto; |
| | | import me.zhengjie.modules.system.service.dto.UserDto; |
| | | import me.zhengjie.modules.system.service.dto.UserQueryCriteria; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | userService.download(userService.queryAll(criteria), response); |
| | | } |
| | | |
| | | @GetMapping(value = "/all") |
| | | @Log("查询用户") |
| | | @ApiOperation("查询用户") |
| | | @PreAuthorize("@el.check('user:list')") |
| | | public ResponseEntity<Object> queryUserAll(UserQueryCriteria criteria){ |
| | | return new ResponseEntity<>(userService.queryAll(criteria),HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping(value = "/approval") |
| | | @Log("查询用户") |
| | | @ApiOperation("查询用户") |
| | | @PreAuthorize("@el.check('user:list')") |
| | | public ResponseEntity<Object> queryApprovalUser(UserQueryCriteria criteria) { |
| | | // 当前用户 |
| | | UserDto user = userService.findByName(SecurityUtils.getCurrentUsername()); |
| | | List<Long> deptList = new ArrayList<Long>(); |
| | | // 当前部门 |
| | | DeptDto deptDto = deptService.findById(user.getDept().getId()); |
| | | // 然后把父节点的ID都加入到集合中 |
| | | deptList.addAll(deptService.getSuperior(deptDto, new ArrayList<Dept>()).stream().map(dept -> dept.getId()).collect(Collectors.toList())); |
| | | // 父部门加入检索条件 |
| | | criteria.getDeptIds().addAll(deptList); |
| | | |
| | | RoleSmallDto role = user.getRoles().stream().findFirst().orElseGet(RoleSmallDto::new); |
| | | // 数据权限是全体的场合,包含自己,否则不包含自己 |
| | | if ("全部".equals(role.getDataScope())) { |
| | | criteria.setLevel(role.getLevel()); |
| | | } else { |
| | | criteria.setLevelNq(role.getLevel()); |
| | | } |
| | | return new ResponseEntity<>(userService.queryAll(criteria),HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping(value = "/approval/level") |
| | | @Log("查询审批员工") |
| | | @ApiOperation("查询审批员工") |
| | | @PreAuthorize("@el.check('user:list')") |
| | | public ResponseEntity<Object> queryApprovalUserByLevel(@RequestParam Long userId) { |
| | | // 获取用户最大角色等级 |
| | | List<Integer> levels = roleService.findByUsersId(userId).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
| | | int min = Collections.min(levels); |
| | | min = min - 1 <= 1 ? min : min - 1; |
| | | // 根据角色等级查询 |
| | | List<UserDto> userDtoList = userService.findByRoleLevel(min); |
| | | return new ResponseEntity<>(userDtoList,HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("查询用户") |
| | | @GetMapping |
| | | @PreAuthorize("@el.check('user:list')") |
| | |
| | | } |
| | | // 数据权限 |
| | | List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername())); |
| | | List<Long> totalScopes = new ArrayList<Long>(dataScopes); |
| | | for (Long dataScope : dataScopes) { |
| | | // 先查找是否存在子节点 |
| | | List<Dept> data = deptService.findByPid(dataScope); |
| | | // 然后把子节点的ID都加入到集合中 |
| | | totalScopes.addAll(deptService.getDeptChildren(data)); |
| | | } |
| | | // criteria.getDeptIds() 不为空并且数据权限不为空则取交集 |
| | | if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)){ |
| | | if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(totalScopes)){ |
| | | // 取交集 |
| | | criteria.getDeptIds().retainAll(dataScopes); |
| | | criteria.getDeptIds().retainAll(totalScopes); |
| | | if(!CollectionUtil.isEmpty(criteria.getDeptIds())){ |
| | | return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK); |
| | | } |
| | | } else { |
| | | // 否则取并集 |
| | | criteria.getDeptIds().addAll(dataScopes); |
| | | criteria.getDeptIds().addAll(totalScopes); |
| | | return new ResponseEntity<>(userService.queryAll(criteria,pageable),HttpStatus.OK); |
| | | } |
| | | return new ResponseEntity<>(PageUtil.toPage(null,0),HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping(value = "/getUsers") |
| | | @Log("查询在职的员工") |
| | | @ApiOperation("查询在职的员工") |
| | | public ResponseEntity<Object> getUsers() { |
| | | return new ResponseEntity<>(userService.getUsers(), HttpStatus.OK); |
| | | } |
| | | |
| | | @Log("新增用户") |
| | |
| | | throw new BadRequestException("角色权限不足"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取用户日历信息 |
| | | * @param month |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @GetMapping(value = "/getUserCalendarInfo/{month}") |
| | | @Log("获取用户日历信息") |
| | | @ApiOperation("获取用户日历信息") |
| | | public ResponseEntity<Object> getUserCalendarInfo(@PathVariable String month) throws Exception { |
| | | return new ResponseEntity<>(userService.getUserCalendarInfo(month), HttpStatus.OK); |
| | | } |
| | | |
| | | @GetMapping(value = "/getUserBaseInfo/{yearMonth}") |
| | | @Log("获取用户基础信息") |
| | | @ApiOperation("获取用户日历信息") |
| | | public ResponseEntity<Object> getUserBaseInfo(@PathVariable Date yearMonth) throws ParseException { |
| | | return new ResponseEntity<>(userService.getUserBaseInfo(yearMonth), HttpStatus.OK); |
| | | } |
| | | } |