| | |
| | | package com.oying.modules.system.rest; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.oying.modules.system.domain.Dept; |
| | | import com.oying.modules.system.domain.Role; |
| | | import com.oying.modules.system.domain.User; |
| | | import com.oying.modules.system.domain.dto.UserPassVo; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.oying.annotation.Log; |
| | | import com.oying.config.properties.RsaProperties; |
| | | import com.oying.modules.system.service.DataService; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.system.service.DeptService; |
| | | import com.oying.modules.system.service.RoleService; |
| | | import com.oying.modules.system.domain.dto.UserQueryCriteria; |
| | | import com.oying.modules.system.service.VerifyService; |
| | |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | |
| | | private final PasswordEncoder passwordEncoder; |
| | | private final UserService userService; |
| | | private final DataService dataService; |
| | | private final DeptService deptService; |
| | | private final RoleService roleService; |
| | | private final VerifyService verificationCodeService; |
| | | |
| | |
| | | @PreAuthorize("@el.check('user:list')") |
| | | public ResponseEntity<Object> queryUser(UserQueryCriteria criteria) { |
| | | Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize()); |
| | | if (!ObjectUtils.isEmpty(criteria.getDeptId())) { |
| | | criteria.getDeptIds().add(criteria.getDeptId()); |
| | | // 先查找是否存在子节点 |
| | | List<Dept> data = deptService.findByPid(criteria.getDeptId()); |
| | | // 然后把子节点的ID都加入到集合中 |
| | | criteria.getDeptIds().addAll(deptService.getDeptChildren(data)); |
| | | } |
| | | // 数据权限 |
| | | List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername())); |
| | | // criteria.getDeptIds() 不为空并且数据权限不为空则取交集 |
| | | if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) { |
| | | // 取交集 |
| | | criteria.getDeptIds().retainAll(dataScopes); |
| | | if (!CollectionUtil.isEmpty(criteria.getDeptIds())) { |
| | | return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); |
| | | } |
| | | } else { |
| | | // 否则取并集 |
| | | criteria.getDeptIds().addAll(dataScopes); |
| | | return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); |
| | | } |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @Log("新增用户") |