浏览代码

交班逻辑调整

qiangxuan 3 天之前
父节点
当前提交
bfa59ca36b

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

@@ -69,24 +69,24 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 
 	@ApiOperation(value="5号机自动化交班测试", notes="5号机自动化交班测试")
 	@GetMapping(value = "/autoByCcmNoFive")
-	public Result<String> autoByCcmNoFive(@RequestParam(name="ccmNo", required = false) String ccmNo,
-										 @RequestParam(name="nextId", required = false) Integer nextId,
-										 @RequestParam(name="shift", required = false) String shift,
-										 @RequestParam(name="shiftGroup", required = false) String shiftGroup) {
+	public Result<String> autoByCcmNoFive(@RequestParam(name="changeShiftTime", required = true) String changeShiftTime,
+										  @RequestParam(name="ban", required = true) Integer ban) {
 		JSONObject jsonObject = new JSONObject();
-		jsonObject.put("changeShiftTime", "2025-04-25 10:21:52");
+		jsonObject.put("changeShiftTime", changeShiftTime);
+		jsonObject.put("ban", ban);
+		log.info("{}{}", "5号机交班参数信息:" ,jsonObject);
 		billetHotsendChangeShiftService.autoChangeShift(jsonObject);
 		return Result.OK(null);
 	}
 
 	@ApiOperation(value="6号机自动化交班测试", notes="6号机自动化交班测试")
 	@GetMapping(value = "/autoByCcmNoSix")
-	public Result<String> autoByCcmNoSix(@RequestParam(name="ccmNo", required = false) String ccmNo,
-									  @RequestParam(name="nextId", required = false) Integer nextId,
-									  @RequestParam(name="shift", required = false) String shift,
-									  @RequestParam(name="shiftGroup", required = false) String shiftGroup) {
+	public Result<String> autoByCcmNoSix(@RequestParam(name="changeShiftTime", required = true) String changeShiftTime,
+										 @RequestParam(name="ban", required = true) Integer ban) {
 		JSONObject jsonObject = new JSONObject();
-		jsonObject.put("changeShiftTime", "2025-04-25 10:21:52");
+		jsonObject.put("changeShiftTime", changeShiftTime);
+		jsonObject.put("ban", ban);
+		log.info("{}{}", "6号机交班参数信息:" ,jsonObject);
 		billetHotsendChangeShiftService.autoChangeShiftSix(jsonObject);
 		return Result.OK(null);
 	}

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

@@ -4,18 +4,14 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.billetActual.entity.BilletHotsendChangeShift;
 import org.jeecg.modules.billetActual.mapper.BilletHotsendChangeShiftMapper;
-import org.jeecg.modules.billetActual.service.IBilletBasicInfoService;
 import org.jeecg.modules.billetActual.service.IBilletHotsendChangeShiftService;
 import org.jeecg.modules.billetActual.util.ScheduleUtils;
-import org.jeecg.modules.billetActual.util.ShiftInfo;
-import org.jeecg.modules.operateLog.service.IOperateLogService;
 import org.jeecg.modules.shiftConfiguration.entity.ShiftConfiguration;
 import org.jeecg.modules.shiftConfiguration.service.IShiftConfigurationService;
 import org.jeecg.modules.storageBill.entity.ShiftEnum;
@@ -25,9 +21,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Arrays;
 import java.util.Date;
-import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
@@ -74,31 +68,9 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
         String keyShiftGroupsix = String.format("class:shift:group:%s", "5");
         String keyShiftsix = String.format("class:shift:%s", "5");
 
-        String sixShiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftGroupsix));
-        String sixShift = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftsix));
+        String currentShiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftGroupsix));
+        String currentShift = 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");
-        String currentCacheId = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
-
-        log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 5号机C端自动化当前班次信息值:" + sixShift+ ","+ sixShiftGroup);
-        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 丁"
-        };
-
-        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 之间
@@ -113,53 +85,33 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
             return;
         }
         // 班组名(甲乙丙丁)
-        String nextShiftGroupName =  nextShiftGroupInfo.getShift();
+        int nextShiftGroupVal = jsonObj.getInteger("ban");
         // 班组值
-        String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftGroupName);
+        String finalNextShiftGroupVal = String.valueOf(nextShiftGroupVal - 1);
         // 班别值
         String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftName + "班");
 
-        int nextUniqueShiftId = nextShiftGroupInfo.getId();
-
-        redisTemplate.opsForValue().set(nextshiftIdKey, nextUniqueShiftId);
 
         log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 5号机C端自动化下一个班次信息值:" + finalNextShiftVal + ","+ finalNextShiftGroupVal);
-        log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 5号机C端自动化下一个班次信息名:" + nextUniqueShiftId + "," + nextShiftGroupName + ","+ nextShiftName);
+        log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 5号机C端自动化下一个班次信息名:" + "," +  ShiftGroupEnum.fromCode(finalNextShiftGroupVal).name() + "," + nextShiftName +  "班");
 
         // 设置键并设置过期时间
         redisTemplate.opsForValue().set(autoChangeShiftLimitKey,"executed", EXPIRE_TIME, EXPIRE_TIME_UNIT);
-        // 查询当天的交班记录
-//        LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapperCS = new LambdaQueryWrapper<>();
-//        queryWrapperCS.between(BilletHotsendChangeShift::getCreateTime, DateUtils.getStartOfDay(), DateUtils.getEndOfDay());
-//        List<BilletHotsendChangeShift> billetHotsendChangeShiftList = baseMapper.selectList(queryWrapperCS);
-//
-//        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(nextShiftAndShiftGroupInfo));
-//            if (exists) {
-//                log.info("C端自动化交班,当天不能重复交班! {}", new Date());
-//                // 自动交班失败,交班ID索引值回滚,保证交班顺序
-//                String nextCacheIdRollBack = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
-//                int nextCacheIdRollBacks = Integer.parseInt(nextCacheIdRollBack);
-//                redisTemplate.opsForValue().set(nextshiftIdKey, nextCacheIdRollBacks - 1);
-//                return;
-//            }
-//        }
+
+        String changeShiftTime = jsonObj.getString("changeShiftTime");
+
         BilletHotsendChangeShift billetHotsendChangeShiftVo = new BilletHotsendChangeShift();
         billetHotsendChangeShiftVo.setCcmNo("5");
         billetHotsendChangeShiftVo.setShiftGroup(finalNextShiftGroupVal);
         billetHotsendChangeShiftVo.setShift(finalNextShiftVal);
-        JSONObject jsonObject = autoChangeShiftHandle(billetHotsendChangeShiftVo, sixShiftGroup, sixShift);
+        JSONObject jsonObject = autoChangeShiftHandle(billetHotsendChangeShiftVo, currentShiftGroup, currentShift, changeShiftTime);
         log.info("5号机C端自动化交班结果:{}{}", jsonObject, DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
     }
 
     @Override
     public void autoChangeShiftSix(JSONObject jsonObj) {
 
-        log.info("{}{}", "C端6号机自动化交班请求参数:", jsonObj);
+        log.info("{}{}", "6号机C端自动化交班请求参数:", jsonObj);
 
         String autoChangeShiftLimitKey = String.format("autoChangeShift:execution:%s", "6");
 
@@ -173,33 +125,10 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
         String keyShiftGroupsix = String.format("class:shift:group:%s", "6");
         String keyShiftsix = String.format("class:shift:%s", "6");
 
-        String sixShiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftGroupsix));
-        String sixShift = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftsix));
+        String currentShiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftGroupsix));
+        String currentShift = 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", "6");
-        String currentCacheId = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
-
-        log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 6号机C端自动化当前班次信息值:" + sixShift+ ","+ sixShiftGroup);
-        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 丁"
-        };
-
-        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 nextShiftName  = "";
         // 验证23:00 到01:00 之间
         if (ScheduleUtils.isBetweenTime(new Date(), "07:40", "08:30")) {
@@ -212,35 +141,33 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
             log.info("{}{}", "未在交班范围内,", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + "6号机C端自动化交班失败!");
             return;
         }
-        // 班组名
-        String nextShiftGroupName =  nextShiftGroupInfo.getShift();
+        // 班组名(甲乙丙丁)
+        int nextShiftGroupVal = jsonObj.getInteger("ban");
         // 班组值
-        String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftGroupName);
+        String finalNextShiftGroupVal = String.valueOf(nextShiftGroupVal - 1);
         // 班别值
         String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftName + "班");
 
-        int nextUniqueShiftId = nextShiftGroupInfo.getId();
-
-        redisTemplate.opsForValue().set(nextshiftIdKey, nextUniqueShiftId);
-
         log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 6号机C端自动化下一个班次信息值:" + finalNextShiftVal + ","+ finalNextShiftGroupVal);
-        log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 6号机C端自动化下一个班次信息名:" + nextUniqueShiftId + "," + nextShiftGroupName + ","+ nextShiftName);
+        log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 6号机C端自动化下一个班次信息名:" + "," +  ShiftGroupEnum.fromCode(finalNextShiftGroupVal).name() + "," + nextShiftName +  "班");
 
         // 设置键并设置过期时间
         redisTemplate.opsForValue().set(autoChangeShiftLimitKey,"executed", EXPIRE_TIME, EXPIRE_TIME_UNIT);
+
+        String changeShiftTime = jsonObj.getString("changeShiftTime");
         BilletHotsendChangeShift billetHotsendChangeShiftVo = new BilletHotsendChangeShift();
         billetHotsendChangeShiftVo.setCcmNo("6");
         billetHotsendChangeShiftVo.setShiftGroup(finalNextShiftGroupVal);
         billetHotsendChangeShiftVo.setShift(finalNextShiftVal);
-        JSONObject jsonObject = autoSixChangeShiftHandle(billetHotsendChangeShiftVo, sixShiftGroup, sixShift);
+        JSONObject jsonObject = autoSixChangeShiftHandle(billetHotsendChangeShiftVo, currentShiftGroup, currentShift, changeShiftTime);
         log.info("6号机C端自动化交班结果:{}{}", jsonObject, DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
     }
 
-    private JSONObject autoSixChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo, String currentShiftGroup, String currentShift) {
+    private JSONObject autoSixChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo, String currentShiftGroup, String currentShift, String changeShiftTime) {
         JSONObject result = new JSONObject();
         // 缓存交班索引ID
         String ccmNo = billetHotsendChangeShiftVo.getCcmNo();
-        String nextshiftIdKey = String.format("class:nextshift:Id:%s", ccmNo);
+
         String keyShiftGroup = String.format("class:shift:group:%s", ccmNo);
         String keyShift = String.format("class:shift:%s", ccmNo);
         // 保存旧的缓存值,用于异常回滚
@@ -262,17 +189,13 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
                     .last("limit 1"));
             if (oConvertUtils.isEmpty(billetHotsendChangeShift)) {
                 result.put("fail", "当班信息查询为空,6号机自动化交班操作失败!");
-                // 自动交班失败,交班ID索引值回滚,保证交班顺序
-                String nextCacheIdRollBack = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
-                int nextCacheIdRollBacks = Integer.parseInt(nextCacheIdRollBack);
-                redisTemplate.opsForValue().set(nextshiftIdKey, nextCacheIdRollBacks - 1);
                 // 班组班别回滚
                 redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
                 redisTemplate.opsForValue().set(keyShift, oldShift);
                 return result;
             }
             // 更新当前班次的交班时间,相当于上一个班交班的结束时间
-            billetHotsendChangeShift.setChangeShiftTime(new Date());
+            billetHotsendChangeShift.setChangeShiftTime(DateUtils.str2Date(changeShiftTime, DateUtils.datetimeFormat.get()));
             billetHotsendChangeShift.setUpdateTime(new Date());
             baseMapper.updateById(billetHotsendChangeShift);
 
@@ -342,10 +265,6 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
                 redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
                 redisTemplate.opsForValue().set(keyShift, oldShift);
             }
-            // 自动交班失败,交班ID索引值回滚,保证交班顺序
-            String nextCacheIdRollBack = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
-            int nextCacheIdRollBacks = Integer.parseInt(nextCacheIdRollBack);
-            redisTemplate.opsForValue().set(nextshiftIdKey, nextCacheIdRollBacks - 1);
             result.put("fail", "6号机自动化交班操作失败,出现异常!");
         }
         return result;
@@ -358,20 +277,13 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
      * @param currentShift
      * @return
      */
-    private JSONObject autoChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo, String currentShiftGroup, String currentShift) {
+    private JSONObject autoChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo, String currentShiftGroup, String currentShift, String changeShiftTime) {
         JSONObject result = new JSONObject();
         // 缓存交班索引ID
         String ccmNo = billetHotsendChangeShiftVo.getCcmNo();
-        String nextshiftIdKey = String.format("class:nextshift:Id:%s", ccmNo);
         String keyShiftGroup = String.format("class:shift:group:%s", ccmNo);
         String keyShift = String.format("class:shift:%s", ccmNo);
-        // 保存旧的缓存值,用于异常回滚
-        String oldShiftGroup = Optional.ofNullable(redisTemplate.opsForValue().get(keyShiftGroup))
-                .map(Object::toString)
-                .orElse(null);
-        String oldShift = Optional.ofNullable(redisTemplate.opsForValue().get(keyShift))
-                .map(Object::toString)
-                .orElse(null);
+
         try {
             // 先更新班组班别缓存
             redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
@@ -384,17 +296,13 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
                     .last("limit 1"));
             if (oConvertUtils.isEmpty(billetHotsendChangeShift)) {
                 result.put("fail", "当班信息查询为空,5号机自动化交班操作失败!");
-                // 自动交班失败,交班ID索引值回滚,保证交班顺序
-                String nextCacheIdRollBack = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
-                int nextCacheIdRollBacks = Integer.parseInt(nextCacheIdRollBack);
-                redisTemplate.opsForValue().set(nextshiftIdKey, nextCacheIdRollBacks - 1);
                 // 班组班别回滚
-                redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
-                redisTemplate.opsForValue().set(keyShift, oldShift);
+                redisTemplate.opsForValue().set(keyShiftGroup, currentShiftGroup);
+                redisTemplate.opsForValue().set(keyShift, currentShift);
                 return result;
             }
             // 更新当前班次的交班时间,相当于上一个班交班的结束时间
-            billetHotsendChangeShift.setChangeShiftTime(new Date());
+            billetHotsendChangeShift.setChangeShiftTime(DateUtils.str2Date(changeShiftTime, DateUtils.datetimeFormat.get()));
             billetHotsendChangeShift.setUpdateTime(new Date());
             baseMapper.updateById(billetHotsendChangeShift);
 
@@ -460,14 +368,10 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
         } catch (Exception e) {
             log.error("5号机自动化交班操作出现异常", e);
             // 回滚缓存
-            if (oldShiftGroup != null && oldShift != null) {
-                redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
-                redisTemplate.opsForValue().set(keyShift, oldShift);
+            if (currentShiftGroup != null && currentShift != null) {
+                redisTemplate.opsForValue().set(keyShiftGroup, currentShiftGroup);
+                redisTemplate.opsForValue().set(keyShift, currentShift);
             }
-            // 自动交班失败,交班ID索引值回滚,保证交班顺序
-            String nextCacheIdRollBack = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
-            int nextCacheIdRollBacks = Integer.parseInt(nextCacheIdRollBack);
-            redisTemplate.opsForValue().set(nextshiftIdKey, nextCacheIdRollBacks - 1);
             result.put("fail", "5号机自动化交班操作失败,出现异常!");
         }
         return result;