| | |
| | | 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); |
| | | return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); |
| | | } |
| | | |
| | | @Log("新增用户") |
| | |
| | | // 默认密码 123456 |
| | | resources.setPassword(passwordEncoder.encode("123456")); |
| | | userService.create(resources); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.CREATED); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.CREATED); |
| | | } |
| | | |
| | | @Log("修改用户") |
| | |
| | | public ResponseEntity<Object> updateUser(@Validated(User.Update.class) @RequestBody User resources) throws Exception { |
| | | checkLevel(resources); |
| | | userService.update(resources); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.NO_CONTENT); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT); |
| | | } |
| | | |
| | | @Log("修改用户:个人中心") |
| | |
| | | throw new BadRequestException("不能修改他人资料"); |
| | | } |
| | | userService.updateCenter(resources); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.NO_CONTENT); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT); |
| | | } |
| | | |
| | | @Log("删除用户") |
| | |
| | | } |
| | | } |
| | | userService.delete(ids); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("修改密码") |
| | |
| | | throw new BadRequestException("新密码不能与旧密码相同"); |
| | | } |
| | | userService.updatePass(user.getUsername(), passwordEncoder.encode(newPass)); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("重置密码") |
| | |
| | | public ResponseEntity<Object> resetPwd(@RequestBody Set<Long> ids) { |
| | | String pwd = passwordEncoder.encode("123456"); |
| | | userService.resetPwd(ids, pwd); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("修改头像") |
| | |
| | | } |
| | | verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + resources.getEmail(), code); |
| | | userService.updateEmail(user.getUsername(), resources.getEmail()); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | /** |