Search in sources :

Example 1 with UserDto

use of com.albedo.java.modules.sys.domain.dto.UserDto in project albedo by somowhere.

the class UserResourceIntTest method createEntity.

/**
 * Create a User.
 * <p>
 * This is a static method, as tests for other entities might also need it, if they
 * test an domain which has a required relationship to the User domain.
 */
public UserDto createEntity() {
    UserDto user = new UserDto();
    user.setUsername(DEFAULT_USERNAME);
    user.setPassword(DEFAULT_PASSWORD);
    user.setEmail(DEFAULT_EMAIL);
    user.setPhone(DEFAULT_PHONE);
    user.setQqOpenId(DEFAULT_QQOPENID);
    user.setDeptId(deptDoList.get(0).getId());
    user.setRoleIdList(CollUtil.extractToList(roleDoList, RoleDo.F_ID));
    return user;
}
Also used : UserDto(com.albedo.java.modules.sys.domain.dto.UserDto)

Example 2 with UserDto

use of com.albedo.java.modules.sys.domain.dto.UserDto in project albedo by somowhere.

the class UserResourceIntTest method createUserWithExistingEmail.

@Test
@Transactional(rollbackFor = Exception.class)
public void createUserWithExistingEmail() throws Exception {
    // Initialize the database
    int databaseSizeBeforeCreate = userService.list().size();
    // Create the User
    UserDto managedUserVM = createEntity();
    managedUserVM.setEmail(DEFAULT_ANOTHER_EMAIL);
    // Create the User
    restUserMockMvc.perform(post(DEFAULT_API_URL).contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedUserVM))).andExpect(status().isBadRequest()).andExpect(jsonPath("$.code").value(ResponseCode.FAIL.getCode())).andExpect(jsonPath("$.message").isNotEmpty());
    // Validate the User in the database
    List<UserDo> userDoList = userService.list();
    assertThat(userDoList).hasSize(databaseSizeBeforeCreate);
}
Also used : UserDo(com.albedo.java.modules.sys.domain.UserDo) UserDto(com.albedo.java.modules.sys.domain.dto.UserDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with UserDto

use of com.albedo.java.modules.sys.domain.dto.UserDto in project albedo by somowhere.

the class UserServiceImpl method save.

@Override
public void save(@Valid UserExcelVo userExcelVo) {
    UserDto user = new UserDto();
    BeanUtils.copyProperties(userExcelVo, user);
    DeptDo deptDo = deptService.getOne(Wrappers.<DeptDo>query().lambda().eq(DeptDo::getName, userExcelVo.getDeptName()));
    if (deptDo != null) {
        user.setDeptId(deptDo.getId());
    }
    RoleDo roleDo = roleService.getOne(Wrappers.<RoleDo>query().lambda().eq(RoleDo::getName, userExcelVo.getRoleName()));
    ArgumentAssert.notNull(roleDo, () -> new BizException("无法获取角色" + userExcelVo.getRoleName() + "信息"));
    user.setRoleIdList(Lists.newArrayList(roleDo.getId()));
    saveOrUpdate(user);
}
Also used : UserDto(com.albedo.java.modules.sys.domain.dto.UserDto) BizException(com.albedo.java.common.core.exception.BizException) DeptDo(com.albedo.java.modules.sys.domain.DeptDo) UserRoleDo(com.albedo.java.modules.sys.domain.UserRoleDo) RoleDo(com.albedo.java.modules.sys.domain.RoleDo)

Example 4 with UserDto

use of com.albedo.java.modules.sys.domain.dto.UserDto in project albedo by somowhere.

the class UserServiceImpl method saveOrUpdate.

/**
 * 保存用户信息
 *
 * @param userDto DTO 对象
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(UserDto userDto) {
    boolean add = ObjectUtil.isEmpty(userDto.getId());
    if (add) {
        ArgumentAssert.notEmpty(userDto.getPassword(), "密码不能为空");
    }
    // username before comparing with database
    if (exitUserByUserName(userDto)) {
        throw new EntityExistException(UserDto.class, "username", userDto.getUsername());
    }
    // email before comparing with database
    if (StringUtil.isNotEmpty(userDto.getEmail()) && exitUserByEmail(userDto)) {
        throw new EntityExistException(UserDto.class, "email", userDto.getEmail());
    }
    // phone before comparing with database
    if (StringUtil.isNotEmpty(userDto.getPhone()) && exitUserByPhone(userDto)) {
        throw new EntityExistException(UserDto.class, "phone", userDto.getPhone());
    }
    UserDo userDo = add ? new UserDo() : repository.selectById(userDto.getId());
    BeanUtil.copyProperties(userDto, userDo, true);
    if (StringUtil.isNotEmpty(userDto.getPassword())) {
        userDo.setPassword(passwordEncoder.encode(userDto.getPassword()));
    }
    super.saveOrUpdate(userDo);
    userDto.setId(userDo.getId());
    if (add || CollUtil.isNotEmpty(userDto.getRoleIdList())) {
        ArgumentAssert.notEmpty(userDto.getRoleIdList(), "用户角色不能为空");
        if (!add) {
            SysCacheUtil.delUserCaches(userDo.getId(), userDo.getUsername());
        }
        List<UserRoleDo> userRoleDoList = userDto.getRoleIdList().stream().map(roleId -> UserRoleDo.builder().userId(userDo.getId()).roleId(roleId).build()).collect(Collectors.toList());
        userRoleService.removeRoleByUserId(userDo.getId());
        userRoleService.saveBatch(userRoleDoList);
    }
}
Also used : Wraps(com.albedo.java.plugins.database.mybatis.conditions.Wraps) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) UserInfo(com.albedo.java.modules.sys.domain.vo.UserInfo) EntityExistException(com.albedo.java.common.core.exception.EntityExistException) UserEmailDto(com.albedo.java.modules.sys.domain.dto.UserEmailDto) UserRoleDo(com.albedo.java.modules.sys.domain.UserRoleDo) RedisUtil(com.albedo.java.common.util.RedisUtil) SysCacheUtil(com.albedo.java.modules.sys.util.SysCacheUtil) Valid(javax.validation.Valid) UserDo(com.albedo.java.modules.sys.domain.UserDo) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) Set(java.util.Set) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) QueryWrapperUtil(com.albedo.java.plugins.database.mybatis.util.QueryWrapperUtil) Collectors(java.util.stream.Collectors) SecurityUtil(com.albedo.java.common.security.util.SecurityUtil) MenuVo(com.albedo.java.modules.sys.domain.vo.MenuVo) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) AbstractDataCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractDataCacheServiceImpl) ArrayUtil(cn.hutool.core.util.ArrayUtil) UserExcelVo(com.albedo.java.modules.sys.domain.vo.UserExcelVo) IPage(com.baomidou.mybatisplus.core.metadata.IPage) BeanUtils(org.springframework.beans.BeanUtils) UserRepository(com.albedo.java.modules.sys.repository.UserRepository) DeptDo(com.albedo.java.modules.sys.domain.DeptDo) PageModel(com.albedo.java.common.core.vo.PageModel) RoleDo(com.albedo.java.modules.sys.domain.RoleDo) LocalDateTime(java.time.LocalDateTime) UserQueryCriteria(com.albedo.java.modules.sys.domain.dto.UserQueryCriteria) HashSet(java.util.HashSet) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) UserDto(com.albedo.java.modules.sys.domain.dto.UserDto) PasswordChangeVo(com.albedo.java.modules.sys.domain.vo.account.PasswordChangeVo) com.albedo.java.common.core.util(com.albedo.java.common.core.util) SecurityConstants(com.albedo.java.common.core.constant.SecurityConstants) CommonConstants(com.albedo.java.common.core.constant.CommonConstants) UserVo(com.albedo.java.modules.sys.domain.vo.UserVo) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) com.albedo.java.modules.sys.service(com.albedo.java.modules.sys.service) BizException(com.albedo.java.common.core.exception.BizException) DataScope(com.albedo.java.plugins.database.mybatis.datascope.DataScope) AllArgsConstructor(lombok.AllArgsConstructor) UserCacheKeyBuilder(com.albedo.java.modules.sys.cache.UserCacheKeyBuilder) PasswordRestVo(com.albedo.java.modules.sys.domain.vo.account.PasswordRestVo) Transactional(org.springframework.transaction.annotation.Transactional) UserRoleDo(com.albedo.java.modules.sys.domain.UserRoleDo) EntityExistException(com.albedo.java.common.core.exception.EntityExistException) UserDo(com.albedo.java.modules.sys.domain.UserDo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with UserDto

use of com.albedo.java.modules.sys.domain.dto.UserDto in project albedo by somowhere.

the class UserResource method saveInfo.

/**
 * 个人中心更新信息
 *
 * @param userInfoDto 用户信息
 * @return R
 */
@LogOperate(value = "用户管理编辑")
@PostMapping("/info")
public Result<String> saveInfo(@Valid @RequestBody UserInfoDto userInfoDto) {
    log.debug("REST request to save userDto : {}", userInfoDto);
    UserDto userDto = BeanUtil.copyPropertiesByClass(userInfoDto, UserDto.class);
    userDto.setId(SecurityUtil.getUser().getId());
    userDto.setUsername(SecurityUtil.getUser().getUsername());
    userService.saveOrUpdate(userDto);
    return Result.buildOk("更新成功");
}
Also used : UserDto(com.albedo.java.modules.sys.domain.dto.UserDto) LogOperate(com.albedo.java.common.log.annotation.LogOperate)

Aggregations

UserDto (com.albedo.java.modules.sys.domain.dto.UserDto)8 UserDo (com.albedo.java.modules.sys.domain.UserDo)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 BizException (com.albedo.java.common.core.exception.BizException)2 DeptDo (com.albedo.java.modules.sys.domain.DeptDo)2 RoleDo (com.albedo.java.modules.sys.domain.RoleDo)2 UserRoleDo (com.albedo.java.modules.sys.domain.UserRoleDo)2 ArrayUtil (cn.hutool.core.util.ArrayUtil)1 CacheKey (com.albedo.java.common.core.cache.model.CacheKey)1 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)1 CommonConstants (com.albedo.java.common.core.constant.CommonConstants)1 SecurityConstants (com.albedo.java.common.core.constant.SecurityConstants)1 EntityExistException (com.albedo.java.common.core.exception.EntityExistException)1 com.albedo.java.common.core.util (com.albedo.java.common.core.util)1 PageModel (com.albedo.java.common.core.vo.PageModel)1 LogOperate (com.albedo.java.common.log.annotation.LogOperate)1 SecurityUtil (com.albedo.java.common.security.util.SecurityUtil)1 RedisUtil (com.albedo.java.common.util.RedisUtil)1