当前位置 博文首页 > 文章内容

    Specification使用in

    作者: 栏目:未分类 时间:2020-09-21 11:00:00

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    //是否包含下级授权点 1 包含 2 不包含
            List<AuthorizationPoint> authList = null;
            List<Long> pointIdList = Lists.newArrayList();
            if (isContain != null) {
                if (1 == isContain) {
                    if(authStr != null && !"".equals(authStr.trim())){
                        authList = this.authorizationPointService.getAuthPointChildrenListByAuthName(authStr);
                    }
                }
            }
            if(!CollectionUtils.isEmpty(authList)){
                for (AuthorizationPoint point : authList) {
                    pointIdList.add(point.getId());
                }
            }
    
            List<AuthorizationPoint> finalAuthList = authList;
            Specification<BaseUser> specification = new Specification<BaseUser>() {
                @Override
                public Predicate toPredicate(Root<BaseUser> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
    
                    List<Predicate> predicateList = Lists.newArrayList();
    
                    //isDelete
                    Predicate isDeletePredicate = criteriaBuilder.equal(root.get("isDelete"), Constant.NOT_DELETE);
                    predicateList.add(isDeletePredicate);
    
                    //非管理员
                    Predicate rolePredicate = criteriaBuilder.isNull(root.join("role", JoinType.LEFT).get("id"));
                    predicateList.add(rolePredicate);
    
                    // 非禁用用户
                    Predicate accountPredicate = criteriaBuilder.equal(root.get("account").get("status"), status == null ? "A" : status);
                    predicateList.add(accountPredicate);
    
    
                    //authCategoryId
                    if (authCategoryId != null) {
                        Predicate predicate = criteriaBuilder.equal(root.join("authorizationPoint", JoinType.LEFT).join("authCategory", JoinType.LEFT).get("id"), authCategoryId);
                        predicateList.add(predicate);
                    }
    
                    //authId
                    if (authId != null) {
                        Predicate predicate = criteriaBuilder.equal(root.join("authorizationPoint", JoinType.LEFT).get("id"), authId);
                        predicateList.add(predicate);
                    }
    
                    //searchText
                    if (searchText != null && !searchText.trim().isEmpty()) {
                        Predicate predicate = criteriaBuilder.like(root.get("name"), "%" + searchText.trim() + "%");
                        predicateList.add(predicate);
                    }
    
                    //创建用户的开始时间和结束时间
                    /*if (startDate != null) {
                        Predicate predicate = criteriaBuilder.greaterThanOrEqualTo(root.get("createTime"), startDate);
                        predicateList.add(predicate);
                    }
    
                    if (endDate != null) {
                        Predicate predicate = criteriaBuilder.lessThanOrEqualTo(root.get("createTime"), endDate);
                        predicateList.add(predicate);
                    }*/
    
                    // 授权点名称
                    if (authStr != null && !authStr.isEmpty()) {
                        Predicate predicate = criteriaBuilder.like(root.join("authorizationPoint", JoinType.LEFT).get("name"), "%" + authStr + "%");
                        predicateList.add(predicate);
    
                        //授权点点击子级授权点集合
                        if(!CollectionUtils.isEmpty(pointIdList)){
                            CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.join("authorizationPoint", JoinType.LEFT).get("id"));
                            Iterator<Long> iterator = pointIdList.iterator();
                            while (iterator.hasNext()){
                                in.value(iterator.next());
                            }
                            predicateList.add(in);
                        }
                    }
    
                    Order createTimeOrder = criteriaBuilder.desc(root.get("createTime"));
    
                    return criteriaQuery.orderBy(createTimeOrder).where(predicateList.toArray(new Predicate[predicateList.size()])).getRestriction();
                }
            };