use of com.hb0730.boot.admin.project.system.user.model.dto.UserInfoDTO in project boot-admin by hb0730.
the class UserInfoServiceImpl method save.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean save(@Nonnull UserInfoDTO dto) {
UserInfoEntity entity = dto.convertTo();
// 1.账号是否存在
String username = dto.getUsername();
if (StringUtils.isBlank(username)) {
throw new BusinessException("用户账号不为空");
}
UserAccountEntity account = accountService.findUserAccountByUsername(username);
if (Objects.nonNull(account)) {
throw new BusinessException("用户账号已存在,请重新设置");
}
boolean result = super.save(entity);
// 保存 用户账号
account = new UserAccountEntity();
account.setUsername(username);
// 默认密码
String password = DictUtils.getEntryValue(TYPE, DEFAULT_PASSWORD);
if (StringUtils.isBlank(password)) {
password = DEFAULT_PASSWORD_VALUE;
}
account.setPassword(PasswordSecurityUtils.encode(SecurityUtils.getPasswordEncoder(), password));
account.setUserId(entity.getId());
accountService.save(account);
// 保存 用户角色
Collection<Long> roleIds = dto.getRoleIds();
if (!CollectionUtils.isEmpty(roleIds)) {
userRoleService.updateUserRole(entity.getId(), roleIds);
}
// 保存 用户岗位
Collection<Long> postIds = dto.getPostIds();
if (!CollectionUtils.isEmpty(postIds)) {
userPostService.updateUserPost(entity.getId(), postIds);
}
return result;
}
use of com.hb0730.boot.admin.project.system.user.model.dto.UserInfoDTO in project boot-admin by hb0730.
the class UserInfoController method getCurrentInfo.
/**
* 获取当前请求认证的用户
*
* @param request 请求
* @return 用户详情(不包含相关信息)
*/
@GetMapping
public Result<UserInfoDTO> getCurrentInfo(HttpServletRequest request) {
User user = SecurityUtils.getCurrentUser();
UserInfoDTO info = BeanUtil.toBean(user, UserInfoDTO.class);
return R.success(info);
}
use of com.hb0730.boot.admin.project.system.user.model.dto.UserInfoDTO in project boot-admin by hb0730.
the class UserInfoServiceImpl method updateById.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateById(@Nonnull Long id, @Nonnull UserInfoDTO dto) {
UserInfoEntity entity = dto.convertTo();
entity.setId(id);
boolean result = this.updateById(entity);
// 更新角色
userRoleService.updateUserRole(id, dto.getRoleIds());
// 更新岗位
userPostService.updateUserPost(id, dto.getPostIds());
return result;
}
use of com.hb0730.boot.admin.project.system.user.model.dto.UserInfoDTO in project boot-admin by hb0730.
the class UserInfoController method getUserInfoById.
/**
* 获取用户详情
*
* @param id 用户id
* @return 用户详情(不包含相关信息)
*/
@GetMapping("/{id}")
public Result<UserInfoDTO> getUserInfoById(@PathVariable("id") Long id) {
UserInfoEntity entity = service.getById(id);
UserInfoDTO info = BeanUtil.toBean(entity, UserInfoDTO.class);
return R.success(info);
}
Aggregations