JPA构造条件and,or组合查询

这是我要实现的sql


SELECT
    TaskId,
    ProcId,
    ArrivalDate,
    HandlerUserId,
    Active 
FROM
    SYSBPMIProc
WHERE
    HandlerUserId = ?
    AND Finished = ? 
    AND ( NodeType BETWEEN 0 AND 1 ) 
    AND ( IsRecede = 0 ) 
    OR ( CompanyId = ? AND Finished = 0 AND IsShare = 1 ) 
    AND Active = 1

这是构造器

Specification<BpmIProc> specification2 = new Specification<BpmIProc>() {
            @Override
            public Predicate toPredicate(Root<BpmIProc> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                Predicate handlerUserId = criteriaBuilder.equal(root.get("handlerUserId"), 489);
                Predicate and1 = criteriaBuilder.equal(root.get("finished"), 0);

                Predicate or1 = criteriaBuilder.equal(root.get("nodeType"),0);
                Predicate or2 = criteriaBuilder.equal(root.get("nodeType"),1);
                Predicate and2 = SpeUtil.getOrByPreList(criteriaBuilder,or1, or2);

                Predicate and3 = criteriaBuilder.equal(root.get("isRecede"), 0);

                Predicate and4 = criteriaBuilder.equal(root.get("companyId"), 28);
                Predicate and5 = criteriaBuilder.equal(root.get("finished"), 0);
                Predicate and6 = criteriaBuilder.equal(root.get("isShare"), 1);
                Predicate or4 = SpeUtil.getAndCommon(criteriaBuilder, and4, and5, and6);

                Predicate active = criteriaBuilder.equal(root.get("active"), 1);
                List<Predicate> predicates1 = new ArrayList<>();
                Predicate andCommon = SpeUtil.getAndCommon(criteriaBuilder, handlerUserId, and1, and2, and3 , active);
                predicates1.add(SpeUtil.getOrByPreList(criteriaBuilder, andCommon, or4));
                return criteriaBuilder.and(predicates1.toArray(new Predicate[predicates1.size()]));
            }
        };
        List<BpmIProc> bpms = bpmIProcRepository.findAll(specification2);

这是控制台打印的sql

Hibernate: 
    select
        bpmiproc0_.ProcId as procid1_363_,
        bpmiproc0_.Active as active2_363_,
        bpmiproc0_.CreateTime as createti3_363_,
        bpmiproc0_.Creater as creater4_363_,
        bpmiproc0_.UpdateTime as updateti5_363_,
        bpmiproc0_.Updater as updater6_363_,
        bpmiproc0_.CompanyId as companyi7_363_,
        bpmiproc0_.PStandardTime as pstandar8_363_,
        bpmiproc0_.ActionLinkId as actionli9_363_,
        bpmiproc0_.ActionLinkName as actionl10_363_,
        bpmiproc0_.AgentUserId as agentus11_363_,
        bpmiproc0_.AgentUserName as agentus12_363_,
        bpmiproc0_.ArrivalDate as arrival13_363_,
        bpmiproc0_.CcRead as ccread14_363_,
        bpmiproc0_.CcReadTime as ccreadt15_363_,
        bpmiproc0_.Comment as comment16_363_,
        bpmiproc0_.FinishDate as finishd17_363_,
        bpmiproc0_.Finished as finishe18_363_,
        bpmiproc0_.FlowCatId as flowcat19_363_,
        bpmiproc0_.FlowCatName as flowcat20_363_,
        bpmiproc0_.FlowCode as flowcod21_363_,
        bpmiproc0_.FlowGuid as flowgui22_363_,
        bpmiproc0_.FlowName as flownam23_363_,
        bpmiproc0_.FormFile as formfil24_363_,
        bpmiproc0_.HandlerUserId as handler25_363_,
        bpmiproc0_.HandlerUserName as handler26_363_,
        bpmiproc0_.IsAsk as isask27_363_,
        bpmiproc0_.IsRecede as isreced28_363_,
        bpmiproc0_.IsShare as isshare29_363_,
        bpmiproc0_.NextHandlerUserIds as nexthan30_363_,
        bpmiproc0_.NodeId as nodeid31_363_,
        bpmiproc0_.NodeName as nodenam32_363_,
        bpmiproc0_.NodeType as nodetyp33_363_,
        bpmiproc0_.OpenDate as opendat34_363_,
        bpmiproc0_.OperatorUserId as operato35_363_,
        bpmiproc0_.OperatorUserName as operato36_363_,
        bpmiproc0_.OwnerUserId as ownerus37_363_,
        bpmiproc0_.OwnerUserName as ownerus38_363_,
        bpmiproc0_.RecedeFromProcId as recedef39_363_,
        bpmiproc0_.StandardTime as standar40_363_,
        bpmiproc0_.SubFlowCount as subflow41_363_,
        bpmiproc0_.SysComment as syscomm42_363_,
        bpmiproc0_.TaskId as taskid43_363_ 
    from
        SysBpmIProc bpmiproc0_ 
    where
        bpmiproc0_.HandlerUserId=489 
        and bpmiproc0_.Finished=0 
        and (
            bpmiproc0_.NodeType=0 
            or bpmiproc0_.NodeType=1
        ) 
        and bpmiproc0_.IsRecede=0 
        and bpmiproc0_.Active=1 
        or bpmiproc0_.CompanyId=28 
        and bpmiproc0_.Finished=0 
        and bpmiproc0_.IsShare=1

就是后面那个or出问题了,OR ( CompanyId = ? AND Finished = 0 AND IsShare = 1 ) ,没有加上括号
麻烦指点一下