Explorar o código

删除用户的时候把权限相关进行删除

夏文涛 %!s(int64=2) %!d(string=hai) anos
pai
achega
134df6543d

+ 43 - 3
src/main/java/com/template/controller/SmartUserController.java

@@ -115,6 +115,9 @@ public class SmartUserController implements SmartUserControllerAPI {
     @Autowired
     private SmartTeachingService smartTeachingService;
 
+    @Autowired
+    private SmartAuthorGroupService smartAuthorGroupService;
+
     private static Logger logger = LoggerFactory.getLogger(SmartUserController.class);
 
     //region 开发自己导数据用的接口
@@ -4639,8 +4642,8 @@ public class SmartUserController implements SmartUserControllerAPI {
     @Override
     @DESRespondSecret(validated = true)
     public CommonResult getPage(int currentPage, int pageCount, String keyWord) {
-        LambdaQueryWrapper<SmartUser> wrapper=new LambdaQueryWrapper<>();
-        wrapper.like(ObjectUtils.isNotEmpty(keyWord),SmartUser::getName,keyWord);
+        LambdaQueryWrapper<SmartUser> wrapper = new LambdaQueryWrapper<>();
+        wrapper.like(ObjectUtils.isNotEmpty(keyWord), SmartUser::getName, keyWord);
         IPage<SmartUser> page = smartUserService.page(new Page<>(currentPage, pageCount), wrapper);
 
         return CommonResult.ok(page);
@@ -5282,7 +5285,44 @@ public class SmartUserController implements SmartUserControllerAPI {
 
         if (deleteUsers != null && deleteUsers.size() > 0) {
             int deleteUser = smartUserService.deleteUserBatch(deleteUsers);
-            return deleteUser > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
+            if (deleteUser > 0) {
+                List<SmartAuthorGroup> allDatas = new ArrayList<>();//要被更新的权限组数据
+                List<Integer> deleteGroupId = new ArrayList<>();//要被删除的权限组
+                List<Integer> deleteUserId = new ArrayList<>();//要被删除的管理组权限
+                for (deleteUserVo dUser : deleteUsers) {
+                    deleteUserId.add(dUser.getId());
+                    List<SmartAuthorGroup> authGroups = smartAuthorGroupService.smartAuthorGroup(dUser.getId());
+                    for (SmartAuthorGroup authGroup : authGroups) {
+                        List<String> newUserId = new ArrayList<>();
+                        List<String> userIds = Arrays.asList(authGroup.getUserId().split(","));
+                        for (String userId:userIds) {
+                            if(!userId.equals(String.valueOf(dUser.getId()))){
+                                newUserId.add(userId);
+                            }
+                        }
+                        if(newUserId != null && newUserId.size() > 0){
+                            authGroup.setUserId(StringUtils.join(newUserId,","));
+                            allDatas.add(authGroup);
+                        }else{
+                            deleteGroupId.add(authGroup.getId());
+                        }
+                    }
+                }
+
+                if(allDatas != null && allDatas.size() > 0){//更新权限组
+                    smartAuthorGroupService.saveBatch(allDatas);
+                }
+                if(deleteGroupId != null && deleteGroupId.size() > 0){//删除权限组
+                    smartAuthorGroupService.deleteSmartAuthorGroupByIds(deleteGroupId);
+                }
+                if(deleteUserId != null && deleteUserId.size() > 0){//删除管理组权限
+                    smartAuthorityService.deleteAuthorityByUserIds(deleteUserId);
+                }
+            } else {
+                return CommonResult.fail("删除失败");
+            }
+
+
         }
 
         return CommonResult.ok("删除成功");

+ 2 - 1
src/main/java/com/template/services/SmartAuthorGroupService.java

@@ -27,6 +27,8 @@ public interface SmartAuthorGroupService extends IService<SmartAuthorGroup> {
 
     int deleteSmartAuthorGroupById(int id);
 
+    int deleteSmartAuthorGroupByIds(List<Integer> ids);
+
     SmartAuthorGroup getSmartById(int id);
 
     List<SmartAuthorGroup> getAuthorGroupList();
@@ -41,7 +43,6 @@ public interface SmartAuthorGroupService extends IService<SmartAuthorGroup> {
 
     List<SmartAuthorGroupManager> getSmartAuthorGroupManager(String groupId);
 
-
     SmartAuthorGroup getByUserId(String userId);
 
 }

+ 2 - 0
src/main/java/com/template/services/SmartAuthorityService.java

@@ -32,4 +32,6 @@ public interface SmartAuthorityService extends IService<SmartAuthority> {
     SmartAuthority getByUserId(String userId);
 
     int deleteAuthorityByUsergroup(List<Integer> userIds,Integer groupId);
+
+    int deleteAuthorityByUserIds(List<Integer> userIds);
 }

+ 6 - 0
src/main/java/com/template/services/impl/SmartAuthorGroupServiceImpl.java

@@ -70,6 +70,12 @@ public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMap
     }
 
     @Override
+    public int deleteSmartAuthorGroupByIds(List<Integer> ids) {
+        int result = smartAuthorGroupMapper.deleteBatchIds(ids);
+        return result;
+    }
+
+    @Override
     public SmartAuthorGroup getSmartById(int id) {
         SmartAuthorGroup result = smartAuthorGroupMapper.selectById(id);
         return result;

+ 8 - 0
src/main/java/com/template/services/impl/SmartAuthorityServiceImpl.java

@@ -88,4 +88,12 @@ public class SmartAuthorityServiceImpl extends ServiceImpl<SmartAuthorityMapper,
         return result;
     }
 
+    @Override
+    public int deleteAuthorityByUserIds(List<Integer> userIds) {
+        QueryWrapper queryWrapper = new QueryWrapper();
+        queryWrapper.in(userIds != null && userIds.size() > 0,"user_id",userIds);
+        int result = smartAuthorityMapper.delete(queryWrapper);
+        return result;
+    }
+
 }