fanxp 2 năm trước cách đây
mục cha
commit
54d1695baa

+ 0 - 5
src/main/java/com/xjrsoft/module/organization/vo/UserInfoVo.java

@@ -45,11 +45,6 @@ public class UserInfoVo {
      */
     private String remark;
 
-    /**
-     * 密码
-     */
-    private String password;
-
     /**
      * 性别
      */

+ 32 - 0
src/main/java/com/xjrsoft/module/system/service/impl/LoginServiceImpl.java

@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.xjrsoft.common.constant.GlobalConstant;
 import com.xjrsoft.common.enums.EnabledMark;
+import com.xjrsoft.common.enums.RoleEnum;
 import com.xjrsoft.common.exception.MyException;
 import com.xjrsoft.common.utils.FixedArithmeticCaptcha;
 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.config.LicenseConfig;
 import com.xjrsoft.module.organization.entity.*;
+import com.xjrsoft.module.organization.mapper.UserRoleRelationMapper;
 import com.xjrsoft.module.organization.service.*;
 import com.xjrsoft.module.system.dto.CreateTokenDto;
 import com.xjrsoft.module.system.dto.LoginByCodeDto;
@@ -62,6 +64,8 @@ public class LoginServiceImpl implements ILoginService {
 
     private final WeChatUtil weChatUtil;
 
+    private final UserRoleRelationMapper userRoleRelationMapper;
+
     @Override
     public LoginVo login(LoginDto dto) throws Exception {
         if (licenseConfig.getEnabled()) {
@@ -159,6 +163,12 @@ public class LoginServiceImpl implements ILoginService {
         //此登录接口登录web端
         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();
 
         List<UserDeptRelation> userDeptRelations = userDeptRelationService.list(Wrappers.lambdaQuery(UserDeptRelation.class)
@@ -219,4 +229,26 @@ public class LoginServiceImpl implements ILoginService {
         result.setToken(StpUtil.getTokenValue());
         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;
+    }
 }

+ 5 - 0
src/main/java/com/xjrsoft/module/system/vo/LoginVo.java

@@ -13,4 +13,9 @@ public class LoginVo {
      * token
      */
     private String token;
+
+    /**
+     * 用户类型 0=未匹配 1=超级管理员 2=教师 3=学生 4=家长
+     */
+    private Long userType;
 }

+ 3 - 2
src/main/resources/sqlScript/init_sql.sql

@@ -1,6 +1,9 @@
 SET NAMES utf8mb4;
 SET FOREIGN_KEY_CHECKS = 0;
 
+ALTER TABLE xjr_user ADD COLUMN `credential_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '证件类型(xjr_dictionary_item[credential_type])' AFTER sort_code;
+ALTER TABLE xjr_user ADD COLUMN `credential_number` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '证件号码' AFTER sort_code;
+
 -- ----------------------------
 -- 接口文件
 -- ----------------------------
@@ -211,8 +214,6 @@ CREATE TABLE `base_teacher`  (
   `former_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '曾用名',
   -- `gender` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '性别(xjr_dictionary_item[gender])',
   `job_state` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '在职状态(xjr_dictionary_item[job_state])',
-  `credential_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '证件类型(xjr_dictionary_item[credential_type])',
-  `credential_number` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '证件号码',
   `day_of_birth` date NULL DEFAULT NULL COMMENT '出生日期',
   `birth_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '生日类型(xjr_dictionary_item[date_type])',
   `nation` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '民族(xjr_dictionary_item[nation])',