duhongyu 5 meses atrás
pai
commit
fcc6d35b9c

+ 3 - 0
ltrq-entity/src/main/java/api/entity/database/scheduling/SchedulingClass.java

@@ -6,6 +6,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
6 6
 import io.swagger.annotations.ApiModel;
7 7
 import io.swagger.annotations.ApiModelProperty;
8 8
 import lombok.Data;
9
+import org.apache.poi.hpsf.Decimal;
10
+
11
+import java.math.BigDecimal;
9 12
 import java.util.Date;
10 13
 
11 14
 /** scheduling_class */

+ 2 - 1
ltrq-entity/src/main/java/api/entity/database/scheduling/SchedulingManage.java

@@ -3,6 +3,7 @@ package api.entity.database.scheduling;
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import com.baomidou.mybatisplus.annotation.TableId;
5 5
 import com.baomidou.mybatisplus.annotation.TableName;
6
+import com.fasterxml.jackson.annotation.JsonFormat;
6 7
 import io.swagger.annotations.ApiModel;
7 8
 import io.swagger.annotations.ApiModelProperty;
8 9
 import lombok.Data;
@@ -21,7 +22,7 @@ public class SchedulingManage {
21 22
     private Long id;
22 23
     /** 排班日期 */
23 24
     @ApiModelProperty("排班日期")
24
-    @DateTimeFormat(pattern="yyyy-MM-dd")
25
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "UTC")
25 26
     private Date schedulingDate;
26 27
     /** 排班人员 */
27 28
     @ApiModelProperty("排班人员")

+ 3 - 2
ltrq-entity/src/main/java/api/entity/database/scheduling/SchedulingRule.java

@@ -3,6 +3,7 @@ package api.entity.database.scheduling;
3 3
 import com.baomidou.mybatisplus.annotation.IdType;
4 4
 import com.baomidou.mybatisplus.annotation.TableId;
5 5
 import com.baomidou.mybatisplus.annotation.TableName;
6
+import com.fasterxml.jackson.annotation.JsonFormat;
6 7
 import io.swagger.annotations.ApiModel;
7 8
 import io.swagger.annotations.ApiModelProperty;
8 9
 import lombok.Data;
@@ -21,11 +22,11 @@ public class SchedulingRule {
21 22
     private Long ruleId;
22 23
     /** 开始时间 */
23 24
     @ApiModelProperty("开始时间")
24
-    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
25
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
25 26
     private Date startTime;
26 27
     /** 结束时间 */
27 28
     @ApiModelProperty("结束时间")
28
-    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
29
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
29 30
     private Date endTime;
30 31
     /** 最大连续工作天数 */
31 32
     @ApiModelProperty("最大连续工作天数")

+ 19 - 5
ltrq-service/src/main/java/api/service/scheduling/impl/SchedulingClassServiceImpl.java

@@ -36,16 +36,30 @@ public class SchedulingClassServiceImpl extends BaseServiceImpl<SchedulingClassM
36 36
         {
37 37
             LocalTime restStart = LocalTime.parse(input.getWorkStartTime(), formatter);
38 38
             LocalTime restEnd = LocalTime.parse(input.getWorkEndTime(), formatter);
39
-            // 计算时间差
40
-            Duration duration = Duration.between(restStart, restEnd);
41
-            double hoursDifference = duration.toMinutes() / 60.0; // 转为小时(含小数)
39
+            double hoursDifference=0;
40
+            if (restStart.isBefore(restEnd))
41
+             {
42
+                 // 计算时间差
43
+                 Duration duration = Duration.between(restStart, restEnd);
44
+                 hoursDifference  = duration.toMinutes() / 60.0; // 转为小时(含小数)
45
+             }
46
+            else
47
+            {
48
+                LocalTime restEnd1 = LocalTime.parse("00:00:00", formatter);
49
+                LocalTime restStart1 = LocalTime.parse("23:59:59", formatter);
50
+                Duration duration = Duration.between(restStart, restStart1);
51
+                Duration duration1 = Duration.between(restEnd1, restEnd);
52
+                hoursDifference = (duration.plusSeconds(1).toMinutes() / 60.0)+
53
+                        (duration1.toMinutes() / 60.0); // 转为小时(含小数)
54
+            }
55
+
42 56
             if (input.getRestDuration()!=null&&input.getRestDuration()>0)
43 57
             {
44
-                input.setRestDuration(hoursDifference-input.getRestDuration());
58
+                input.setWorkDuration(hoursDifference-input.getRestDuration());
45 59
             }
46 60
             else
47 61
             {
48
-                input.setRestDuration(hoursDifference);
62
+                input.setWorkDuration(hoursDifference);
49 63
             }
50 64
 
51 65
         }

+ 29 - 19
ltrq-service/src/main/java/api/service/scheduling/impl/SchedulingRuleServiceImpl.java

@@ -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
         // 随机选择可用班别