设备日历修改

parent eeeb4888
...@@ -806,7 +806,7 @@ public class ResourceGanttController { ...@@ -806,7 +806,7 @@ public class ResourceGanttController {
return new ArrayList<>(); return new ArrayList<>();
} }
List<Machine> machineList = planResultService.InitCalendarToAllMachines2(sceneId); List<Machine> machineList = planResultService.InitCalendarToAllMachines3(schedule);
// 转换为 ResourceGanttVO 格式 // 转换为 ResourceGanttVO 格式
List<ResourceGanttVO> resourceGanttVOList = new ArrayList<>(); List<ResourceGanttVO> resourceGanttVOList = new ArrayList<>();
......
...@@ -1881,4 +1881,59 @@ private GlobalParam InitGlobalParam() ...@@ -1881,4 +1881,59 @@ private GlobalParam InitGlobalParam()
} }
public List<Machine> InitCalendarToAllMachines3(Chromosome chromosome) {
List<Machine> machines = chromosome.getInitMachines();
Set<Long> machineIds = chromosome.getResult().stream()
.map(GAScheduleResult::getMachineId)
.collect(Collectors.toSet());
machines = machines.stream()
.filter(machine -> machineIds.contains(machine.getId()))
.collect(Collectors.toList());
for (Machine machine:machines) {
{
List<Shift> result = new ArrayList<>();
List<Shift> shifts = machine.getShifts();
for (Shift shift : shifts) {
// 处理跨天班次(开始时间晚于结束时间的情况,如 7:30 到 3:30)
if (shift.getEndTime().isBefore(shift.getStartTime())) {
// 创建第一天的班次 (开始时间到24:00)
Shift firstShift = new Shift();
firstShift.setStartTime(shift.getStartTime());
firstShift.setEndTime(LocalTime.of(23, 59, 59)); // 23:59:59代替24:00
firstShift.setDays(new HashSet<>(shift.getDays()));
firstShift.setStatus(shift.getStatus());
firstShift.setStartDate(shift.getStartDate());
firstShift.setEndDate(shift.getEndDate());
firstShift.setSpecial(shift.isSpecial());
// 创建第二天的班次 (00:00到结束时间)
Shift secondShift = new Shift();
secondShift.setStartTime(LocalTime.MIDNIGHT);
secondShift.setEndTime(shift.getEndTime());
secondShift.setDays(new HashSet<>(shift.getDays()));
secondShift.setStatus(shift.getStatus());
secondShift.setStartDate(shift.getStartDate().plusDays(1));
secondShift.setEndDate(shift.getEndDate().plusDays(1));
secondShift.setSpecial(shift.isSpecial());
result.add(firstShift);
result.add(secondShift);
} else {
// 正常班次直接添加
result.add(shift);
}
}
machine.setShifts(result);
}
}
return machines;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment