| | |
| | | import com.oying.modules.system.domain.Role; |
| | | import com.oying.modules.system.domain.User; |
| | | import com.oying.modules.system.domain.dto.UserPassVo; |
| | | import com.oying.utils.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.oying.utils.PageResult; |
| | | import com.oying.utils.PageUtil; |
| | | import com.oying.utils.RsaUtils; |
| | | import com.oying.utils.SecurityUtils; |
| | | import com.oying.annotation.Log; |
| | | import com.oying.config.properties.RsaProperties; |
| | | import com.oying.modules.system.service.DataService; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | |
| | | @ApiOperation("查询用户") |
| | | @GetMapping |
| | | @PreAuthorize("@el.check('user:list')") |
| | | public ResponseEntity<PageResult<User>> queryUser(UserQueryCriteria criteria){ |
| | | 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()); |
| | |
| | | // 取交集 |
| | | criteria.getDeptIds().retainAll(dataScopes); |
| | | if(!CollectionUtil.isEmpty(criteria.getDeptIds())){ |
| | | return new ResponseEntity<>(userService.queryAll(criteria,page),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); |
| | | } |
| | | } else { |
| | | // 否则取并集 |
| | | criteria.getDeptIds().addAll(dataScopes); |
| | | return new ResponseEntity<>(userService.queryAll(criteria,page),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); |
| | | } |
| | | return new ResponseEntity<>(PageUtil.noData(),HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @Log("新增用户") |
| | |
| | | // 默认密码 123456 |
| | | resources.setPassword(passwordEncoder.encode("123456")); |
| | | userService.create(resources); |
| | | return new ResponseEntity<>(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<>(HttpStatus.NO_CONTENT); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.NO_CONTENT); |
| | | } |
| | | |
| | | @Log("修改用户:个人中心") |
| | |
| | | throw new BadRequestException("不能修改他人资料"); |
| | | } |
| | | userService.updateCenter(resources); |
| | | return new ResponseEntity<>(HttpStatus.NO_CONTENT); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.NO_CONTENT); |
| | | } |
| | | |
| | | @Log("删除用户") |
| | |
| | | } |
| | | } |
| | | userService.delete(ids); |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("修改密码") |
| | |
| | | throw new BadRequestException("新密码不能与旧密码相同"); |
| | | } |
| | | userService.updatePass(user.getUsername(),passwordEncoder.encode(newPass)); |
| | | return new ResponseEntity<>(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<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.OK); |
| | | } |
| | | |
| | | @ApiOperation("修改头像") |
| | | @PostMapping(value = "/updateAvatar") |
| | | public ResponseEntity<Object> updateUserAvatar(@RequestParam MultipartFile avatar){ |
| | | return new ResponseEntity<>(userService.updateAvatar(avatar), HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(userService.updateAvatar(avatar)), HttpStatus.OK); |
| | | } |
| | | |
| | | @Log("修改邮箱") |
| | |
| | | } |
| | | verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + resources.getEmail(), code); |
| | | userService.updateEmail(user.getUsername(),resources.getEmail()); |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(),HttpStatus.OK); |
| | | } |
| | | |
| | | /** |
| | | * 如果当前用户的角色级别低于创建用户的角色级别,则抛出权限不足的错误 |
| | | * |
| | | * @param resources / |
| | | */ |
| | | private void checkLevel(User resources) { |