gpt4 book ai didi

java - 在 EmployeePanel NurseRoster 中显示假期的建议方法

转载 作者:行者123 更新时间:2023-12-02 03:00:58 25 4
gpt4 key购买 nike

我已经为 NurseRoster Optaplanner 实现了一个假期组件。我遇到的问题是如何最好地在EmployeePanelGUI中显示假期。 (底部代码元素 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;
}
}

我想在休假/假期期间请求的所有日期中显示背景颜色。

最佳答案

我最终删除了这对并执行了以下狗代码:

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;
}


}

关于java - 在 EmployeePanel NurseRoster 中显示假期的建议方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57051109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com