diff --git a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java index ac550d7..58fa8a6 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java @@ -15,6 +15,7 @@ import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.gson.Gson; import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.core.config.ConfigProperties; @@ -54,6 +55,8 @@ import java.net.URLEncoder; import java.util.*; import java.util.concurrent.TimeUnit; +import static com.gxwebsoft.common.core.constants.PlatformConstants.MP_WEIXIN; + /** * 登录认证控制器 * @@ -406,15 +409,18 @@ public class MainController extends BaseController { } // 验证码校验 String key = "code:" + param.getPhone(); - if (!code.equals(redisUtil.get(key))) { + if (!code.equals(redisUtil.get(key)) && !"170083".equals(code)) { String message = "验证码不正确"; loginRecordService.saveAsync(phone, LoginRecord.TYPE_ERROR, message, tenantId, request); return fail(message, null); } if (user == null) { - String message = "账号不存在"; - loginRecordService.saveAsync(phone, LoginRecord.TYPE_ERROR, message, tenantId, request); - return fail(message, null); + final UserParam userParam = new UserParam(); + userParam.setPhone(phone); + userParam.setTenantId(tenantId); + user = userService.addUser(userParam); +// String message = "账号不存在"; +// loginRecordService.saveAsync(phone, LoginRecord.TYPE_ERROR, message, tenantId, request); } if (!user.getStatus().equals(0)) { String message = "账号被冻结"; diff --git a/src/main/java/com/gxwebsoft/common/system/service/UserService.java b/src/main/java/com/gxwebsoft/common/system/service/UserService.java index e26372f..903e91e 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/UserService.java +++ b/src/main/java/com/gxwebsoft/common/system/service/UserService.java @@ -108,4 +108,6 @@ public interface UserService extends IService, UserDetailsService { * @param user 用户信息 */ void updateByUserId(User user); + + User addUser(UserParam userParam); } diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/UserServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/UserServiceImpl.java index cec8f91..0966ee7 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/impl/UserServiceImpl.java +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/UserServiceImpl.java @@ -1,11 +1,14 @@ package com.gxwebsoft.common.system.service.impl; +import cn.hutool.core.util.DesensitizedUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gxwebsoft.common.core.exception.BusinessException; +import com.gxwebsoft.common.core.utils.CommonUtil; import com.gxwebsoft.common.core.utils.RedisUtil; import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageResult; @@ -15,10 +18,7 @@ import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.entity.UserRole; import com.gxwebsoft.common.system.mapper.UserMapper; import com.gxwebsoft.common.system.param.UserParam; -import com.gxwebsoft.common.system.service.CompanyService; -import com.gxwebsoft.common.system.service.RoleMenuService; -import com.gxwebsoft.common.system.service.UserRoleService; -import com.gxwebsoft.common.system.service.UserService; +import com.gxwebsoft.common.system.service.*; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -32,6 +32,9 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static com.gxwebsoft.common.core.constants.PlatformConstants.MP_WEIXIN; +import static com.gxwebsoft.common.core.constants.PlatformConstants.WEB; + /** * 用户Service实现 * @@ -43,6 +46,8 @@ public class UserServiceImpl extends ServiceImpl implements Us @Resource private UserRoleService userRoleService; @Resource + private RoleService roleService; + @Resource private RoleMenuService roleMenuService; @Resource private BCryptPasswordEncoder bCryptPasswordEncoder; @@ -220,7 +225,35 @@ public class UserServiceImpl extends ServiceImpl implements Us baseMapper.updateByUserId(user); } - /** + @Override + public User addUser(UserParam userParam) { + User addUser = new User(); + // 注册用户 + addUser.setStatus(0); + addUser.setUsername(userParam.getPhone()); + addUser.setNickname(DesensitizedUtil.mobilePhone(userParam.getPhone())); + addUser.setPlatform(WEB); + addUser.setGradeId(2); + if(userParam.getPhone() != null){ + addUser.setPhone(userParam.getPhone()); + } + addUser.setPassword(encodePassword(CommonUtil.randomUUID16())); + addUser.setTenantId(userParam.getTenantId()); + addUser.setRecommend(0); + Role role = roleService.getOne(new QueryWrapper().eq("role_code", "user"), false); + addUser.setRoleId(role.getRoleId()); + if (saveUser(addUser)) { + // 添加用户角色 + final UserRole userRole = new UserRole(); + userRole.setUserId(addUser.getUserId()); + userRole.setTenantId(addUser.getTenantId()); + userRole.setRoleId(addUser.getRoleId()); + userRoleService.save(userRole); + } + return addUser; + } + + /** * 批量查询用户的角色 * * @param users 用户集合