Exemplo n.º 1
0
 private Specification<Node> spec(
     final Integer parentId,
     final String treeNumber,
     final Integer userId,
     final boolean allNode,
     Map<String, String[]> params) {
   Collection<SearchFilter> filters = SearchFilter.parse(params).values();
   final Specification<Node> fs = SearchFilter.spec(filters, Node.class);
   Specification<Node> sp =
       new Specification<Node>() {
         public Predicate toPredicate(
             Root<Node> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
           Predicate pred = fs.toPredicate(root, query, cb);
           if (parentId != null) {
             pred = cb.and(pred, cb.equal(root.get("parent").<Integer>get("id"), parentId));
           }
           if (StringUtils.isNotBlank(treeNumber)) {
             Path<String> tnPath = root.<String>get("treeNumber");
             pred = cb.and(pred, cb.like(tnPath, treeNumber + "%"));
           }
           if (!allNode) {
             Path<Integer> userPath =
                 root.join("nodeRoleSites").join("role").join("users").<Integer>get("id");
             pred = cb.and(pred, cb.equal(userPath, userId));
             query.distinct(true);
           }
           return pred;
         }
       };
   return sp;
 }
  private Specification<Info> spec(
      final Integer siteId,
      final Integer mainNodeId,
      final Integer nodeId,
      final String treeNumber,
      final Integer userId,
      final boolean allInfoPerm,
      final int infoPermType,
      final String status,
      Map<String, String[]> params) {
    Collection<SearchFilter> filters = SearchFilter.parse(params).values();
    final Specification<Info> fsp = SearchFilter.spec(filters, Info.class);
    Specification<Info> sp =
        new Specification<Info>() {
          public Predicate toPredicate(
              Root<Info> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            boolean distinct = false;
            Predicate pred = fsp.toPredicate(root, query, cb);
            if (siteId != null) {
              pred = cb.and(pred, cb.equal(root.get("site").get("id"), siteId));
            }
            if (mainNodeId != null) {
              pred = cb.and(pred, cb.equal(root.get("node").get("id"), mainNodeId));
            } else if (nodeId != null) {
              Path<Integer> nodesPath = root.join("infoNodes").get("node").get("id");
              pred = cb.and(pred, cb.equal(nodesPath, nodeId));
              distinct = true;
            } else if (StringUtils.isNotBlank(treeNumber)) {
              pred =
                  cb.and(
                      pred, cb.like(root.get("node").<String>get("treeNumber"), treeNumber + "%"));
            }
            if (!allInfoPerm) {
              Join<Node, NodeRole> nodeRoleJoin = root.join("node").join("nodeRoles");
              Path<Integer> userPath =
                  nodeRoleJoin.join("role").join("userRoles").get("user").<Integer>get("id");
              pred = cb.and(pred, cb.equal(userPath, userId));
              pred = cb.and(pred, cb.equal(nodeRoleJoin.get("infoPerm"), true));
              query.distinct(true);
            }

            if (infoPermType == Role.INFO_PERM_SELF) {
              pred = cb.and(pred, cb.equal(root.get("creator").<Integer>get("id"), userId));
            } else if (infoPermType == Role.INFO_PERM_ORG) {
              pred =
                  cb.and(
                      pred,
                      cb.equal(
                          root.join("org").join("userOrgs").get("user").<Integer>get("id"),
                          userId));
              distinct = true;
            }
            if (StringUtils.isNotBlank(status)) {
              if (status.length() == 1) {
                pred = cb.and(pred, cb.equal(root.get("status"), status));
              } else if (status.equals("pending") || status.equals("notpassed")) {
                pred = cb.and(pred, cb.equal(root.get("status"), Info.AUDITING));
                boolean rejection = "notpassed".equals(status);
                Subquery<Integer> sq = query.subquery(Integer.class);
                Root<WorkflowProcess> root2 = sq.from(WorkflowProcess.class);
                sq.select(root2.<Integer>get("dataId"));
                sq.where(
                    cb.equal(root2.get("rejection"), rejection),
                    cb.equal(root2.get("dataType"), 1),
                    cb.equal(root2.get("end"), false),
                    cb.equal(
                        root2
                            .join("step")
                            .join("stepRoles")
                            .join("role")
                            .join("userRoles")
                            .get("user")
                            .get("id"),
                        userId));
                pred = cb.and(pred, cb.in(root.<Integer>get("id")).value(sq));
              }
            } else {
              // 除了删除状态
              pred = cb.and(pred, cb.notEqual(root.get("status"), Info.DELETED));
            }
            if (distinct) {
              query.distinct(true);
            }
            return pred;
          }
        };
    return sp;
  }
Exemplo n.º 3
0
 private Specification<Member> spec(Map<String, String[]> params) {
   Collection<SearchFilter> filters = SearchFilter.parse(params).values();
   Specification<Member> sp = SearchFilter.spec(filters, Member.class);
   return sp;
 }