集合中不存在流口水

drools not exists in collection

如果集合没有特定对象,我需要触发规则。

AuditAssignment 可用作问题事实。

AuditAssignment 有一个 属性 "requiredSkill"

审计分配 属性 "auditor"

Auditor 对象有一个 "qualifications" 的列表,它是 "requiredSkill "

的集合

现在,我需要检查 auditassignment 对象中审计员的资格是否具有所需的技能

下面是我试过但不起作用的示例规则。

rule "checkIfAuditSkillIsMatching"
    when
        $auditAssignment : AuditAssignment( $neededSkill : requiredSkill.getSkillCode())

        $auditor : Auditor( $auditorSkills : qualifications)
        not exists ( Skill ( skillCode == $neededSkill ) from $auditorSkills  )  

    then
        System.out.println( " **** " + $neededSkill);
        scoreHolder.addHardConstraintMatch(kcontext, -1 );
end

下面这个我也试过了

rule "checkIfAuditSkillIsMatching"
    when

        $validAuditorCount : Number ( intValue < 1  ) from accumulate (
            $auditor : Auditor( $auditorSkills: qualifications )
            and   exists AuditAssignment( auditor == $auditor , 
                    $auditorSkills.contains(requiredSkill) )   ,
            count($auditor)

        ) 

    then
        scoreHolder.addHardConstraintMatch(kcontext, -1 );
end

这里建议使用Collection的一个属性方法来获取你需要的逻辑值

rule "checkIfAuditSkillIsMatching"
when
    $auditAssignment: AuditAssignment( $neededSkill: requiredSkill.getSkillCode() )
    $auditor: Auditor( $auditorSkills: qualifications,
                       ! $auditorSkills.contains( $neededSkill ) )  
then
    //...no suitably qualified auditor
end

以下配置有效

rule "checkIfAuditSkillIsMatching"
    when
        $auditAssignment : AuditAssignment( $neededSkill : requiredSkill ,
                    $assignedAuditor : auditor )

        $auditor : Auditor( this == $assignedAuditor , !qualifications.contains($neededSkill) ) 

    then
        scoreHolder.addHardConstraintMatch(kcontext, -1 );
end