/**
* @see UserWebService#createUser(UserDTO)
*/
public CreateUserResult createUser(UserDTO user) {
CreateUserResult result = new CreateUserResult();
//校验请求参数
try {
Assert.notNull(user, "用户参数为空");
Assert.hasText(user.getLoginName(), "新建用户登录名参数为空");
Assert.isNull(user.getId(), "新建用户ID参数必须为空");
} catch (IllegalArgumentException e) {
logger.error(e.getMessage());
return result.buildResult(WSResult.PARAMETER_ERROR, e.getMessage());
}
//保存用户
try {
User userEntity = dozer.map(user, User.class);
accountManager.saveUser(userEntity);
result.setUserId(userEntity.getId());
return result;
} catch (ConstraintViolationException e) {
String message = "新建用户参数存在唯一性冲突(用户:" + user + ")";
logger.error(message, e);
return result.buildResult(WSResult.PARAMETER_ERROR, message);
} catch (RuntimeException e) {
logger.error(e.getMessage(), e);
return result.buildDefaultErrorResult();
}
}