去除多余的 createUser 方法

pull/1/head
YunaiV 2019-03-09 22:13:48 +08:00
parent f3fb8faf22
commit d9e97a05d9
6 changed files with 51 additions and 37 deletions

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.user.application.controller.users; package cn.iocoder.mall.user.application.controller;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.application.convert.PassportConvert; import cn.iocoder.mall.user.application.convert.PassportConvert;
@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("users/passport") @RequestMapping("user/passport")
@Api("Passport 模块") @Api("Passport 模块")
public class PassportController { public class PassportController {

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.user.application.controller.users; package cn.iocoder.mall.user.application.controller;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("users/user") @RequestMapping("/user")
@Api("用户模块") @Api("用户模块")
public class UserController { public class UserController {

View File

@ -1,5 +1,19 @@
package cn.iocoder.mall.user.service.api; package cn.iocoder.mall.user.service.api;
import cn.iocoder.common.framework.exception.ServiceException;
import cn.iocoder.mall.user.service.api.bo.UserBO;
public interface UserService { public interface UserService {
/**
*
*
* TODO ipua
*
* @param mobile
* @param code
* @return
*/
UserBO createUser(String mobile, String code) throws ServiceException;
} }

View File

@ -1,13 +1,13 @@
package cn.iocoder.mall.user.dataobject; package cn.iocoder.mall.user.dataobject;
import cn.iocoder.common.framework.dataobject.BaseDO; import java.util.Date;
/** /**
* *
* *
* idx_mobile * idx_mobile
*/ */
public class UserDO extends BaseDO { public class UserDO {
/** /**
* *
@ -18,13 +18,9 @@ public class UserDO extends BaseDO {
*/ */
private String mobile; private String mobile;
/** /**
* *
*/ */
private String nickname; private Date createTime;
/**
*
*/
private String avatar;
public Long getId() { public Long getId() {
return id; return id;
@ -44,22 +40,12 @@ public class UserDO extends BaseDO {
return this; return this;
} }
public String getNickname() { public Date getCreateTime() {
return nickname; return createTime;
} }
public UserDO setNickname(String nickname) { public UserDO setCreateTime(Date createTime) {
this.nickname = nickname; this.createTime = createTime;
return this; return this;
} }
public String getAvatar() {
return avatar;
}
public UserDO setAvatar(String avatar) {
this.avatar = avatar;
return this;
}
} }

View File

@ -61,11 +61,7 @@ public class OAuth2ServiceImpl implements OAuth2Service {
// 获取用户 // 获取用户
UserDO userDO = userService.getUser(mobile); UserDO userDO = userService.getUser(mobile);
if (userDO == null) { // 用户不存在,则进行创建用户 if (userDO == null) { // 用户不存在,则进行创建用户
CommonResult<UserDO> createResult = userService.createUser(mobile); userDO = userService.createUser(mobile);
if (createResult.isError()) {
return CommonResult.error(createResult);
}
userDO = createResult.getData();
Assert.notNull(userDO, "创建用户必然成功"); Assert.notNull(userDO, "创建用户必然成功");
} }
// 创建刷新令牌 // 创建刷新令牌

View File

@ -1,13 +1,14 @@
package cn.iocoder.mall.user.service; package cn.iocoder.mall.user.service;
import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.user.convert.UserConvert;
import cn.iocoder.mall.user.dao.UserMapper; import cn.iocoder.mall.user.dao.UserMapper;
import cn.iocoder.mall.user.dao.UserRegisterMapper; import cn.iocoder.mall.user.dao.UserRegisterMapper;
import cn.iocoder.mall.user.dataobject.UserDO; import cn.iocoder.mall.user.dataobject.UserDO;
import cn.iocoder.mall.user.dataobject.UserRegisterDO; import cn.iocoder.mall.user.dataobject.UserRegisterDO;
import cn.iocoder.mall.user.service.api.UserService; import cn.iocoder.mall.user.service.api.UserService;
import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum; import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum;
import cn.iocoder.mall.user.service.api.bo.UserBO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -31,21 +32,38 @@ public class UserServiceImpl implements UserService {
return userMapper.selectByMobile(mobile); return userMapper.selectByMobile(mobile);
} }
@Override
@Transactional @Transactional
public CommonResult<UserDO> createUser(String mobile) { public UserBO createUser(String mobile, String code) {
// TODO 芋艿,校验手机格式 // TODO 芋艿,校验手机格式
// 校验手机号的最后一个手机验证码是否有效
mobileCodeService.validLastMobileCode(mobile, code);
// 校验用户是否已经存在 // 校验用户是否已经存在
if (getUser(mobile) != null) { if (getUser(mobile) != null) {
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode()); throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode());
} }
// 创建用户 // 创建用户
UserDO userDO = new UserDO().setMobile(mobile); UserDO userDO = new UserDO().setMobile(mobile).setCreateTime(new Date());
userDO.setCreateTime(new Date());
userMapper.insert(userDO); userMapper.insert(userDO);
// 插入注册信息 // 插入注册信息
createUserRegister(userDO); createUserRegister(userDO);
// 转换返回 // 转换返回
return CommonResult.success(userDO); return UserConvert.INSTANCE.convert(userDO);
}
@Transactional
public UserDO createUser(String mobile) {
// 校验用户是否已经存在
if (getUser(mobile) != null) {
throw ServiceExceptionUtil.exception(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode());
}
// 创建用户
UserDO userDO = new UserDO().setMobile(mobile).setCreateTime(new Date());
userMapper.insert(userDO);
// 插入注册信息
createUserRegister(userDO);
// 转换返回
return userDO;
} }
private void createUserRegister(UserDO userDO) { private void createUserRegister(UserDO userDO) {