List<DataPermissionSchemaEo> dataPermissionSchemaEoList = comDataComponent.getDataPermissionSchemaList(); List<SchemaRowRuleEo> schemaRowRuleList = comDataComponent.getSchemaRowRuleList(); List<SchemaColumnRuleEo> schemaColumnRuleList = comDataComponent.getSchemaColumnRuleList(); //设置行权限 根据用户id和用户组织去获取 List<SchemaRowRule> userRowRuleList = schemaRowRuleList.stream() .filter(schemaRowRuleEo -> { List<String> userList = JSONObject.parseArray(schemaRowRuleEo.getRowPermissionUserList(), String.class); List<String> orgList = JSONObject.parseArray(schemaRowRuleEo.getRowPermissionOrgList(), String.class); return userList.contains(userUid) || orgList.contains(orgCode) || userList.contains(WILDCARD) || orgList.contains(WILDCARD); }) .map(schemaRowRuleEo -> { SchemaRowRule schemaRowRule = new SchemaRowRule(); BeanUtils.copyProperties(schemaRowRuleEo, schemaRowRule); return schemaRowRule; }) .collect(Collectors.toList());List<SchemaColumnRule> userColumnRuleList = schemaColumnRuleList.stream() .filter(rule -> { List<String> userList = Optional.ofNullable(rule.getColumnPermissionUserList()) .map(userListStr -> JSONObject.parseArray(userListStr, String.class)) .orElse(Collections.emptyList()); List<String> orgList = Optional.ofNullable(rule.getColumnPermissionOrgList()) .map(orgListStr -> JSONObject.parseArray(orgListStr, String.class)) .orElse(Collections.emptyList()); return userList.contains(userUid) || orgList.contains(orgCode) || userList.contains(WILDCARD) || orgList.contains(WILDCARD); }) .map(rule -> { SchemaColumnRule columnRule = new SchemaColumnRule(); BeanUtils.copyProperties(rule, columnRule); return columnRule; }) .collect(Collectors.toList()); List<DataPermissionSchema> dataPermissionSchemaList = dataPermissionSchemaEoList.stream().map(dataPermissionSchemaEo -> { List<SchemaRowRule> schemaRowRules = userRowRuleList.stream() .filter(schemaRule -> dataPermissionSchemaEo.getDatabaseCode().equals(schemaRule.getDatabaseCode()) && dataPermissionSchemaEo.getSchemaCode().equals(schemaRule.getSchemaCode())) .collect(Collectors.toList()); List<SchemaColumnRule> schemaColumnRules = userColumnRuleList.stream() .filter(schemaRule -> dataPermissionSchemaEo.getDatabaseCode().equals(schemaRule.getDatabaseCode()) && dataPermissionSchemaEo.getSchemaCode().equals(schemaRule.getSchemaCode())) .collect(Collectors.toList()); if(!schemaRowRules.isEmpty() || !schemaColumnRules.isEmpty()) { DataPermissionSchema dataPermissionSchema = new DataPermissionSchema(); dataPermissionSchema.setDatabaseCode(dataPermissionSchemaEo.getDatabaseCode()); dataPermissionSchema.setSchemaCode(dataPermissionSchemaEo.getSchemaCode()); dataPermissionSchema.setSchemaRowRuleList(schemaRowRules); dataPermissionSchema.setSchemaColumnRuleList(schemaColumnRules); return dataPermissionSchema; } return null; }).filter(Objects::nonNull).collect(Collectors.toList());把这段代码改造成每个用户拥有的行权限和列权限
时间: 2024-02-01 11:16:37 浏览: 69
基于javascript实现listbox左右移动
可以将该代码封装成一个方法,接收用户ID和组织代码作为参数,返回该用户拥有的行权限和列权限,代码如下:
```
public List<DataPermissionSchema> getUserDataPermissionSchema(String userUid, String orgCode) {
List<DataPermissionSchemaEo> dataPermissionSchemaEoList = comDataComponent.getDataPermissionSchemaList();
List<SchemaRowRuleEo> schemaRowRuleList = comDataComponent.getSchemaRowRuleList();
List<SchemaColumnRuleEo> schemaColumnRuleList = comDataComponent.getSchemaColumnRuleList();
// 获取用户行权限
List<SchemaRowRule> userRowRuleList = schemaRowRuleList.stream()
.filter(schemaRowRuleEo -> {
List<String> userList = JSONObject.parseArray(schemaRowRuleEo.getRowPermissionUserList(), String.class);
List<String> orgList = JSONObject.parseArray(schemaRowRuleEo.getRowPermissionOrgList(), String.class);
return userList.contains(userUid) || orgList.contains(orgCode) || userList.contains(WILDCARD) || orgList.contains(WILDCARD);
})
.map(schemaRowRuleEo -> {
SchemaRowRule schemaRowRule = new SchemaRowRule();
BeanUtils.copyProperties(schemaRowRuleEo, schemaRowRule);
return schemaRowRule;
})
.collect(Collectors.toList());
// 获取用户列权限
List<SchemaColumnRule> userColumnRuleList = schemaColumnRuleList.stream()
.filter(rule -> {
List<String> userList = Optional.ofNullable(rule.getColumnPermissionUserList())
.map(userListStr -> JSONObject.parseArray(userListStr, String.class))
.orElse(Collections.emptyList());
List<String> orgList = Optional.ofNullable(rule.getColumnPermissionOrgList())
.map(orgListStr -> JSONObject.parseArray(orgListStr, String.class))
.orElse(Collections.emptyList());
return userList.contains(userUid) || orgList.contains(orgCode) || userList.contains(WILDCARD) || orgList.contains(WILDCARD);
})
.map(rule -> {
SchemaColumnRule columnRule = new SchemaColumnRule();
BeanUtils.copyProperties(rule, columnRule);
return columnRule;
})
.collect(Collectors.toList());
// 获取用户权限所在的数据权限模板
List<DataPermissionSchema> dataPermissionSchemaList = dataPermissionSchemaEoList.stream().map(dataPermissionSchemaEo -> {
List<SchemaRowRule> schemaRowRules = userRowRuleList.stream()
.filter(schemaRule -> dataPermissionSchemaEo.getDatabaseCode().equals(schemaRule.getDatabaseCode())
&& dataPermissionSchemaEo.getSchemaCode().equals(schemaRule.getSchemaCode()))
.collect(Collectors.toList());
List<SchemaColumnRule> schemaColumnRules = userColumnRuleList.stream()
.filter(schemaRule -> dataPermissionSchemaEo.getDatabaseCode().equals(schemaRule.getDatabaseCode())
&& dataPermissionSchemaEo.getSchemaCode().equals(schemaRule.getSchemaCode()))
.collect(Collectors.toList());
if(!schemaRowRules.isEmpty() || !schemaColumnRules.isEmpty()) {
DataPermissionSchema dataPermissionSchema = new DataPermissionSchema();
dataPermissionSchema.setDatabaseCode(dataPermissionSchemaEo.getDatabaseCode());
dataPermissionSchema.setSchemaCode(dataPermissionSchemaEo.getSchemaCode());
dataPermissionSchema.setSchemaRowRuleList(schemaRowRules);
dataPermissionSchema.setSchemaColumnRuleList(schemaColumnRules);
return dataPermissionSchema;
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
return dataPermissionSchemaList;
}
```
阅读全文