[英]Drools collect list from object property
I have a student, who have list of courses. 我有一个学生,有课程清单。 Also I have a lectures and I need to check that student courses list and list of courses of lectures that he visits are same
我也有一个讲座,我需要检查学生课程列表和他访问的讲座课程列表是否相同
I added rule for case, when student visits lecture, that he doesn't have in courses list: 我添加了案例规则,当学生参观讲座时,他没有在课程列表中:
when
$student:Student ($courses:courses)
LectureAssignment(student == $student, course not memberOf $courses)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
But I also need to check, that student visits all lecture, that he have in courses list 但我还需要检查学生是否访问了课程列表中的所有讲座
$student:Student ($courses:courses)
$rightCourses: collect (LectureAssignment(student == $student)) // and get courses list
here I get lectures, that assigned to current student , all lectures have property course and I need to collect them into list $rightCourses and after this compare $courses and $rightCourses (in this case I think I don't need first rule) 在这里,我得到了分配给当前学生的讲座,所有讲座都有财产课程,我需要将它们收集到列表$ rightCourses中,然后将$ courses和$ rightCourses进行比较(在这种情况下,我认为我不需要第一条规则)
You could use forall operator. 您可以使用forall运算符。 See documentation here [1].
请参阅此处的文档[1]。 If that doesn't work for you, you could use accumulate [2], checking that the lecture count a student has assigned is correct, with a combination of your first rule that checks that a student has not assigned a course that is not part of the courses list.
如果这对您不起作用,则可以使用累加[2],检查学生分配的讲座数是否正确,并结合检查您的学生未分配不属于某门课程的第一条规则课程列表。
[1] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_forall [1] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_forall
[2] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_accumulate [2] https://docs.jboss.org/drools/release/7.16.0.Final/drools-docs/html_single/index.html#_conditional_element_accumulate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.