我正在尝试修改员工调度快速入门中的约束以支持参数,但它似乎不起作用。
我将代码修改为这样,不知道为什么它不起作用。
Constraint atLeast10HoursBetweenTwoShifts(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Shift.class)
.join(Shift.class, equal(Shift::getEmployee), lessThanOrEqual(Shift::getEnd, Shift::getStart))
.join(ConstraintParameters.class)
.filter((firstShift,
secondShift, constraintParameters) -> {
return Duration.between(firstShift.getEnd(), secondShift.getStart()).toHours() < constraintParameters.minRestHours();
})
.penalize(HardSoftBigDecimalScore.ONE_HARD,
(firstShift, secondShift, constraintParameters) -> {
int breakLength = (int) Duration.between(firstShift.getEnd(), secondShift.getStart()).toMinutes();
return (constraintParameters.minRestHours() * 60) - breakLength;
})
.asConstraint("At least 10 hours between 2 shifts");
}
可能没有已知可连接的 ConstraintParameters 实例。
检查您的解决方案类是否具有用 @ProblemFactProperty 注释的 ConstraintParameters 字段。