Browse Source

交班 限制时间

guoqiang 1 month ago
parent
commit
80fb028c58

+ 6 - 13
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/controller/BilletHotsendChangeShiftController.java

@@ -155,20 +155,19 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 		log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " C端自动化当前班次信息名:" + currentCacheId + "," + currentShiftName+ ","+ currentShiftGroupName);
 
 		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 丁"
 		};
 
-		ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName, currentShiftName);
+		ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName);
 		if (nextShiftInfo == null){
 			log.info("{}{}", "获取到下个班组信息为空!", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + "C端自动化交班失败!");
 			return Result.OK(null);
 		}
 
-		String nextShiftGroupName = nextShiftInfo.getShiftgroup();
 
 		String nextShiftName = nextShiftInfo.getShift();
 
@@ -176,12 +175,6 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 
 		String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftName);
 
-		String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftGroupName + "班");;
-
-		log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " C端自动化下一个班次信息值:" + finalNextShiftVal + ","+ finalNextShiftGroupVal);
-		log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " C端自动化下一个班次信息名:" + nextUniqueShiftId + "," + nextShiftGroupName + ","+ nextShiftName);
-
-
 		return Result.OK(null);
 	}
 }

+ 55 - 32
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/impl/BilletHotsendChangeShiftServiceImpl.java

@@ -87,28 +87,39 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
         log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 5号机C端自动化当前班次信息名:" + currentCacheId + "," + currentShiftName+ ","+ currentShiftGroupName);
 
         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 丁"
         };
 
-        ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName, currentShiftName);
-        if (nextShiftInfo == null){
+        ShiftInfo nextShiftGroupInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName);
+        if (nextShiftGroupInfo == null){
             log.info("{}{}", "5号机获取到下个班组信息为空!", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + "C端自动化交班失败!");
             return;
         }
+        // 班别名(白中夜)
+        String nextShiftName  = "";
+        // 验证23:00 到01:00 之间
+        if (ScheduleUtils.isBetweenTime(new Date(), "07:30", "08:30")) {
+            nextShiftName = "白";
+        } else if (ScheduleUtils.isBetweenTime(new Date(), "15:30", "16:30")) {
+            nextShiftName = "中";
+        } else if (ScheduleUtils.isBetweenTime(new Date(), "23:30", "01:00")) {
+            nextShiftName = "夜";
+        }else {
+            log.info("{}{}", "未在交班范围内,", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + "5号机C端自动化交班失败!");
+            return;
+        }
+        // 班组名(甲乙丙丁)
+        String nextShiftGroupName =  nextShiftGroupInfo.getShift();
+        // 班组值
+        String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftGroupName);
+        // 班别值
+        String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftName + "班");
 
-        String nextShiftGroupName = nextShiftInfo.getShiftgroup();
-
-        String nextShiftName = nextShiftInfo.getShift();
-
-        int nextUniqueShiftId = nextShiftInfo.getId();
-
-        String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftName);
-
-        String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftGroupName + "班");;
+        int nextUniqueShiftId = nextShiftGroupInfo.getId();
 
         redisTemplate.opsForValue().set(nextshiftIdKey, nextUniqueShiftId);
 
@@ -175,28 +186,40 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
         log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 6号机C端自动化当前班次信息名:" + currentCacheId + "," + currentShiftName+ ","+ currentShiftGroupName);
 
         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 丁"
         };
 
-        ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName, currentShiftName);
-        if (nextShiftInfo == null){
+        ShiftInfo nextShiftGroupInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName);
+        if (nextShiftGroupInfo == null){
             log.info("{}{}", "6号机获取到下个班组信息为空!", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + "6号机C端自动化交班失败!");
             return;
         }
 
-        String nextShiftGroupName = nextShiftInfo.getShiftgroup();
-
-        String nextShiftName = nextShiftInfo.getShift();
-
-        int nextUniqueShiftId = nextShiftInfo.getId();
-
-        String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftName);
-
-        String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftGroupName + "班");;
+        // 班别名
+        String nextShiftName  = "";
+        // 验证23:00 到01:00 之间
+        if (ScheduleUtils.isBetweenTime(new Date(), "07:30", "08:30")) {
+            nextShiftName = "白";
+        } else if (ScheduleUtils.isBetweenTime(new Date(), "15:30", "16:30")) {
+            nextShiftName = "中";
+        } else if (ScheduleUtils.isBetweenTime(new Date(), "23:30", "01:00")) {
+            nextShiftName = "夜";
+        }else {
+            log.info("{}{}", "未在交班范围内,", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + "6号机C端自动化交班失败!");
+            return;
+        }
+        // 班组名
+        String nextShiftGroupName =  nextShiftGroupInfo.getShift();
+        // 班组值
+        String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftGroupName);
+        // 班别值
+        String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftName + "班");
+
+        int nextUniqueShiftId = nextShiftGroupInfo.getId();
 
         redisTemplate.opsForValue().set(nextshiftIdKey, nextUniqueShiftId);
 

+ 63 - 45
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/util/ScheduleUtils.java

@@ -1,16 +1,18 @@
 package org.jeecg.modules.billetActual.util;
 
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.modules.storageBill.entity.ShiftGroupEnum;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+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<>();
 
@@ -19,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);
         }
@@ -28,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;
             }
@@ -42,41 +43,58 @@ public class ScheduleUtils {
         return null;
     }
 
-//    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 丁 中"
-//        };
-//
-//        int currentUniqueShiftId = 26;
-//
-//        String currentShift = "丁";
-//
-//        String currentShiftGroup = "白";
-//
-//        ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, currentUniqueShiftId, currentShift, currentShiftGroup);
-//        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 * * ?
-//
-//
-//
-//    }
+    /**
+     * 验证当前时间是否在指定时间范围内
+     * @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 丁"
+        };
+
+        int currentUniqueShiftId = 16;
+        String currentShift = "丁";
+
+        ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, currentUniqueShiftId, currentShift);
+        if (nextShiftInfo == null) {
+            log.info("{}{}", "获取到下个班组信息为空!", new Date() + "自动化交班失败!");
+            return;
+        }
+
+        // 班组
+        String nextShiftGroupName = nextShiftInfo.getShift();
+        int nextUniqueShiftId = nextShiftInfo.getId();
+        String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftGroupName);
+    }
 }

+ 1 - 4
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/util/ShiftInfo.java

@@ -7,12 +7,10 @@ import lombok.Data;
 public class ShiftInfo {
     int id;
     String shift;
-    String shiftgroup;
 
-    public ShiftInfo(int id, String shift, String shiftgroup) {
+    public ShiftInfo(int id, String shift) {
         this.id = id;
         this.shift = shift;
-        this.shiftgroup = shiftgroup;
     }
 
     @Override
@@ -20,7 +18,6 @@ public class ShiftInfo {
         return "ShiftInfo{" +
                 "id=" + id +
                 ", shift='" + shift + '\'' +
-                ", shiftgroup='" + shiftgroup + '\'' +
                 '}';
     }
 }