PropertyFilterBuilder使用

使grants中的每个条件之间是“或”的关系

正确写法: 

public List<Long> getAllEmployeeIds(List<GrantPermission> grants) {
        List<PropertyFilterBuilder> builderList = new ArrayList<>();
        for(GrantPermission g : grants){
            switch (g.getSecurityType()){
                case employee:
                    builderList.add(new PropertyFilterBuilder().equal("id",Long.parseLong(g.getValue())));
                case department:
                    Department department = departmentDao.findById(Long.parseLong(g.getValue())).orElse(null);
                    if(department == null)
                        continue;
                    builderList.add(new PropertyFilterBuilder().startsWith("employeePositions.department.path",department.getPath()));
                case employeeGroup:
                    builderList.add(new PropertyFilterBuilder().equal("groups.id",g.getValue()));
                case role:
                    builderList.add(new PropertyFilterBuilder().equal("user.roles.id",g.getValue()));
                default:
                    log.error("未找到权限对应的类型");
            }
        }
        List<PropertyFilter> build = PropertyFilter.builder().or(builderList.stream().map(e -> e.build()).flatMap(Collection::stream).collect(Collectors.toList()))
                .and(new PropertyFilterBuilder().in("organizationEmployees.status.code", "fullparty","probationary","work")).build();
        return employeeService.findEmployeeInUse(build);
}

运行结果:

 错误写法:

public List<Long> getAllEmployeeIds(List<GrantPermission> grants) {
PropertyFilterBuilder builder = new PropertyFilterBuilder();
        for(GrantPermission g : grants){
            switch (g.getSecurityType()){
                case employee:
                    builder.or(new PropertyFilterBuilder().equal("id",Long.parseLong(g.getValue())));
                case department:
                    Department department = departmentDao.findById(Long.parseLong(g.getValue())).orElse(null);
                    if(department == null)
                        continue;
                    builder.or(new PropertyFilterBuilder().startsWith("employeePositions.department.path",department.getPath()));
                case employeeGroup:
                    builder.or(new PropertyFilterBuilder().equal("groups.id",g.getValue()));
                case role:
                    builder.or(new PropertyFilterBuilder().equal("user.roles.id",g.getValue()));
                default:
                    log.error("未找到权限对应的类型");
            }
        }
        PropertyFilterBuilder builder2 = new PropertyFilterBuilder();
        builder2.in("organizationEmployees.status.code", "fullparty","probationary","work");
        return employeeService.findEmployeeInUse(builder2.and(builder).build());
}

 运行结果:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值