@Test public void structuringPermissions() { Long id = mockData(); List<PermissionDO> permissions = permissionService.getPermissionByGroupIds(Collections.singletonList(id)); List<Map<String, List<Map<String, String>>>> structuringPermissions = permissionService.structuringPermissions(permissions); assertTrue(structuringPermissions.size() > 0); log.info("structuringPermissions: {}", structuringPermissions); boolean anyMatch = structuringPermissions.stream().anyMatch(it -> it.containsKey("炉石传说")); assertTrue(anyMatch); }
@Override public List<Map<String, List<Map<String, String>>>> structuringPermissions(List<PermissionDO> permissions) { Map<String, List<Map<String, String>>> tmp = new HashMap(); permissions.forEach(permission -> { if (!tmp.containsKey(permission.getModule())) { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); List<Map<String, String>> mini = new ArrayList(); mini.add(tiny); tmp.put(permission.getModule(), mini); } else { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); tmp.get(permission.getModule()).add(tiny); } permission.getName(); }); List<Map<String, List<Map<String, String>>>> structualPermissions = new ArrayList(); tmp.forEach((k, v) -> { Map<String, List<Map<String, String>>> ttmp = new HashMap(); ttmp.put(k, v); structualPermissions.add(ttmp); }); return structualPermissions; }
PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionDO> implements PermissionService { @Override public List<Map<String, List<Map<String, String>>>> structuringPermissions(List<PermissionDO> permissions) { Map<String, List<Map<String, String>>> tmp = new HashMap(); permissions.forEach(permission -> { if (!tmp.containsKey(permission.getModule())) { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); List<Map<String, String>> mini = new ArrayList(); mini.add(tiny); tmp.put(permission.getModule(), mini); } else { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); tmp.get(permission.getModule()).add(tiny); } permission.getName(); }); List<Map<String, List<Map<String, String>>>> structualPermissions = new ArrayList(); tmp.forEach((k, v) -> { Map<String, List<Map<String, String>>> ttmp = new HashMap(); ttmp.put(k, v); structualPermissions.add(ttmp); }); return structualPermissions; } }
PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionDO> implements PermissionService { @Override public List<Map<String, List<Map<String, String>>>> structuringPermissions(List<PermissionDO> permissions) { Map<String, List<Map<String, String>>> tmp = new HashMap(); permissions.forEach(permission -> { if (!tmp.containsKey(permission.getModule())) { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); List<Map<String, String>> mini = new ArrayList(); mini.add(tiny); tmp.put(permission.getModule(), mini); } else { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); tmp.get(permission.getModule()).add(tiny); } permission.getName(); }); List<Map<String, List<Map<String, String>>>> structualPermissions = new ArrayList(); tmp.forEach((k, v) -> { Map<String, List<Map<String, String>>> ttmp = new HashMap(); ttmp.put(k, v); structualPermissions.add(ttmp); }); return structualPermissions; }  }
PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionDO> implements PermissionService { @Override public List<Map<String, List<Map<String, String>>>> structuringPermissions(List<PermissionDO> permissions) { Map<String, List<Map<String, String>>> tmp = new HashMap(); permissions.forEach(permission -> { if (!tmp.containsKey(permission.getModule())) { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); List<Map<String, String>> mini = new ArrayList(); mini.add(tiny); tmp.put(permission.getModule(), mini); } else { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); tmp.get(permission.getModule()).add(tiny); } permission.getName(); }); List<Map<String, List<Map<String, String>>>> structualPermissions = new ArrayList(); tmp.forEach((k, v) -> { Map<String, List<Map<String, String>>> ttmp = new HashMap(); ttmp.put(k, v); structualPermissions.add(ttmp); }); return structualPermissions; }  @Override List<PermissionDO> getPermissionByGroupId(Long groupId); @Override List<PermissionDO> getPermissionByGroupIds(List<Long> groupIds); @Override Map<Long, List<PermissionDO>> getPermissionMapByGroupIds(List<Long> groupIds); @Override List<Map<String, List<Map<String, String>>>> structuringPermissions(List<PermissionDO> permissions); @Override Map<String, List<String>> structuringPermissionsSimply(List<PermissionDO> permissions); }
PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionDO> implements PermissionService { @Override public List<Map<String, List<Map<String, String>>>> structuringPermissions(List<PermissionDO> permissions) { Map<String, List<Map<String, String>>> tmp = new HashMap(); permissions.forEach(permission -> { if (!tmp.containsKey(permission.getModule())) { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); List<Map<String, String>> mini = new ArrayList(); mini.add(tiny); tmp.put(permission.getModule(), mini); } else { Map<String, String> tiny = new HashMap(); tiny.put("module", permission.getModule()); tiny.put("permission", permission.getName()); tmp.get(permission.getModule()).add(tiny); } permission.getName(); }); List<Map<String, List<Map<String, String>>>> structualPermissions = new ArrayList(); tmp.forEach((k, v) -> { Map<String, List<Map<String, String>>> ttmp = new HashMap(); ttmp.put(k, v); structualPermissions.add(ttmp); }); return structualPermissions; }  @Override List<PermissionDO> getPermissionByGroupId(Long groupId); @Override List<PermissionDO> getPermissionByGroupIds(List<Long> groupIds); @Override Map<Long, List<PermissionDO>> getPermissionMapByGroupIds(List<Long> groupIds); @Override List<Map<String, List<Map<String, String>>>> structuringPermissions(List<PermissionDO> permissions); @Override Map<String, List<String>> structuringPermissionsSimply(List<PermissionDO> permissions);  }