@Test public void createGroup() { PermissionDO permission1 = PermissionDO.builder().name("权限1").module("炉石传说").build(); PermissionDO permission2 = PermissionDO.builder().name("权限2").module("炉石传说").build(); permissionMapper.insert(permission1); permissionMapper.insert(permission2); NewGroupDTO dto = new NewGroupDTO(); dto.setName("测试分组1"); dto.setInfo("just for test"); dto.setPermissionIds(Arrays.asList(permission1.getId(), permission2.getId())); boolean ok = adminService.createGroup(dto); assertTrue(ok); QueryWrapper<GroupDO> wrapper = new QueryWrapper<>(); wrapper.lambda().eq(GroupDO::getName, "测试分组1"); GroupDO group = groupMapper.selectOne(wrapper); assertEquals("测试分组1", group.getName()); assertEquals("just for test", group.getInfo()); GroupPermissionsBO groupPermissions = adminService.getGroup(group.getId()); boolean anyMatch = groupPermissions.getPermissions().stream().anyMatch(it -> { PermissionDO p = (PermissionDO) it; return p.getName().equals("权限1"); }); assertTrue(anyMatch); }
@Transactional @Override public boolean createGroup(NewGroupDTO dto) { throwGroupNameExist(dto.getName()); GroupDO group = GroupDO.builder().name(dto.getName()).info(dto.getInfo()).build(); groupService.save(group); if (dto.getPermissionIds() != null && !dto.getPermissionIds().isEmpty()) { List<GroupPermissionDO> relations = dto.getPermissionIds().stream() .map(id -> new GroupPermissionDO(group.getId(), id)) .collect(Collectors.toList()); groupPermissionMapper.insertBatch(relations); } return true; }
AdminServiceImpl implements AdminService { @Transactional @Override public boolean createGroup(NewGroupDTO dto) { throwGroupNameExist(dto.getName()); GroupDO group = GroupDO.builder().name(dto.getName()).info(dto.getInfo()).build(); groupService.save(group); if (dto.getPermissionIds() != null && !dto.getPermissionIds().isEmpty()) { List<GroupPermissionDO> relations = dto.getPermissionIds().stream() .map(id -> new GroupPermissionDO(group.getId(), id)) .collect(Collectors.toList()); groupPermissionMapper.insertBatch(relations); } return true; } }
AdminServiceImpl implements AdminService { @Transactional @Override public boolean createGroup(NewGroupDTO dto) { throwGroupNameExist(dto.getName()); GroupDO group = GroupDO.builder().name(dto.getName()).info(dto.getInfo()).build(); groupService.save(group); if (dto.getPermissionIds() != null && !dto.getPermissionIds().isEmpty()) { List<GroupPermissionDO> relations = dto.getPermissionIds().stream() .map(id -> new GroupPermissionDO(group.getId(), id)) .collect(Collectors.toList()); groupPermissionMapper.insertBatch(relations); } return true; }  }
AdminServiceImpl implements AdminService { @Transactional @Override public boolean createGroup(NewGroupDTO dto) { throwGroupNameExist(dto.getName()); GroupDO group = GroupDO.builder().name(dto.getName()).info(dto.getInfo()).build(); groupService.save(group); if (dto.getPermissionIds() != null && !dto.getPermissionIds().isEmpty()) { List<GroupPermissionDO> relations = dto.getPermissionIds().stream() .map(id -> new GroupPermissionDO(group.getId(), id)) .collect(Collectors.toList()); groupPermissionMapper.insertBatch(relations); } return true; }  @Override IPage<UserDO> getUserPageByGroupId(Long groupId, Long count, Long page); @Override boolean changeUserPassword(Long id, ResetPasswordDTO dto); @Transactional @Override boolean deleteUser(Long id); @Override boolean updateUserInfo(Long id, UpdateUserInfoDTO validator); @Override IPage<GroupDO> getGroupPage(Long page, Long count); @Override GroupPermissionsBO getGroup(Long id); @Transactional @Override boolean createGroup(NewGroupDTO dto); @Override boolean updateGroup(Long id, UpdateGroupDTO dto); @Override boolean deleteGroup(Long id); @Override boolean dispatchPermission(DispatchPermissionDTO dto); @Override boolean dispatchPermissions(DispatchPermissionsDTO dto); @Override boolean removePermissions(RemovePermissionsDTO dto); @Override List<GroupDO> getAllGroups(); @Override List<PermissionDO> getAllPermissions(); @Override Map<String, List<PermissionDO>> getAllStructualPermissions(); }
AdminServiceImpl implements AdminService { @Transactional @Override public boolean createGroup(NewGroupDTO dto) { throwGroupNameExist(dto.getName()); GroupDO group = GroupDO.builder().name(dto.getName()).info(dto.getInfo()).build(); groupService.save(group); if (dto.getPermissionIds() != null && !dto.getPermissionIds().isEmpty()) { List<GroupPermissionDO> relations = dto.getPermissionIds().stream() .map(id -> new GroupPermissionDO(group.getId(), id)) .collect(Collectors.toList()); groupPermissionMapper.insertBatch(relations); } return true; }  @Override IPage<UserDO> getUserPageByGroupId(Long groupId, Long count, Long page); @Override boolean changeUserPassword(Long id, ResetPasswordDTO dto); @Transactional @Override boolean deleteUser(Long id); @Override boolean updateUserInfo(Long id, UpdateUserInfoDTO validator); @Override IPage<GroupDO> getGroupPage(Long page, Long count); @Override GroupPermissionsBO getGroup(Long id); @Transactional @Override boolean createGroup(NewGroupDTO dto); @Override boolean updateGroup(Long id, UpdateGroupDTO dto); @Override boolean deleteGroup(Long id); @Override boolean dispatchPermission(DispatchPermissionDTO dto); @Override boolean dispatchPermissions(DispatchPermissionsDTO dto); @Override boolean removePermissions(RemovePermissionsDTO dto); @Override List<GroupDO> getAllGroups(); @Override List<PermissionDO> getAllPermissions(); @Override Map<String, List<PermissionDO>> getAllStructualPermissions();  }