java - 在 EmployeePanel NurseRoster 中显示假期的建议方法
问题描述
我已经Holiday's component
对NurseRoster Optaplanner
. 我遇到的问题是如何最好地holidays
在EmployeePanel
GUI
. (底部代码元素 TODO)注意我使用了Map Pair
. 所有作品,但想在GUI
. 有什么建议么?
以下是我的代码元素:
//My Data input Method
@Entity(name = "HolidaysData")
public class HolidaysData extends AbstractPersistable{
private int weight;
@ManyToOne
private Employee employee;
private LocalDate startdate;
private LocalDate enddate;
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public LocalDate getStartdate() {
return startdate;
}
public void setStartdate(LocalDate startdate) {
this.startdate = startdate;
}
public LocalDate getEnddate() {
return enddate;
}
public void setEnddate(LocalDate enddate) {
this.enddate = enddate;
}
}
//The emlements I have added to the NurseRoster Method
@ProblemFactCollectionProperty
private List<HolidayRequest> holidayRequestList;
public List<HolidayRequest> getHolidayRequestList() {
return holidayRequestList;
}
public void setHolidayRequestList(List<HolidayRequest> holidayRequestList) {
this.holidayRequestList = holidayRequestList;
}
//The elements I have added to the Employee Method
@OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
@MapKey(name="id")
private Map<Pair<ShiftDate,ShiftDate>, HolidayRequest> holidayRequestMap;
public void setHolidayRequestMap(
Map<Pair<ShiftDate, ShiftDate>, HolidayRequest> holidayRequestMap) {
this.holidayRequestMap = holidayRequestMap;
}
//The method used in my DataLogic to read from the database
private void readHolidayRequestList(NurseRoster nurseRoster) {
List<HolidayRequest> holidayRequestList;
List<HolidaysData> holidayElementList = (List<HolidaysData>) rosterService
.listHolidaysData();
holidayRequestList = new ArrayList<>(holidayElementList.size());
for (HolidaysData element : holidayElementList) {
long Id = element.getId();
int weight = element.getWeight();
String empname = element.getEmployee().getName();
Employee employee = employeeMap.get(empname);
LocalDate startdate = element.getStartdate();
LocalDate enddate = element.getEnddate();
ShiftDate firstDate = shiftDateMap.get(startdate);
ShiftDate lastDate = shiftDateMap.get(enddate);
HolidayRequest holidayRequest = new HolidayRequest();
holidayRequest.setId(Id);
holidayRequest.setEmployee(employee);
holidayRequest.setStartshiftDate(firstDate);
holidayRequest.setEndshiftDate(lastDate);
holidayRequest.setWeight(weight);
holidayRequestList.add(holidayRequest);
employee.getHolidayRequestMap().put(Pair.of(firstDate, lastDate),
holidayRequest);
}
nurseRoster.setHolidayRequestList(holidayRequestList);
}
//DRL Rule
// Holiday input
rule "holidayRequest"
when
$holidayRequest : HolidayRequest($employee : employee, $startshiftDate : startshiftDate, $endshiftDate : endshiftDate, $weight : weight)
$assignment : ShiftAssignment(employee == $employee, shiftDate >= $startshiftDate, shiftDate <= $endshiftDate)
then
scoreHolder.addHardConstraintMatch(kcontext, - $weight);
end
//Element I want to ideas on within EmployeePanel
shiftDatePanelMap = new LinkedHashMap<>(shiftDateList.size());
for (ShiftDate shiftDate : shiftDateList) {
// System.out.println(shiftDate);
JPanel shiftDatePanel = new JPanel(new GridLayout(1, 0));
Color backgroundColor = weekendDefinition.isWeekend(shiftDate.getDayOfWeek())
? TangoColorFactory.ALUMINIUM_2 : shiftDatePanel.getBackground();
if (employee != null) {
if (employee.getDayOffRequestMap().containsKey(shiftDate)) {
backgroundColor = TangoColorFactory.ALUMINIUM_5;
}
//TODO Figure this out to show leave / holidays
/*
* else if (employee.getHolidayRequestMap().is) {
*
* backgroundColor = TangoColorFactory.ALUMINIUM_4; }
*/
else if (employee.getDayOnRequestMap().containsKey(shiftDate)) {
backgroundColor = TangoColorFactory.SCARLET_1;
}
}
我想在休假/假期期间请求的所有日期显示背景颜色。
解决方案
我最终删除了 Pair Of 并执行以下小狗代码:
private void readHolidayRequestList(NurseRoster nurseRoster) {
List<LocalDate> allDates = new ArrayList<>();
List<HolidayRequest> holidayRequestList;
long Id = 0L;
List<HolidaysData> holidayElementList = (List<HolidaysData>) rosterService
.listHolidaysData();
holidayRequestList = new ArrayList<>(holidayElementList.size());
for (HolidaysData element : holidayElementList) {
int weight = element.getWeight();
String empname = element.getEmployee().getName();
Employee employee = employeeMap.get(empname);
LocalDate startdate = element.getStartdate();
LocalDate enddate = element.getEnddate();
if (startdate.isAfter(enddate)) {
throw new IllegalStateException(
"start date must be before or equal to end date");
}
while (!startdate.isAfter(enddate)) {
allDates.add(startdate);
startdate = startdate.plusDays(1);
ShiftDate firstDate = shiftDateMap.get(startdate);
HolidayRequest holidayRequest = new HolidayRequest();
Id++;
holidayRequest.setId(Id);
holidayRequest.setEmployee(employee);
holidayRequest.setStartshiftDate(firstDate);
holidayRequest.setWeight(weight);
holidayRequestList.add(holidayRequest);
employee.getHolidayRequestMap().put(firstDate, holidayRequest);
}
}
nurseRoster.setHolidayRequestList(holidayRequestList);
}
// Holiday input
rule "holidayRequest"
when
$holidayRequest : HolidayRequest($employee : employee, $startshiftDate : startshiftDate, $weight : weight)
$assignment : ShiftAssignment(employee == $employee, shiftDate == $startshiftDate)
then
scoreHolder.addHardConstraintMatch(kcontext, - $weight);
end
for (ShiftDate shiftDate : shiftDateList) {
JPanel shiftDatePanel = new JPanel(new GridLayout(1, 0));
Color backgroundColor = weekendDefinition.isWeekend(shiftDate.getDayOfWeek())
? TangoColorFactory.ALUMINIUM_2 : shiftDatePanel.getBackground();
if (employee != null) {
if (employee.getDayOffRequestMap().containsKey(shiftDate)) {
backgroundColor = TangoColorFactory.ALUMINIUM_4;
} else if (employee.getDayOnRequestMap().containsKey(shiftDate)) {
backgroundColor = TangoColorFactory.SCARLET_1;
}
else if (employee.getHolidayRequestMap().containsKey(shiftDate)) {
backgroundColor = TangoColorFactory.ALUMINIUM_4;
}
}
推荐阅读
- graphql - 如何解决 GraphQL 错误,字段“x”不能有选择,因为类型“String”没有子字段
- python - 在给定这个有限状态机的情况下编写 Python 正则表达式
- unit-testing - 使用 InMemoryDatabase 为 EFCore 测试 IDbCommandInterceptor
- c# - C# (object sender, RoutedEventArgs e) 属性
- php - 如何使用 Laravel 多次上传数据
- pandas - 相同的计算适用于 pandas 数据框中的列
- javascript - Firebase 存储和 JavaScript,从存储下载文件
- windows - 有没有办法确定源端口号?
- node.js - 如何测试节点文件,在生成函数时收到“EACCES”错误
- python - Tabula-py 在 df 的一个特定列上返回“...”。其他一切似乎都有效,