qiangxuan 2 mesiacov pred
rodič
commit
dcf2937dae

+ 39 - 100
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/controller/BilletHotsendChangeShiftController.java

@@ -18,7 +18,8 @@ import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.actualControl.heatsActuals.service.IHeatsActualsService;
 import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
 import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
-import org.jeecg.modules.billet.billetHotsendChangeShift.util.ScheduleRecord;
+import org.jeecg.modules.billet.billetHotsendChangeShift.util.ScheduleUtils;
+import org.jeecg.modules.billet.billetHotsendChangeShift.util.ShiftInfo;
 import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
 import org.jeecg.modules.billet.storageBill.entity.ShiftEnum;
 import org.jeecg.modules.billet.storageBill.entity.ShiftGroupEnum;
@@ -34,7 +35,6 @@ import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -288,7 +288,7 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 			redisTemplate.opsForValue().set(nextshiftIdKey, nextId);
 			return Result.OK("设置交班索引i为:" + nextId);
 		}
-//		performShiftChange(null);
+		performShiftChange(null);
 		return Result.OK(null);
 	}
 	/**
@@ -304,116 +304,55 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 		String sixShiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftGroupsix));
 		String sixShift = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftsix));
 
-
 		String currentShiftGroupName = ShiftGroupEnum.fromCode(sixShiftGroup).name();
 		String currentShiftName = ShiftEnum.fromCode(sixShift).name().replace("班", "");
 
 		String nextshiftIdKey = String.format("class:nextshift:Id:%s", "5-6");
-		String nextCacheId = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
+		String currentCacheId = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
+
+		log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 当前班次信息值:" + sixShift+ ","+ sixShiftGroup);
+		log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 当前班次信息名:" + 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 丁 中"
+		};
+
+		ShiftInfo nextShiftInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName, currentShiftName);
+		if (nextShiftInfo == null){
+			log.info("{}{}", "获取到下个班组信息为空!", new Date() + "自动化交班失败!");
+			return;
+		}
 
+		String nextShiftGroupName = nextShiftInfo.getShiftgroup();
 
-		String nextShiftGroupName = "";
-		String nextShiftName = "";
-		int nextShiftGroupVal = 0;
-		int nextShiftVal = 0;
-
-
-		List<ScheduleRecord> scheduleRecordListAll = new ArrayList<>();
-		// 将数据添加到列表中
-		scheduleRecordListAll.add(new ScheduleRecord(1, "丙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(2, "甲", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(3, "乙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(4, "丙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(5, "甲", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(6, "乙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(7, "丙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(8, "甲", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(9, "乙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(10, "丙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(11, "甲", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(12, "乙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(13, "丁", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(14, "丙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(15, "甲", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(16, "丁", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(17, "丙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(18, "甲", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(19, "丁", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(20, "丙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(21, "甲", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(22, "丁", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(23, "丙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(24, "甲", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(25, "乙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(26, "丁", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(27, "丙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(28, "乙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(29, "丁", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(30, "丙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(31, "乙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(32, "丁", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(33, "丙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(34, "乙", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(35, "丁", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(36, "丙", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(37, "甲", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(38, "乙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(39, "丁", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(40, "甲", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(41, "乙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(42, "丁", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(43, "甲", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(44, "乙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(45, "丁", "中"));
-		scheduleRecordListAll.add(new ScheduleRecord(46, "甲", "夜"));
-		scheduleRecordListAll.add(new ScheduleRecord(47, "乙", "白"));
-		scheduleRecordListAll.add(new ScheduleRecord(48, "丁", "中"));
-
-		if (oConvertUtils.isEmpty(nextCacheId)) {
-			for (ScheduleRecord scheduleRecord : scheduleRecordListAll) {
-				if (currentShiftGroupName.equals(scheduleRecord.getShiftGroup()) && currentShiftName.equals(scheduleRecord.getShift())) {
-					nextShiftGroupName = scheduleRecord.getShiftGroup();
-					nextShiftName = scheduleRecord.getShift();
-					nextShiftGroupVal = scheduleRecord.getShiftGroupValue();
-					nextShiftVal = scheduleRecord.getShiftValue();
-					redisTemplate.opsForValue().set(nextshiftIdKey, scheduleRecord.getId() + 1);
-					break;
-				}
-			}
-		}else {
-			for (ScheduleRecord scheduleRecord : scheduleRecordListAll) {
-				if (scheduleRecord.getId() == Integer.parseInt(nextCacheId)) {
-
-					nextShiftName = scheduleRecord.getShift();
-					nextShiftGroupName = scheduleRecord.getShiftGroup();
-
-					nextShiftGroupVal = scheduleRecord.getShiftGroupValue();
-					nextShiftVal = scheduleRecord.getShiftValue();
-
-					if (Integer.parseInt(nextCacheId) == 48){
-						redisTemplate.opsForValue().set(nextshiftIdKey, 1);
-					}else {
-						redisTemplate.opsForValue().set(nextshiftIdKey, scheduleRecord.getId() + 1);
-					}
-				}
-			}
-		}
-		log.info(new Date() + "下一个班次名::" + nextCacheId + ","+nextShiftGroupName+ ","+ nextShiftName);
-		log.info("下一个班次值::" + nextShiftGroupVal+ ","+ nextShiftVal);
+		String nextShiftName = nextShiftInfo.getShift();
+
+		int nextUniqueShiftId = nextShiftInfo.getId();
+
+		String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftName);
+
+		String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftGroupName + "班");;
+
+		redisTemplate.opsForValue().set(nextshiftIdKey, nextUniqueShiftId);
+
+		log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 下一个班次信息值:" + finalNextShiftVal + ","+ finalNextShiftGroupVal);
+		log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 下一个班次信息名:" + nextUniqueShiftId + "," + nextShiftGroupName + ","+ nextShiftName);
 
-		String finalNextShiftGroupVal = String.valueOf(nextShiftGroupVal);
-		String finalNextShiftVal = String.valueOf(nextShiftVal);
 		// 查询当天的交班记录
 		LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapperCS = new LambdaQueryWrapper<>();
 		queryWrapperCS.between(BilletHotsendChangeShift::getCreateTime, DateUtils.getStartOfDay(), DateUtils.getEndOfDay());
 		List<BilletHotsendChangeShift> billetHotsendChangeShiftList = billetHotsendChangeShiftService.list(queryWrapperCS);
 
-		String nextShift = String.join(",", finalNextShiftVal, finalNextShiftGroupVal);
+		String nextShiftAndShiftGroupInfo = String.join(",", finalNextShiftVal, finalNextShiftGroupVal);
 
 		if (oConvertUtils.listIsNotEmpty(billetHotsendChangeShiftList)) {
 			boolean exists = billetHotsendChangeShiftList.stream()
 					.map(x -> String.join(",", x.getShift(), x.getShiftGroup()))
-					.anyMatch(s -> s.equals(nextShift));
+					.anyMatch(s -> s.equals(nextShiftAndShiftGroupInfo));
 			if (exists) {
 				log.info("自动交班,当天不能重复交班! {}", new Date());
 				// 自动交班失败,交班ID索引值回滚,保证交班顺序
@@ -428,14 +367,14 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 		billetHotsendChangeShiftVo.setShiftGroup(finalNextShiftGroupVal);
 		billetHotsendChangeShiftVo.setShift(finalNextShiftVal);
 		JSONObject jsonObject = billetHotsendChangeShiftService.autoChangeShiftHandle(billetHotsendChangeShiftVo);
-		log.info("自动化{}交班成功!{} 结果值:{}", shiftName, new Date(), jsonObject);
+		log.info("自动化{}交班成功!{} 结果值:{}", shiftName, DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()), jsonObject);
 	}
 
-//	@Scheduled(cron = "0 38 17 * * ?")
+	@Scheduled(cron = "0 40 10 * * ?")
 	public void executeNeightShiftTask1() {
 		log.info("设置索引iD");
 		String nextshiftIdKey = String.format("class:nextshift:Id:%s", "5-6");
-		redisTemplate.opsForValue().set(nextshiftIdKey, 22);
+		redisTemplate.opsForValue().set(nextshiftIdKey, 26);
 	}
 
 //	@Scheduled(cron = "0 * * * * ?")

+ 0 - 1
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/service/impl/BilletHotsendChangeShiftServiceImpl.java

@@ -218,7 +218,6 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
                 billetHotsendChangeShift1.setWasteAmount(0); // 当前废品支数
                 billetHotsendChangeShift1.setCreateTime(new Date());
                 baseMapper.insert(billetHotsendChangeShift1);
-                operateLogService.add(billetHotsendChangeShift1, null, BilletHotsendChangeShift.class);
                 result.put("success", "自动化交班操作成功!");
             } catch (Exception e) {
                 log.error("自动化交班操作出现异常", e);

+ 0 - 76
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/util/ScheduleRecord.java

@@ -1,76 +0,0 @@
-package org.jeecg.modules.billet.billetHotsendChangeShift.util;
-
-import lombok.Data;
-
-@Data
-public class ScheduleRecord {
-
-    private int id;
-    private String shiftGroup; // 人员,如甲、乙、丙、丁
-    private String shift;      // 班次,如白、中、夜
-    private String startTime;  // 班次开始时间
-    private String endTime;    // 班次结束时间
-
-    public ScheduleRecord(int id, String shiftGroup, String shift) {
-        this.id = id;
-        this.shiftGroup = shiftGroup;
-        this.shift = shift;
-        // 根据班次设置开始和结束时间
-        switch (shift) {
-            case "白":
-                this.startTime = "00:00:00";
-                this.endTime = "08:00:00";
-                break;
-            case "中":
-                this.startTime = "08:00:01";
-                this.endTime = "16:00:00";
-                break;
-            case "夜":
-                this.startTime = "16:00:01";
-                this.endTime = "00:00:00";
-                break;
-            default:
-                this.startTime = "";
-                this.endTime = "";
-        }
-    }
-
-    public int getId() {
-        return id;
-    }
-
-    // 获取人员对应的值
-    public int getShiftGroupValue() {
-        switch (shiftGroup) {
-            case "甲":
-                return 0;
-            case "乙":
-                return 1;
-            case "丙":
-                return 2;
-            case "丁":
-                return 3;
-            default:
-                return -1;
-        }
-    }
-
-    // 获取班次对应的值
-    public int getShiftValue() {
-        switch (shift) {
-            case "白":
-                return 0;
-            case "中":
-                return 2;
-            case "夜":
-                return 1;
-            default:
-                return -1;
-        }
-    }
-
-    @Override
-    public String toString() {
-        return "id: " + id + ", 人员: " + shiftGroup + "(" + getShiftGroupValue() + "), 班次: " + shift + "(" + getShiftValue() + "), 时段: " + startTime + " - " + endTime;
-    }
-}

+ 79 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/util/ScheduleUtils.java

@@ -0,0 +1,79 @@
+package org.jeecg.modules.billet.billetHotsendChangeShift.util;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.*;
+
+@Slf4j
+public class ScheduleUtils {
+
+    public static ShiftInfo findNextShift(String[] data, int currentId, String currentShift, String currentShiftGroup) {
+        List<ShiftInfo> shiftList = new ArrayList<>();
+        Map<Integer, ShiftInfo> shiftMap = new HashMap<>();
+
+        // Parse data into list and map
+        for (String line : data) {
+            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);
+            shiftList.add(shiftInfo);
+            shiftMap.put(id, shiftInfo);
+        }
+
+        // 找到当前的 ShiftInfo 对象
+        ShiftInfo currentShiftInfo = null;
+        for (ShiftInfo info : shiftList) {
+            if (info.getId() == currentId && info.getShift().equals(currentShift) && info.getShiftgroup().equals(currentShiftGroup)) {
+                currentShiftInfo = info;
+                break;
+            }
+        }
+
+        if (currentShiftInfo != null) {
+            // 计算下一个 id
+            int nextId = (currentId % shiftList.size()) + 1;
+            return shiftMap.get(nextId);
+        }
+        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 * * ?
+//
+//
+//
+//    }
+}

+ 26 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/util/ShiftInfo.java

@@ -0,0 +1,26 @@
+package org.jeecg.modules.billet.billetHotsendChangeShift.util;
+
+
+import lombok.Data;
+
+@Data
+public class ShiftInfo {
+    int id;
+    String shift;
+    String shiftgroup;
+
+    public ShiftInfo(int id, String shift, String shiftgroup) {
+        this.id = id;
+        this.shift = shift;
+        this.shiftgroup = shiftgroup;
+    }
+
+    @Override
+    public String toString() {
+        return "ShiftInfo{" +
+                "id=" + id +
+                ", shift='" + shift + '\'' +
+                ", shiftgroup='" + shiftgroup + '\'' +
+                '}';
+    }
+}

+ 10 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/entity/ShiftEnum.java

@@ -30,4 +30,14 @@ public enum ShiftEnum {
         }
         throw new IllegalArgumentException("无效的代码值: " + code);
     }
+
+    // 根据传入的枚举名称查找对应的代码的静态方法
+    public static String getCodeByName(String name) {
+        for (ShiftEnum group : ShiftEnum.values()) {
+            if (group.name().equals(name)) {
+                return group.getCode();
+            }
+        }
+        throw new IllegalArgumentException("无效的枚举名称: " + name);
+    }
 }

+ 10 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/entity/ShiftGroupEnum.java

@@ -30,4 +30,14 @@ public enum ShiftGroupEnum {
         }
         throw new IllegalArgumentException("无效的代码值: " + code);
     }
+
+    // 根据传入的枚举名称查找对应的代码的静态方法
+    public static String getCodeByName(String name) {
+        for (ShiftGroupEnum group : ShiftGroupEnum.values()) {
+            if (group.name().equals(name)) {
+                return group.getCode();
+            }
+        }
+        throw new IllegalArgumentException("无效的枚举名称: " + name);
+    }
 }