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;
}
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);
}
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);
}
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);
}
}
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("更新成功");
}
Aggregations