|
@@ -1,13 +1,18 @@
|
|
|
package org.jeecg.modules.billet.billetHotsendChangeShift.util;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.modules.billet.storageBill.entity.ShiftGroupEnum;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
|
public class ScheduleUtils {
|
|
|
|
|
|
- public static ShiftInfo findNextShift(String[] data, int currentId, String currentShift, String currentShiftGroup) {
|
|
|
+ private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
|
|
+
|
|
|
+ public static ShiftInfo findNextShift(String[] data, int currentId, String currentShift) {
|
|
|
List<ShiftInfo> shiftList = new ArrayList<>();
|
|
|
Map<Integer, ShiftInfo> shiftMap = new HashMap<>();
|
|
|
|
|
@@ -16,8 +21,7 @@ public class ScheduleUtils {
|
|
|
String[] parts = line.split(" ");
|
|
|
int id = Integer.parseInt(parts[0]);
|
|
|
String shift = parts[1];
|
|
|
- String shiftgroup = parts[2];
|
|
|
- ShiftInfo shiftInfo = new ShiftInfo(id, shift, shiftgroup);
|
|
|
+ ShiftInfo shiftInfo = new ShiftInfo(id, shift);
|
|
|
shiftList.add(shiftInfo);
|
|
|
shiftMap.put(id, shiftInfo);
|
|
|
}
|
|
@@ -25,7 +29,7 @@ public class ScheduleUtils {
|
|
|
// 找到当前的 ShiftInfo 对象
|
|
|
ShiftInfo currentShiftInfo = null;
|
|
|
for (ShiftInfo info : shiftList) {
|
|
|
- if (info.getId() == currentId && info.getShift().equals(currentShift) && info.getShiftgroup().equals(currentShiftGroup)) {
|
|
|
+ if (info.getId() == currentId && info.getShift().equals(currentShift)) {
|
|
|
currentShiftInfo = info;
|
|
|
break;
|
|
|
}
|
|
@@ -39,41 +43,58 @@ public class ScheduleUtils {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 验证当前时间是否在指定时间范围内
|
|
|
+ * @param currentDate 当前日期
|
|
|
+ * @param startTime 开始时间,格式为 "HH:mm"
|
|
|
+ * @param endTime 结束时间,格式为 "HH:mm"
|
|
|
+ * @return 如果当前时间在指定时间范围内,返回 true;否则返回 false
|
|
|
+ */
|
|
|
+ public static boolean isBetweenTime(Date currentDate, String startTime, String endTime) {
|
|
|
+ try {
|
|
|
+ // 将开始时间和结束时间转换为 Date 对象
|
|
|
+ Date start = TIME_FORMAT.parse(startTime);
|
|
|
+ Date end = TIME_FORMAT.parse(endTime);
|
|
|
+
|
|
|
+ // 获取当前时间的小时和分钟
|
|
|
+ String currentTimeStr = TIME_FORMAT.format(currentDate);
|
|
|
+ Date currentTime = TIME_FORMAT.parse(currentTimeStr);
|
|
|
+
|
|
|
+ // 处理跨天的情况,例如 23:30 到 01:00
|
|
|
+ if (end.before(start)) {
|
|
|
+ // 如果结束时间早于开始时间,说明跨天了
|
|
|
+ return currentTime.after(start) || currentTime.before(end);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 正常情况,开始时间早于结束时间
|
|
|
+ return currentTime.after(start) && currentTime.before(end);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// public static void main(String[] args) {
|
|
|
// String[] data = {
|
|
|
-// "1 丙 夜", "2 甲 白", "3 乙 中", "4 丙 夜", "5 甲 白", "6 乙 中", "7 丙 夜", "8 甲 白", "9 乙 中", "10 丙 夜",
|
|
|
-// "11 甲 白", "12 乙 中", "13 丁 夜", "14 丙 白", "15 甲 中", "16 丁 夜", "17 丙 白", "18 甲 中", "19 丁 夜", "20 丙 白",
|
|
|
-// "21 甲 中", "22 丁 夜", "23 丙 白", "24 甲 中", "25 乙 夜", "26 丁 白", "27 丙 中", "28 乙 夜", "29 丁 白", "30 丙 中",
|
|
|
-// "31 乙 夜", "32 丁 白", "33 丙 中", "34 乙 夜", "35 丁 白", "36 丙 中", "37 甲 夜", "38 乙 白", "39 丁 中", "40 甲 夜",
|
|
|
-// "41 乙 白", "42 丁 中", "43 甲 夜", "44 乙 白", "45 丁 中", "46 甲 夜", "47 乙 白", "48 丁 中"
|
|
|
+// "1 丙", "2 甲", "3 乙", "4 丙", "5 甲", "6 乙", "7 丙", "8 甲", "9 乙", "10 丙",
|
|
|
+// "11 甲", "12 乙", "13 丁", "14 丙", "15 甲", "16 丁", "17 丙", "18 甲", "19 丁", "20 丙",
|
|
|
+// "21 甲", "22 丁", "23 丙", "24 甲", "25 乙", "26 丁", "27 丙", "28 乙", "29 丁", "30 丙",
|
|
|
+// "31 乙", "32 丁", "33 丙", "34 乙", "35 丁", "36 丙", "37 甲", "38 乙", "39 丁", "40 甲",
|
|
|
+// "41 乙", "42 丁", "43 甲", "44 乙", "45 丁", "46 甲", "47 乙", "48 丁"
|
|
|
// };
|
|
|
//
|
|
|
-// int currentUniqueShiftId = 26;
|
|
|
-//
|
|
|
+// int currentUniqueShiftId = 16;
|
|
|
// String currentShift = "丁";
|
|
|
//
|
|
|
-// String currentShiftGroup = "白";
|
|
|
-//
|
|
|
-// ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, currentUniqueShiftId, currentShift, currentShiftGroup);
|
|
|
-// if (nextShiftInfo == null){
|
|
|
+// ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, currentUniqueShiftId, currentShift);
|
|
|
+// if (nextShiftInfo == null) {
|
|
|
// log.info("{}{}", "获取到下个班组信息为空!", new Date() + "自动化交班失败!");
|
|
|
// return;
|
|
|
// }
|
|
|
-// String nextShift = nextShiftInfo.shift;
|
|
|
-//
|
|
|
-// String nextShiftGroup = nextShiftInfo.shiftgroup;
|
|
|
-//
|
|
|
-// int nextUniqueShiftId= nextShiftInfo.getId();
|
|
|
-// // redis中更新缓存nextUniqueShiftId
|
|
|
-//
|
|
|
-// log.info("{}{}", "获取到下个班组信息:", nextShift+" "+nextShiftGroup);
|
|
|
-// log.info("{}{}", "获取到下个交班索引ID:", nextUniqueShiftId);
|
|
|
-// // 甲:0,乙:1,丙、2,丁:3 白:0、夜:1, 中:2
|
|
|
-//// 0 0 0 * * ?
|
|
|
-//// 0 0 8 * * ?
|
|
|
-//// 0 0 16 * * ?
|
|
|
-//
|
|
|
-//
|
|
|
//
|
|
|
+// // 班组
|
|
|
+// String nextShiftGroupName = nextShiftInfo.getShift();
|
|
|
+// int nextUniqueShiftId = nextShiftInfo.getId();
|
|
|
+// String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftGroupName);
|
|
|
// }
|
|
|
}
|