upd: 编码规范
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
public UserJwtModel loadUserByUsername(String username) {
|
||||
UserJwtModel userJwtModel = userCacheService.describeUserJwtModelByUsername(username);
|
||||
if (userJwtModel == null) {
|
||||
User user = userService.getUserByUsername(username);
|
||||
User user = userService.describeUserByUsername(username);
|
||||
if (user == null) {
|
||||
throw new BadRequestException("用户不存在");
|
||||
} else {
|
||||
|
||||
+13
-13
@@ -64,7 +64,7 @@ public class UserController {
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('user:list')")
|
||||
public void exportUser(HttpServletResponse response, QueryUserRequest criteria) throws IOException {
|
||||
userService.downloadExcel(userService.selectUserByCriteria(criteria), response);
|
||||
userService.downloadUserExcel(userService.describeUserList(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("查询用户")
|
||||
@@ -80,18 +80,18 @@ public class UserController {
|
||||
criteria.getDeptIds().addAll(deptService.describeChildDeptIdListByDeptIds(data));
|
||||
}
|
||||
// 数据权限
|
||||
List<Long> dataScopes = dataService.describeDeptIdListByUserIdWithDeptId(userService.getUserByUsername(SecurityHelper.getCurrentUsername()));
|
||||
List<Long> dataScopes = dataService.describeDeptIdListByUserIdWithDeptId(userService.describeUserByUsername(SecurityHelper.getCurrentUsername()));
|
||||
// criteria.getDeptIds() 不为空并且数据权限不为空则取交集
|
||||
if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) {
|
||||
// 取交集
|
||||
criteria.getDeptIds().retainAll(dataScopes);
|
||||
if (!CollectionUtil.isEmpty(criteria.getDeptIds())) {
|
||||
return new ResponseEntity<>(userService.queryUserPage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(userService.describeUserPage(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
} else {
|
||||
// 否则取并集
|
||||
criteria.getDeptIds().addAll(dataScopes);
|
||||
return new ResponseEntity<>(userService.queryUserPage(criteria, page), HttpStatus.OK);
|
||||
return new ResponseEntity<>(userService.describeUserPage(criteria, page), HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(PageUtil.noData(), HttpStatus.OK);
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class UserController {
|
||||
@PreAuthorize("@el.check('user:edit')")
|
||||
public ResponseEntity<Object> updateUser(@Validated(User.Update.class) @RequestBody User resources) throws Exception {
|
||||
checkLevel(resources);
|
||||
userService.updateUserById(resources);
|
||||
userService.modifyUserById(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class UserController {
|
||||
if (!resources.getId().equals(SecurityHelper.getCurrentUserId())) {
|
||||
throw new BadRequestException("不能修改他人资料");
|
||||
}
|
||||
userService.updateCenterInfoById(resources);
|
||||
userService.modifyUserCenterInfoById(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class UserController {
|
||||
Integer currentLevel = Collections.min(roleService.describeRoleListByUsersId(SecurityHelper.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||
Integer optLevel = Collections.min(roleService.describeRoleListByUsersId(id).stream().map(Role::getLevel).collect(Collectors.toList()));
|
||||
if (currentLevel > optLevel) {
|
||||
throw new BadRequestException("角色权限不足,不能删除:" + userService.getUserById(id).getUsername());
|
||||
throw new BadRequestException("角色权限不足,不能删除:" + userService.describeUserById(id).getUsername());
|
||||
}
|
||||
}
|
||||
userService.deleteUserByIds(ids);
|
||||
@@ -146,14 +146,14 @@ public class UserController {
|
||||
public ResponseEntity<Object> updatePassword(@RequestBody UpdateUserPasswordResponse passVo) throws Exception {
|
||||
String oldPass = RsaEncryptUtil.decryptByPrivateKey(RsaProperties.privateKey, passVo.getOldPass());
|
||||
String newPass = RsaEncryptUtil.decryptByPrivateKey(RsaProperties.privateKey, passVo.getNewPass());
|
||||
User user = userService.getUserByUsername(SecurityHelper.getCurrentUsername());
|
||||
User user = userService.describeUserByUsername(SecurityHelper.getCurrentUsername());
|
||||
if (!passwordEncoder.matches(oldPass, user.getPassword())) {
|
||||
throw new BadRequestException("修改失败,旧密码错误");
|
||||
}
|
||||
if (passwordEncoder.matches(newPass, user.getPassword())) {
|
||||
throw new BadRequestException("新密码不能与旧密码相同");
|
||||
}
|
||||
userService.updatePasswordByUsername(user.getUsername(), passwordEncoder.encode(newPass));
|
||||
userService.modifyUserPasswordByUsername(user.getUsername(), passwordEncoder.encode(newPass));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -161,26 +161,26 @@ public class UserController {
|
||||
@PostMapping(value = "/resetPwd")
|
||||
public ResponseEntity<Object> resetPwd(@RequestBody Set<Long> ids) {
|
||||
String defaultPwd = passwordEncoder.encode("123456");
|
||||
userService.resetPasswordByIds(ids, defaultPwd);
|
||||
userService.resetUserPasswordByIds(ids, defaultPwd);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("修改头像")
|
||||
@PostMapping(value = "/updateAvatar")
|
||||
public ResponseEntity<Object> updateUserAvatar(@RequestParam MultipartFile avatar) {
|
||||
return new ResponseEntity<>(userService.updateAvatarFile(avatar), HttpStatus.OK);
|
||||
return new ResponseEntity<>(userService.modifyUserAvatarFile(avatar), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("修改邮箱")
|
||||
@PostMapping(value = "/updateEmail/{code}")
|
||||
public ResponseEntity<Object> updateUserEmail(@PathVariable String code, @RequestBody User resources) throws Exception {
|
||||
String password = RsaEncryptUtil.decryptByPrivateKey(RsaProperties.privateKey, resources.getPassword());
|
||||
User user = userService.getUserByUsername(SecurityHelper.getCurrentUsername());
|
||||
User user = userService.describeUserByUsername(SecurityHelper.getCurrentUsername());
|
||||
if (!passwordEncoder.matches(password, user.getPassword())) {
|
||||
throw new BadRequestException("密码错误");
|
||||
}
|
||||
verificationCodeService.checkCodeAvailable(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey(), resources.getEmail(), code);
|
||||
userService.updateEmailByUsername(user.getUsername(), resources.getEmail());
|
||||
userService.modifyUserEmailByUsername(user.getUsername(), resources.getEmail());
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -20,7 +20,7 @@ public interface UserService extends IService<User> {
|
||||
* @param id ID
|
||||
* @return /
|
||||
*/
|
||||
User getUserById(long id);
|
||||
User describeUserById(long id);
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
@@ -35,7 +35,7 @@ public interface UserService extends IService<User> {
|
||||
* @param resources /
|
||||
* @throws Exception /
|
||||
*/
|
||||
void updateUserById(User resources) throws Exception;
|
||||
void modifyUserById(User resources) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
@@ -50,7 +50,7 @@ public interface UserService extends IService<User> {
|
||||
* @param username /
|
||||
* @return /
|
||||
*/
|
||||
User getUserByUsername(String username);
|
||||
User describeUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
@@ -58,7 +58,7 @@ public interface UserService extends IService<User> {
|
||||
* @param username 用户名
|
||||
* @param encryptPassword 密码
|
||||
*/
|
||||
void updatePasswordByUsername(String username, String encryptPassword);
|
||||
void modifyUserPasswordByUsername(String username, String encryptPassword);
|
||||
|
||||
/**
|
||||
* 修改头像
|
||||
@@ -66,7 +66,7 @@ public interface UserService extends IService<User> {
|
||||
* @param file 文件
|
||||
* @return /
|
||||
*/
|
||||
Map<String, String> updateAvatarFile(MultipartFile file);
|
||||
Map<String, String> modifyUserAvatarFile(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 修改邮箱
|
||||
@@ -74,7 +74,7 @@ public interface UserService extends IService<User> {
|
||||
* @param username 用户名
|
||||
* @param email 邮箱
|
||||
*/
|
||||
void updateEmailByUsername(String username, String email);
|
||||
void modifyUserEmailByUsername(String username, String email);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
@@ -83,7 +83,7 @@ public interface UserService extends IService<User> {
|
||||
* @param page 分页参数
|
||||
* @return /
|
||||
*/
|
||||
PageResult<User> queryUserPage(QueryUserRequest criteria, Page<Object> page);
|
||||
PageResult<User> describeUserPage(QueryUserRequest criteria, Page<Object> page);
|
||||
|
||||
/**
|
||||
* 查询全部不分页
|
||||
@@ -91,7 +91,7 @@ public interface UserService extends IService<User> {
|
||||
* @param criteria 条件
|
||||
* @return /
|
||||
*/
|
||||
List<User> selectUserByCriteria(QueryUserRequest criteria);
|
||||
List<User> describeUserList(QueryUserRequest criteria);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
@@ -100,14 +100,14 @@ public interface UserService extends IService<User> {
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void downloadExcel(List<User> queryAll, HttpServletResponse response) throws IOException;
|
||||
void downloadUserExcel(List<User> queryAll, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 用户自助修改资料
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
void updateCenterInfoById(User resources);
|
||||
void modifyUserCenterInfoById(User resources);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
@@ -115,5 +115,5 @@ public interface UserService extends IService<User> {
|
||||
* @param ids 用户id
|
||||
* @param password 密码
|
||||
*/
|
||||
void resetPasswordByIds(Set<Long> ids, String password);
|
||||
void resetUserPasswordByIds(Set<Long> ids, String password);
|
||||
}
|
||||
|
||||
+11
-11
@@ -53,7 +53,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
private final UserOnlineService userOnlineService;
|
||||
|
||||
@Override
|
||||
public PageResult<User> queryUserPage(QueryUserRequest criteria, Page<Object> page) {
|
||||
public PageResult<User> describeUserPage(QueryUserRequest criteria, Page<Object> page) {
|
||||
criteria.setOffset(page.offset());
|
||||
List<User> users = userMapper.queryUserPageByArgs(criteria, PageUtil.getCount(userMapper)).getRecords();
|
||||
Long total = userMapper.getUserCountByArgs(criteria);
|
||||
@@ -61,13 +61,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> selectUserByCriteria(QueryUserRequest criteria) {
|
||||
public List<User> describeUserList(QueryUserRequest criteria) {
|
||||
return userMapper.queryUserPageByArgs(criteria, PageUtil.getCount(userMapper)).getRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public User getUserById(long id) {
|
||||
public User describeUserById(long id) {
|
||||
String key = SystemRedisKey.USER_ID + id;
|
||||
User user = redisHelper.get(key, User.class);
|
||||
if (user == null) {
|
||||
@@ -99,7 +99,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateUserById(User resources) {
|
||||
public void modifyUserById(User resources) {
|
||||
User user = getById(resources.getId());
|
||||
User user1 = userMapper.getUserByUsername(resources.getUsername());
|
||||
User user2 = userMapper.getUserByEmail(resources.getEmail());
|
||||
@@ -151,7 +151,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateCenterInfoById(User resources) {
|
||||
public void modifyUserCenterInfoById(User resources) {
|
||||
User user = getById(resources.getId());
|
||||
User user1 = userMapper.getUserByPhone(resources.getPhone());
|
||||
if (user1 != null && !user.getId().equals(user1.getId())) {
|
||||
@@ -181,20 +181,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
public User describeUserByUsername(String username) {
|
||||
return userMapper.getUserByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePasswordByUsername(String username, String pass) {
|
||||
public void modifyUserPasswordByUsername(String username, String pass) {
|
||||
userMapper.updatePasswordByUsername(username, pass, new Date());
|
||||
flushCache(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void resetPasswordByIds(Set<Long> ids, String password) {
|
||||
public void resetUserPasswordByIds(Set<Long> ids, String password) {
|
||||
List<User> users = userMapper.selectByIds(ids);
|
||||
// 清除缓存
|
||||
users.forEach(user -> {
|
||||
@@ -209,7 +209,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, String> updateAvatarFile(MultipartFile multipartFile) {
|
||||
public Map<String, String> modifyUserAvatarFile(MultipartFile multipartFile) {
|
||||
// 文件大小验证
|
||||
FileUtil.checkSize(fileProperties.getAvatarMaxSize(), multipartFile.getSize());
|
||||
// 验证文件上传的格式
|
||||
@@ -236,13 +236,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateEmailByUsername(String username, String email) {
|
||||
public void modifyUserEmailByUsername(String username, String email) {
|
||||
userMapper.updateEmailByUsername(username, email);
|
||||
flushCache(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadExcel(List<User> users, HttpServletResponse response) throws IOException {
|
||||
public void downloadUserExcel(List<User> users, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (User user : users) {
|
||||
List<String> roles = user.getRoles().stream().map(Role::getName).collect(Collectors.toList());
|
||||
|
||||
Reference in New Issue
Block a user