对于规则,我需要将基数增加到 5。我不确定如何添加
.map
函数和下游数据。另外,在下游之后如何提取数据。
请参阅我正在尝试开发的以下代码。我正在尝试填写代码中的注释部分 .map
和 .penalizeConfigurable
部分,我正在尝试提取它。
return constraintFactory.forEach(RuleSetting.class)
.filter(ruleSetting -> ruleSetting.getRuleName().equals("E015")&& ruleSetting.getIsActive() == true)
.join(Shift.class)
.join(ForeignerType.class)
.filter((ruleSetting, shift, foreignerType) -> shift.getEmployee().getForeignerType() != null
&& foreignerType.getForeignerType().equals(shift.getEmployee().getForeignerType())
&& shift.getWeekNo() != null
)
.groupBy((ruleSetting, shift, foreignerType)->ruleSetting,
(ruleSetting, shift, foreignerType)->shift.getEmployee(),
(ruleSetting, shift, foreignerType)->shift.getWeekNo(),
ConstraintCollectors.sumLong((ruleSetting, shift, foreignerType)->shift.getWorkMinutes()))
.filter((ruleSetting, employee, weekNo, totalDuration) -> totalDuration > employee.getContracts().getMaxMinutesPerWeek())
.map(//How to fill the map function??
)
.join(ForeignerType.class)
.penalizeConfigurable((first, foreigner)->{
//How to extract the data here.
Double result = Math.abs(((double)totalDuration / (double) employee.getContracts().getMaxMinutesPerWeek()));
result = result * Math.abs(ruleSetting.getWeight());
return result.intValue();
})
.indictWith((ruleSetting, employee, weekNo, totalDuration) ->{
EmployeeScoreKeyItems res = new EmployeeScoreKeyItems(EmployeeScoreKeyItems.KeyType.BY_WEEK,
ruleSetting.getRuleName(),
employee.getEmployeeId(),
null, null, weekNo, null);
return List.of(res);
})
.asConstraint("E015")
map(...)
允许您在基数之间任意更改,最大基数为 4。如果您需要超过 4,有一个技巧 - 您可以将多个参数打包到另一种类型中。
考虑这样的 Java 记录:
record QuadTuple<A, B, C, D>(A a, B b, C c, D d) {
}
我们可以将
Quad
流打包到 Uni
流,如下所示:
.map((a, b, c, d) -> new QuadTuple(a, b, c, d))
或者,使用方法参考:
.map(QuadTuple::new)
例如,在后续过滤器中,您可以执行以下操作:
.filter(quadTuple -> quadTuple.a() > 0)