Search in sources :

Example 1 with UserInfoDTO

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;
}
Also used : BusinessException(com.hb0730.boot.admin.exceptions.BusinessException) UserAccountEntity(com.hb0730.boot.admin.project.system.user.model.entity.UserAccountEntity) UserInfoEntity(com.hb0730.boot.admin.project.system.user.model.entity.UserInfoEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserInfoDTO

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);
}
Also used : User(com.hb0730.boot.admin.security.model.User) UserInfoDTO(com.hb0730.boot.admin.project.system.user.model.dto.UserInfoDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with UserInfoDTO

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;
}
Also used : UserInfoEntity(com.hb0730.boot.admin.project.system.user.model.entity.UserInfoEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with UserInfoDTO

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);
}
Also used : UserInfoEntity(com.hb0730.boot.admin.project.system.user.model.entity.UserInfoEntity) UserInfoDTO(com.hb0730.boot.admin.project.system.user.model.dto.UserInfoDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

UserInfoEntity (com.hb0730.boot.admin.project.system.user.model.entity.UserInfoEntity)3 UserInfoDTO (com.hb0730.boot.admin.project.system.user.model.dto.UserInfoDTO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 BusinessException (com.hb0730.boot.admin.exceptions.BusinessException)1 UserAccountEntity (com.hb0730.boot.admin.project.system.user.model.entity.UserAccountEntity)1 User (com.hb0730.boot.admin.security.model.User)1