|
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
import com.xjrsoft.common.enums.EnabledMark;
|
|
import com.xjrsoft.common.enums.EnabledMark;
|
|
|
|
|
+import com.xjrsoft.common.enums.RoleEnum;
|
|
|
import com.xjrsoft.common.exception.MyException;
|
|
import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.utils.FixedArithmeticCaptcha;
|
|
import com.xjrsoft.common.utils.FixedArithmeticCaptcha;
|
|
|
import com.xjrsoft.common.utils.RSAUtil;
|
|
import com.xjrsoft.common.utils.RSAUtil;
|
|
@@ -20,6 +21,7 @@ import com.xjrsoft.common.utils.RedisUtil;
|
|
|
import com.xjrsoft.common.utils.WeChatUtil;
|
|
import com.xjrsoft.common.utils.WeChatUtil;
|
|
|
import com.xjrsoft.config.LicenseConfig;
|
|
import com.xjrsoft.config.LicenseConfig;
|
|
|
import com.xjrsoft.module.organization.entity.*;
|
|
import com.xjrsoft.module.organization.entity.*;
|
|
|
|
|
+import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
|
|
|
import com.xjrsoft.module.organization.service.*;
|
|
import com.xjrsoft.module.organization.service.*;
|
|
|
import com.xjrsoft.module.system.dto.CreateTokenDto;
|
|
import com.xjrsoft.module.system.dto.CreateTokenDto;
|
|
|
import com.xjrsoft.module.system.dto.LoginByCodeDto;
|
|
import com.xjrsoft.module.system.dto.LoginByCodeDto;
|
|
@@ -62,6 +64,8 @@ public class LoginServiceImpl implements ILoginService {
|
|
|
|
|
|
|
|
private final WeChatUtil weChatUtil;
|
|
private final WeChatUtil weChatUtil;
|
|
|
|
|
|
|
|
|
|
+ private final UserRoleRelationMapper userRoleRelationMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public LoginVo login(LoginDto dto) throws Exception {
|
|
public LoginVo login(LoginDto dto) throws Exception {
|
|
|
if (licenseConfig.getEnabled()) {
|
|
if (licenseConfig.getEnabled()) {
|
|
@@ -159,6 +163,12 @@ public class LoginServiceImpl implements ILoginService {
|
|
|
//此登录接口登录web端
|
|
//此登录接口登录web端
|
|
|
StpUtil.login(loginUser.getId(), loginType);
|
|
StpUtil.login(loginUser.getId(), loginType);
|
|
|
|
|
|
|
|
|
|
+ // 获取用户类型(根据固定角色进行匹配)
|
|
|
|
|
+ List<UserRoleRelation> relations = userRoleRelationMapper.selectList(Wrappers.lambdaQuery(UserRoleRelation.class)
|
|
|
|
|
+ .select(UserRoleRelation::getRoleId)
|
|
|
|
|
+ .eq(UserRoleRelation::getUserId, StpUtil.getLoginIdAsLong()));
|
|
|
|
|
+ result.setUserType(roleMatching(relations));
|
|
|
|
|
+
|
|
|
SaSession tokenSession = StpUtil.getTokenSession();
|
|
SaSession tokenSession = StpUtil.getTokenSession();
|
|
|
|
|
|
|
|
List<UserDeptRelation> userDeptRelations = userDeptRelationService.list(Wrappers.lambdaQuery(UserDeptRelation.class)
|
|
List<UserDeptRelation> userDeptRelations = userDeptRelationService.list(Wrappers.lambdaQuery(UserDeptRelation.class)
|
|
@@ -219,4 +229,26 @@ public class LoginServiceImpl implements ILoginService {
|
|
|
result.setToken(StpUtil.getTokenValue());
|
|
result.setToken(StpUtil.getTokenValue());
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 角色匹配
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private Long roleMatching(List<UserRoleRelation> relations){
|
|
|
|
|
+ for (UserRoleRelation role :relations) {
|
|
|
|
|
+ if (role.getRoleId() == RoleEnum.PARENT.getCode()) {
|
|
|
|
|
+ return RoleEnum.PARENT.getCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (role.getRoleId() == RoleEnum.TEACHER.getCode()) {
|
|
|
|
|
+ return RoleEnum.TEACHER.getCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (role.getRoleId() == RoleEnum.STUDENT.getCode()) {
|
|
|
|
|
+ return RoleEnum.STUDENT.getCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (role.getRoleId() == RoleEnum.ADMIN.getCode()) {
|
|
|
|
|
+ return RoleEnum.ADMIN.getCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0L;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|