ソースを参照

829 早上提交

LT32820A 2 ヶ月 前
コミット
b1aad44696

+ 0 - 4
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/AppmanageController.java

@@ -168,8 +168,4 @@ public class AppmanageController {
         return Result.ok(appInfoService.isAppAdminOrDevOrOpe(appid));
     }
 
-    @GetMapping("/addAppUserRoleInfos")
-    public void addAppUserRoleInfos(SysUserRole sysUserRole){
-        appInfoService.addAppUserRoleInfos(sysUserRole);
-    }
 }

+ 0 - 1
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/entity/AppmanageEntity/AppUserInfo.java

@@ -18,5 +18,4 @@ public class AppUserInfo {
     private String id;
     private String appid;
     private String userid;
-    private String roles;
 }

+ 0 - 1
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/AppmanageService.java

@@ -59,6 +59,5 @@ public interface AppmanageService {
     // 是否为应用管理员或开发负责人、运维负责人
     boolean isAppAdminOrDevOrOpe(String appid);
 
-    boolean addAppUserRoleInfos(SysUserRole sysUserRole);
 }
 

+ 49 - 80
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/AppmanageServiceImpl.java

@@ -135,7 +135,6 @@ public class AppmanageServiceImpl implements AppmanageService {
             AppUserInfo userInfo = new AppUserInfo();
             userInfo.setAppid(appid);
             userInfo.setUserid(userid);
-            userInfo.setRoles(roleid);
             useridlist.add(userid);
             userInfoMapper.insert(userInfo);
         });
@@ -202,43 +201,36 @@ public class AppmanageServiceImpl implements AppmanageService {
         LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
 
         // 查询当前应用的应用管理员信息
-        if (ids.length == 1){  // 删除单条信息时
-            QueryWrapper<AppBaseInfo> baseInfoPOQueryWrapper = new QueryWrapper<>();
-            baseInfoPOQueryWrapper.select("admin").in("id", ids[0]);
-            AppBaseInfo appBaseInfo = baseInfoMapper.selectOne(baseInfoPOQueryWrapper);
-            if (!appBaseInfo.getAdmin().equals(loginUser.getId())) return false;
-        }else {  //  批量删除应用信息时,如果有一个应用不是当前登录用户所创建,则返回false
-            for (String id : ids) {
-                // 不能删除基础平台的应用信息
-                if (id.equals("0")) return false;
-                AppBaseInfo appBaseInfo = baseInfoMapper.selectById(id);
-                if (!appBaseInfo.getAdmin().equals(loginUser.getId())) return false;
-
-                // 删除所属该应用的基础信息、环境信息、文档信息、用户信息
-                baseInfoMapper.deleteById(id);
-                envInfoMapper.delete(new QueryWrapper<AppEnvInfo>().eq("appid", id));
-                docInfoMapper.delete(new QueryWrapper<AppDocInfo>().eq("appid", id));
-                // 简易注册下的应用信息不具备用户、菜单、权限等信息,所有不需要删除
-                if (appBaseInfo.getAddType().equals("easy")) return true ;
-                userInfoMapper.delete(new QueryWrapper<AppUserInfo>().eq("appid", id));
-
-                // 删除该应用下所创建的菜单
-                // 查询该应用的一级菜单
-                LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
-                query.eq(SysPermission::getMenuType,CommonConstant.MENU_TYPE_0);
-                query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
-                query.eq(SysPermission::getAppId, id);
-                List<SysPermission> list = sysPermissionService.list(query);
-                for (SysPermission sysPermission : list){
-                    sysPermissionService.deletePermission(sysPermission.getId());
-                }
+        for (String id : ids) {
+            // 不能删除基础平台的应用信息
+            if (id.equals("0")) return false;
+            AppBaseInfo appBaseInfo = baseInfoMapper.selectById(id);
+            if (!(appBaseInfo.getAdmin().equals(loginUser.getId()))) return false;
+
+            // 删除所属该应用的基础信息、环境信息、文档信息、用户信息
+            baseInfoMapper.deleteById(id);
+            envInfoMapper.delete(new QueryWrapper<AppEnvInfo>().eq("appid", id));
+            docInfoMapper.delete(new QueryWrapper<AppDocInfo>().eq("appid", id));
+            // 简易注册下的应用信息不具备用户、菜单、权限等信息,所有不需要删除
+            if (appBaseInfo.getAddType().equals("easy")) break;
+            userInfoMapper.delete(new QueryWrapper<AppUserInfo>().eq("appid", id));
+
+            // 删除该应用下所创建的菜单
+            // 查询该应用的一级菜单
+            LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
+            query.eq(SysPermission::getMenuType,CommonConstant.MENU_TYPE_0);
+            query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
+            query.eq(SysPermission::getAppId, id);
+            List<SysPermission> list = sysPermissionService.list(query);
+            for (SysPermission sysPermission : list){
+                sysPermissionService.deletePermission(sysPermission.getId());
+            }
 
-                // 删除该应用下所创建的角色信息
-                String[] Approleids = sysRoleService.listRoleIdsByAppId(id);
-                if (Approleids!=null){
-                    boolean tag = sysRoleService.deleteBatchRole(Approleids);
-                    if (!tag) return false;
-                }
+            // 删除该应用下所创建的角色信息
+            String[] Approleids = sysRoleService.listRoleIdsByAppId(id);
+            if (Approleids!=null){
+                boolean tag = sysRoleService.deleteBatchRole(Approleids);
+                if (!tag) return false;
             }
         }
         // 记录日志
@@ -301,20 +293,22 @@ public class AppmanageServiceImpl implements AppmanageService {
     @Transactional
     public Boolean editUserInfo(AppUpdataUserInfo updataUserInfo) {
         String appid = updataUserInfo.getAppid();
-        // 删除用户 删除应用用户默认权限
+        // 移除应用用户时,将去角色收回
         if (updataUserInfo.getDelUserids()!=null&&!updataUserInfo.getDelUserids().isEmpty()){
             updataUserInfo.getDelUserids().forEach(userid -> {
                 System.out.println("删除用户:"+userid);
+                // 获取要移除的用户的信息
                 QueryWrapper<AppUserInfo> userInfoPOQueryWrapper = new QueryWrapper<>();
                 userInfoPOQueryWrapper.eq("appid",appid).eq("userid",userid);
-                AppUserInfo userInfoPO = userInfoMapper.selectOne(userInfoPOQueryWrapper);
-                // 先去除字符串两端的空格
-                String userDefaultRoleId = userInfoPO.getRoles().trim();
-                // 根据逗号分割字符串
-                String[] parts = userDefaultRoleId.split(",");
-                QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
-                queryWrapper.eq("role_id", parts[0]).eq("user_id",userid);
-                sysUserRoleService.remove(queryWrapper);
+                AppUserInfo userInfo = userInfoMapper.selectOne(userInfoPOQueryWrapper);
+                // 获取该用户在该应用下的角色信息
+                List<String> roleIds = sysUserRoleService.listByAppId(appid, userid);
+                // 删除该用户在该应用下的角色信息
+                roleIds.forEach(roleId -> {
+                    QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
+                    queryWrapper.eq("role_id", roleId).eq("user_id",userid);
+                    sysUserRoleService.remove(queryWrapper);
+                });
                 QueryWrapper<AppUserInfo> wrapper = new QueryWrapper<>();
                 wrapper.eq("appid",updataUserInfo.getAppid()).eq("userid",userid);
                 userInfoMapper.delete(wrapper);
@@ -470,25 +464,22 @@ public class AppmanageServiceImpl implements AppmanageService {
                 AppBaseInfo appBaseInfo = baseInfoMapper.selectById(queryParams.getAppid());
                 // 查询用户角色信息
                 appUserInfos.forEach(map -> {
-                    QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
-                    appUserInfoQueryWrapper.select("roles")
-                            .eq("userid", map.get("id")).eq("appid", queryParams.getAppid());
-                    AppUserInfo roleInfo = userInfoMapper.selectOne(appUserInfoQueryWrapper);
-                    // 查询应用基础信息的相关用户信息
                     String roleNameInfo = baseInfoToUserInfoRoles(appBaseInfo, (String) map.get("id"));
-                    // 使用 Stream API 将字符串转换为 List
-                    if (roleInfo!=null){
-                        // 将应用用户表中存的的角色信息字符串转换为List
-                        List<String> list = Arrays.stream(roleInfo.getRoles().split(","))
-                                .collect(Collectors.toList());
-                        QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
-                        sysRoleQueryWrapper.select("role_name").in("id", list);
+                    List<String> roleIds = sysUserRoleService.listByAppId(queryParams.getAppid(), (String) map.get("id"));
+
+                    if (!roleIds.isEmpty()){
                         // 查询角色名信息
+                        QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
+                        sysRoleQueryWrapper.select("role_name").in("id", roleIds);
                         List<SysRole> sysRoles = sysRoleMapper.selectList(sysRoleQueryWrapper);
                         if (!sysRoles.isEmpty()&&!roleNameInfo.isEmpty()){
                             roleNameInfo =roleNameInfo +", "+ sysRoles.stream()
                                     .map(SysRole::getRoleName)
                                     .collect(Collectors.joining(", "));
+                        }else {
+                            roleNameInfo = sysRoles.stream()
+                                    .map(SysRole::getRoleName)
+                                    .collect(Collectors.joining(", "));
                         }
                     }
                     map.put("roles", roleNameInfo);
@@ -619,28 +610,6 @@ public class AppmanageServiceImpl implements AppmanageService {
         return false;
     }
 
-    /**
-     * 角色分配用户时添加应用用户角色信息
-     * @param sysUserRole
-     */
-    @Override
-    public boolean addAppUserRoleInfos(SysUserRole sysUserRole){
-        // 根据角色id查询所属的应用id
-        SysRole sysRole = sysRoleMapper.selectById(sysUserRole.getRoleId());
-        String appid = sysRole.getAppId();
-        QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
-        // 先查询应用用户原来的角色信息,若为空,则直接更新,若不为空,将原角色信息与新的角色信息进行拼接后再更新,新旧角色id信息通过逗号分隔的字符串
-        appUserInfoQueryWrapper.eq("appid",appid).eq("userid",sysUserRole.getUserId());
-        AppUserInfo appUserInfo = userInfoMapper.selectOne(appUserInfoQueryWrapper);
-        String appUserRolesInfo = appUserInfo.getRoles();
-        if (appUserRolesInfo!=null){
-            appUserInfo.setRoles(appUserRolesInfo+","+sysUserRole.getRoleId());
-        }else {
-            appUserInfo.setRoles(sysUserRole.getRoleId());
-        }
-        int i = userInfoMapper.updateById(appUserInfo);
-        return i>0;
-    }
 
     private String baseInfoToUserInfoRoles(AppBaseInfo appBaseInfo, String userid){
         String roleNameInfo = "";