Browse Source

企业用户 注册 系统用户 并给权限

zyh
小久哥 3 years ago
parent
commit
9bc848dd96
  1. 32
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
  2. 4
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/permission/UserRoleDO.java

32
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java

@ -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.CpUser.CpUserDO;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; 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.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.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.ErrorCodeConstants;
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum; import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
import cn.iocoder.yudao.module.system.service.CpUser.CpUserService; 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 me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -63,6 +67,8 @@ public class AuthController {
@Resource @Resource
private AdminUserService userService; private AdminUserService userService;
@Resource @Resource
private AdminUserMapper adminUserMapper;
@Resource
private RoleService roleService; private RoleService roleService;
@Resource @Resource
private PermissionService permissionService; private PermissionService permissionService;
@ -77,6 +83,10 @@ public class AuthController {
@Resource @Resource
private AdminAuthServiceImpl adminAuthService; private AdminAuthServiceImpl adminAuthService;
@Resource
private UserRoleMapper userRoleMapper;
@Resource
private PasswordEncoder passwordEncoder;
@PostMapping("/login") @PostMapping("/login")
@ -103,13 +113,29 @@ public class AuthController {
} }
if (ObjectUtil.isEmpty(cpuser)){ if (ObjectUtil.isEmpty(cpuser)){
cpuser = cpUserService.getByUserId("test"); return CommonResult.error(ErrorCodeConstants.USER_NOT_EXISTS.getCode(),"未发现绑定的企业用户,暂时无法登录,请联系管理员");
} }
AdminUserDO user = userService.getUserByUsername(cpuser.getUserId()); AdminUserDO user = userService.getUserByUsername(cpuser.getUserId());
if (ObjectUtil.isEmpty(user)){ 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 { }else {
user.setCpUserId(cpuser.getUserId()); user.setCpUserId(cpuser.getUserId());
userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user)); userService.updateUser(UserConvert.INSTANCE.convertFromEntity(user));

4
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/permission/UserRoleDO.java

@ -1,8 +1,10 @@
package cn.iocoder.yudao.module.system.dal.dataobject.permission; package cn.iocoder.yudao.module.system.dal.dataobject.permission;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -14,7 +16,7 @@ import lombok.EqualsAndHashCode;
@TableName("system_user_role") @TableName("system_user_role")
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class UserRoleDO extends BaseDO { public class UserRoleDO extends TenantBaseDO {
/** /**
* 自增主键 * 自增主键

Loading…
Cancel
Save