|
|
@@ -59,25 +59,25 @@ public class SchedulingRuleServiceImpl extends BaseServiceImpl<SchedulingRuleMap
|
|
59
|
59
|
Map<User, Map<Date, Long>> UserSchedules = new HashMap<>();
|
|
60
|
60
|
Map<Date, Map<Long, Integer>> dailyShiftCount = new HashMap<>();
|
|
61
|
61
|
// 步骤1: 整合现有排班(若不替换)
|
|
62
|
|
- if (constraint.getIsReplace()==0 ) {
|
|
|
62
|
+
|
|
63
|
63
|
for (User emp : Users) {
|
|
64
|
64
|
Map<Date, Long> empSchedule = new HashMap<>();
|
|
65
|
|
- if (existingShifts.containsKey(emp)) {
|
|
66
|
|
- for (SchedulingManage shift : existingShifts.get(emp)) {
|
|
67
|
|
- if (shift.getSchedulingDate().after(constraint.getStartTime()) &&
|
|
68
|
|
- shift.getSchedulingDate().before(constraint.getEndTime())) {
|
|
69
|
|
- empSchedule.put( shift.getSchedulingDate(), shift.getClassId());
|
|
70
|
|
- // 更新班别人数计数
|
|
71
|
|
- dailyShiftCount
|
|
72
|
|
- .computeIfAbsent(shift.getSchedulingDate(), k -> initializeShiftCount(constraint))
|
|
73
|
|
- .merge(shift.getClassId(), 1, Integer::sum);
|
|
|
65
|
+ if (constraint.getIsReplace()==0 ) {
|
|
|
66
|
+ if (existingShifts.containsKey(emp)) {
|
|
|
67
|
+ for (SchedulingManage shift : existingShifts.get(emp)) {
|
|
|
68
|
+ if (shift.getSchedulingDate().after(constraint.getStartTime()) &&
|
|
|
69
|
+ shift.getSchedulingDate().before(constraint.getEndTime())) {
|
|
|
70
|
+ empSchedule.put(shift.getSchedulingDate(), shift.getClassId());
|
|
|
71
|
+ // 更新班别人数计数
|
|
|
72
|
+ dailyShiftCount
|
|
|
73
|
+ .computeIfAbsent(shift.getSchedulingDate(), k -> initializeShiftCount(constraint))
|
|
|
74
|
+ .merge(shift.getClassId(), 1, Integer::sum);
|
|
|
75
|
+ }
|
|
74
|
76
|
}
|
|
75
|
77
|
}
|
|
76
|
78
|
}
|
|
77
|
|
- UserSchedules.put(emp, empSchedule);
|
|
78
|
|
- }
|
|
79
|
|
- }
|
|
80
|
|
- else
|
|
|
79
|
+ UserSchedules.put(emp, empSchedule);}
|
|
|
80
|
+ if (constraint.getIsReplace()==1 )
|
|
81
|
81
|
{
|
|
82
|
82
|
//删除现有排班
|
|
83
|
83
|
LambdaUpdateWrapper<SchedulingManage> ManageUpdate =new LambdaUpdateWrapper<>();
|
|
|
@@ -92,7 +92,7 @@ public class SchedulingRuleServiceImpl extends BaseServiceImpl<SchedulingRuleMap
|
|
92
|
92
|
Date currentDate = constraint.getStartTime();
|
|
93
|
93
|
Calendar calendar=Calendar.getInstance();
|
|
94
|
94
|
calendar.setTime(currentDate);
|
|
95
|
|
- while (currentDate.before(constraint.getEndTime())) {
|
|
|
95
|
+ while (currentDate.compareTo(constraint.getEndTime()) <= 0) {
|
|
96
|
96
|
// 初始化当天班别人数计数
|
|
97
|
97
|
Map<Long, Integer> shiftCount = dailyShiftCount
|
|
98
|
98
|
.computeIfAbsent(currentDate, k -> initializeShiftCount(constraint));
|
|
|
@@ -193,9 +193,16 @@ public class SchedulingRuleServiceImpl extends BaseServiceImpl<SchedulingRuleMap
|
|
193
|
193
|
private List<User> getAvailableEmployees(List<User> employees,
|
|
194
|
194
|
Map<User, Map<Date, Long>> schedules,
|
|
195
|
195
|
Date date) {
|
|
196
|
|
- return employees.stream()
|
|
197
|
|
- .filter(emp -> !schedules.get(emp).containsKey(date))
|
|
198
|
|
- .collect(Collectors.toList());
|
|
|
196
|
+ if (schedules.size()>0)
|
|
|
197
|
+ {
|
|
|
198
|
+ return employees.stream()
|
|
|
199
|
+ .filter(emp -> !schedules.get(emp).containsKey(date))
|
|
|
200
|
+ .collect(Collectors.toList());
|
|
|
201
|
+ }
|
|
|
202
|
+ else
|
|
|
203
|
+ {
|
|
|
204
|
+ return new ArrayList<>();
|
|
|
205
|
+ }
|
|
199
|
206
|
}
|
|
200
|
207
|
|
|
201
|
208
|
private Map<Long, Integer> initializeShiftCount(SchedulingRule constraint) {
|
|
|
@@ -329,8 +336,11 @@ public class SchedulingRuleServiceImpl extends BaseServiceImpl<SchedulingRuleMap
|
|
329
|
336
|
List<String> intersection = availableShifts.stream()
|
|
330
|
337
|
.filter( Arrays.asList(emp.getPreference().split(","))::contains) // 检查元素是否在list2中
|
|
331
|
338
|
.collect(Collectors.toList());
|
|
|
339
|
+ if (intersection.size()>0)
|
|
|
340
|
+ {
|
|
|
341
|
+ return intersection.get(new Random().nextInt(intersection.size()));
|
|
|
342
|
+ }
|
|
332
|
343
|
|
|
333
|
|
- return intersection.get(new Random().nextInt(availableShifts.size()));
|
|
334
|
344
|
}
|
|
335
|
345
|
|
|
336
|
346
|
// 随机选择可用班别
|