|
|
|
@ -17,7 +17,10 @@ import cn.iocoder.yudao.module.system.convert.user.UserConvert;
|
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.permission.UserRoleMapper; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; |
|
|
|
|
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants; |
|
|
|
|
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum; |
|
|
|
|
import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; |
|
|
|
@ -38,6 +41,7 @@ import me.chanjar.weixin.cp.api.WxCpService;
|
|
|
|
|
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager; |
|
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder; |
|
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
@ -63,6 +67,8 @@ public class AuthController {
|
|
|
|
|
@Resource |
|
|
|
|
private AdminUserService userService; |
|
|
|
|
@Resource |
|
|
|
|
private AdminUserMapper adminUserMapper; |
|
|
|
|
@Resource |
|
|
|
|
private RoleService roleService; |
|
|
|
|
@Resource |
|
|
|
|
private PermissionService permissionService; |
|
|
|
@ -77,6 +83,10 @@ public class AuthController {
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private AdminAuthServiceImpl adminAuthService; |
|
|
|
|
@Resource |
|
|
|
|
private UserRoleMapper userRoleMapper; |
|
|
|
|
@Resource |
|
|
|
|
private PasswordEncoder passwordEncoder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/login") |
|
|
|
@ -103,13 +113,29 @@ public class AuthController {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(cpuser)){ |
|
|
|
|
cpuser = cpUserService.getByUserId("test"); |
|
|
|
|
return CommonResult.error(ErrorCodeConstants.USER_NOT_EXISTS.getCode(),"未发现绑定的企业用户,暂时无法登录,请联系管理员"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AdminUserDO user = userService.getUserByUsername(cpuser.getUserId()); |
|
|
|
|
if (ObjectUtil.isEmpty(user)){ |
|
|
|
|
CommonResult.error(ErrorCodeConstants.USER_NOT_EXISTS.getCode(),"未发现绑定的企业用户,暂时无法登录,请联系管理员"); |
|
|
|
|
user = userService.getUserByUsername("test"); |
|
|
|
|
//第一次登录 注册一个系统用户
|
|
|
|
|
user = AdminUserDO.builder() |
|
|
|
|
.username(cpuser.getUserId()) |
|
|
|
|
.nickname(cpuser.getName()) |
|
|
|
|
.cpUserId(cpuser.getUserId()) |
|
|
|
|
.password((passwordEncoder.encode("123456"))) |
|
|
|
|
.cpUserId(cpuser.getUserId()) |
|
|
|
|
.build(); |
|
|
|
|
user.setTenantId(1L); |
|
|
|
|
adminUserMapper.insert(user); |
|
|
|
|
|
|
|
|
|
//设置默认角色 农场人员
|
|
|
|
|
UserRoleDO userRole = new UserRoleDO(); |
|
|
|
|
userRole.setUserId(user.getId()); |
|
|
|
|
userRole.setRoleId(112L); |
|
|
|
|
userRole.setTenantId(1L); |
|
|
|
|
userRoleMapper.insert(userRole); |
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
user.setCpUserId(cpuser.getUserId()); |
|
|
|
|
userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user)); |
|
|
|
|