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