duhongyu 5 kuukautta sitten
vanhempi
commit
fcc6d35b9c

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

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

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

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

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

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

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

36
         {
36
         {
37
             LocalTime restStart = LocalTime.parse(input.getWorkStartTime(), formatter);
37
             LocalTime restStart = LocalTime.parse(input.getWorkStartTime(), formatter);
38
             LocalTime restEnd = LocalTime.parse(input.getWorkEndTime(), formatter);
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
             if (input.getRestDuration()!=null&&input.getRestDuration()>0)
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
             else
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
         Map<User, Map<Date, Long>> UserSchedules = new HashMap<>();
59
         Map<User, Map<Date, Long>> UserSchedules = new HashMap<>();
60
         Map<Date, Map<Long, Integer>> dailyShiftCount = new HashMap<>();
60
         Map<Date, Map<Long, Integer>> dailyShiftCount = new HashMap<>();
61
         // 步骤1: 整合现有排班(若不替换)
61
         // 步骤1: 整合现有排班(若不替换)
62
-        if (constraint.getIsReplace()==0 ) {
62
+
63
             for (User emp : Users) {
63
             for (User emp : Users) {
64
                 Map<Date, Long> empSchedule = new HashMap<>();
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
             LambdaUpdateWrapper<SchedulingManage> ManageUpdate =new LambdaUpdateWrapper<>();
83
             LambdaUpdateWrapper<SchedulingManage> ManageUpdate =new LambdaUpdateWrapper<>();
92
         Date currentDate = constraint.getStartTime();
92
         Date currentDate = constraint.getStartTime();
93
         Calendar calendar=Calendar.getInstance();
93
         Calendar calendar=Calendar.getInstance();
94
         calendar.setTime(currentDate);
94
         calendar.setTime(currentDate);
95
-        while (currentDate.before(constraint.getEndTime())) {
95
+        while (currentDate.compareTo(constraint.getEndTime()) <= 0) {
96
             // 初始化当天班别人数计数
96
             // 初始化当天班别人数计数
97
             Map<Long, Integer> shiftCount = dailyShiftCount
97
             Map<Long, Integer> shiftCount = dailyShiftCount
98
                     .computeIfAbsent(currentDate, k -> initializeShiftCount(constraint));
98
                     .computeIfAbsent(currentDate, k -> initializeShiftCount(constraint));
193
     private List<User> getAvailableEmployees(List<User> employees,
193
     private List<User> getAvailableEmployees(List<User> employees,
194
                                                  Map<User, Map<Date, Long>> schedules,
194
                                                  Map<User, Map<Date, Long>> schedules,
195
                                                  Date date) {
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
     private Map<Long, Integer> initializeShiftCount(SchedulingRule constraint) {
208
     private Map<Long, Integer> initializeShiftCount(SchedulingRule constraint) {
329
             List<String> intersection = availableShifts.stream()
336
             List<String> intersection = availableShifts.stream()
330
                     .filter( Arrays.asList(emp.getPreference().split(","))::contains) // 检查元素是否在list2中
337
                     .filter( Arrays.asList(emp.getPreference().split(","))::contains) // 检查元素是否在list2中
331
                     .collect(Collectors.toList());
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
         // 随机选择可用班别