Browse Source

登陆接口权限修改

sl 10 months ago
parent
commit
67d4aa4d6a

+ 6 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockSystemLimit/mapper/InterlockSystemLimitMapper.java

@@ -15,9 +15,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface InterlockSystemLimitMapper extends BaseMapper<InterlockSystemLimit> {
 
-    //系统管理员权限 查询所有系统并将系统权限赋成管理0用于展示
+    //登陆时系统管理员权限 查询所有系统并将系统权限赋成管理0用于展示
     @Select("select #{username} as create_by, b.id as interlock_system_id, b.pid as interlock_apparatus_id, #{userId} as interlock_user_id, '0' as limit_type from (select * from interlock_base where interlock_type = '1') b")
-    List<InterlockSystemLimit> getInterlockSystemLimitList(@Param("username") String username, @Param("userId") String userId);
+    List<InterlockSystemLimit> getInterlockAdminSystemLimitList(@Param("username") String username, @Param("userId") String userId);
+
+    //登陆时普通用户权限 查询所有系统并将系统权限赋成既不管理也不查看null或者""用于展示
+    @Select("select #{username} as create_by, b.id as interlock_system_id, b.pid as interlock_apparatus_id, #{userId} as interlock_user_id, null as limit_type from (select * from interlock_base where interlock_type = '1') b")
+    List<InterlockSystemLimit> getInterlockPtSystemLimitList(@Param("username") String username, @Param("userId") String userId);
 
     List<InterlockSystemLimit> selectListByUserId(@Param("userId") String id);
 }

+ 6 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockSystemLimit/service/IInterlockSystemLimitService.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.interlockSystemLimit.service;
 
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 import org.jeecg.modules.interlockSystemLimit.entity.InterlockSystemLimit;
 import com.baomidou.mybatisplus.extension.service.IService;
 
@@ -14,8 +15,11 @@ import java.util.List;
  */
 public interface IInterlockSystemLimitService extends IService<InterlockSystemLimit> {
 
-    //系统管理员权限 查询所有系统并将系统权限赋成管理0用于展示
-    List<InterlockSystemLimit> getInterlockSystemLimitList(String username, String userId);
+    //登陆时系统管理员权限 查询所有系统并将系统权限赋成管理0用于展示
+    List<InterlockSystemLimit> getInterlockAdminSystemLimitList(String username, String userId);
+
+    //登陆时普通用户权限 查询所有系统并将系统权限赋成既不管理也不查看null或者""用于展示
+    List<InterlockSystemLimit> getInterlockPtSystemLimitList(String username, String userId);
 
     List<InterlockSystemLimit> selectListByUserId(String id);
 }

+ 7 - 2
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockSystemLimit/service/impl/InterlockSystemLimitServiceImpl.java

@@ -24,8 +24,13 @@ public class InterlockSystemLimitServiceImpl extends ServiceImpl<InterlockSystem
     private InterlockSystemLimitMapper interlockSystemLimitMapper;
 
     //系统管理员权限 查询所有系统并将系统权限赋成管理0用于展示
-    public List<InterlockSystemLimit> getInterlockSystemLimitList(String username, String userId){
-        return interlockSystemLimitMapper.getInterlockSystemLimitList(username, userId);
+    public List<InterlockSystemLimit> getInterlockAdminSystemLimitList(String username, String userId){
+        return interlockSystemLimitMapper.getInterlockAdminSystemLimitList(username, userId);
+    }
+
+    //登陆时普通用户权限 查询所有系统并将系统权限赋成既不管理也不查看null或者""用于展示
+    public List<InterlockSystemLimit> getInterlockPtSystemLimitList(String username, String userId){
+        return interlockSystemLimitMapper.getInterlockPtSystemLimitList(username, userId);
     }
 
     @Autowired

+ 33 - 1
jeecg-module-interlock/src/main/java/org/jeecg/modules/ssoClient/controller/SSOLoginLogoutController.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.ssoClient.controller;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
@@ -359,6 +360,12 @@ public class SSOLoginLogoutController {
             log.info("用户在本系统不存在,新增该用户");
             JSONObject addJSONObject = toAddInterlockUserJSONObject(username, ssoRole);
             addInterlockUser(addJSONObject);
+        }else{
+            if(ssoRole.equals("globalAdmin")){//已经存在的用户如果是系统管理员,更新用户、用户角色以及权限表
+                if(!interlockUser.getRole().equals("0")){
+                    editInterlockAdminUser(interlockUser);
+                }
+            }
         }
 
 //        SysUser sysUser1 = sysUserService.getUserAll(username);
@@ -409,7 +416,10 @@ public class SSOLoginLogoutController {
             //创建一个用户权限列表,用来存放系统权限信息 填充权限信息列表
             //系统管理员获取全部权限,否则无任何权限
             if(isAdmin.equals("1")){
-                List<InterlockSystemLimit> interlockSystemLimitList = interlockSystemLimitService.getInterlockSystemLimitList(username, userId);
+                List<InterlockSystemLimit> interlockSystemLimitList = interlockSystemLimitService.getInterlockAdminSystemLimitList(username, userId);
+                interlockSystemLimitService.saveBatch(interlockSystemLimitList);
+            }else{
+                List<InterlockSystemLimit> interlockSystemLimitList = interlockSystemLimitService.getInterlockPtSystemLimitList(username, userId);
                 interlockSystemLimitService.saveBatch(interlockSystemLimitList);
             }
             baseCommonService.addLog("添加用户,username: " + username, CommonConstant.LOG_TYPE_2, 2);
@@ -418,6 +428,28 @@ public class SSOLoginLogoutController {
         }
     }
 
+    private void editInterlockAdminUser(InterlockUser interlockUser){
+        try{
+            //更新用户信息
+            interlockUser.setRole("0");//系统管理员
+            interlockUserService.updateById(interlockUser);
+            String userId = interlockUser.getId();
+
+            //先删后加  用户角色表
+            sysUserRoleService.remove(new QueryWrapper<SysUserRole>().lambda().eq(SysUserRole::getUserId, userId));
+            SysUserRole userRole = new SysUserRole(userId, "1820384671259701250");
+            sysUserRoleService.save(userRole);
+
+            //先删后加  系统权限表
+            interlockSystemLimitService.remove(new QueryWrapper<InterlockSystemLimit>().lambda().eq(InterlockSystemLimit::getInterlockUserId, userId));
+            List<InterlockSystemLimit> interlockSystemLimitList = interlockSystemLimitService.getInterlockAdminSystemLimitList(interlockUser.getUsername(), userId);
+            interlockSystemLimitService.saveBatch(interlockSystemLimitList);
+            baseCommonService.addLog("修改用户,username: " + interlockUser.getUsername(), CommonConstant.LOG_TYPE_2, 2);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
     private JSONObject toAddJSONObject(String username, String password){
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("workNo", "");