qiangxuan 3 月之前
父節點
當前提交
23df0fabe3

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

@@ -29,6 +29,7 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @Description: 钢坯交班记录
@@ -45,6 +46,11 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
 
     @Autowired
     private IShiftConfigurationService shiftConfigurationService;
+
+    private static final long EXPIRE_TIME = 10; // 10 分钟
+
+    private static final TimeUnit EXPIRE_TIME_UNIT = TimeUnit.MINUTES;
+
     /**
      * 自动化交班
      * @author: jeecg-boot
@@ -53,8 +59,17 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void autoChangeShift(JSONObject jsonObj) {
-        String changeShiftTime = jsonObj.getString("changeShiftTime");
-        log.info("{}{}", "C端自动化交班请求时间:", changeShiftTime);
+
+        log.info("{}{}", "C端自动化交班请求参数:", jsonObj);
+
+        String autoChangeShiftLimitKey = String.format("autoChangeShift:execution:%s", "5");
+
+        // 检查键是否存在
+        Boolean isExecutedRecently = redisTemplate.hasKey(autoChangeShiftLimitKey);
+        if (isExecutedRecently == null || isExecutedRecently) {
+            log.info("{}{}", "5号机自动化交班10分钟内已有交班记录,执行失败!", jsonObj);
+            return;
+        }
 
         String keyShiftGroupsix = String.format("class:shift:group:%s", "5");
         String keyShiftsix = String.format("class:shift:%s", "5");
@@ -100,6 +115,8 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
         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);
 
+        // 设置键并设置过期时间
+        redisTemplate.opsForValue().set(autoChangeShiftLimitKey,"executed", EXPIRE_TIME, EXPIRE_TIME_UNIT);
         // 查询当天的交班记录
 //        LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapperCS = new LambdaQueryWrapper<>();
 //        queryWrapperCS.between(BilletHotsendChangeShift::getCreateTime, DateUtils.getStartOfDay(), DateUtils.getEndOfDay());
@@ -124,7 +141,7 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
         billetHotsendChangeShiftVo.setShiftGroup(finalNextShiftGroupVal);
         billetHotsendChangeShiftVo.setShift(finalNextShiftVal);
         JSONObject jsonObject = autoChangeShiftHandle(billetHotsendChangeShiftVo, sixShiftGroup, sixShift);
-        log.info("C端自动化交班结果:{}{}", jsonObject, DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
+        log.info("C端5号机自动化交班结果:{}{}", jsonObject, DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
     }
 
     private JSONObject autoChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo, String currentShiftGroup, String currentShift) {
@@ -223,9 +240,9 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
                     newShiftConfiguration.setCreateTime(new Date());
                     newShiftConfiguration.setDate(DateUtils.getDateWithOnlyYearMonthDay(new Date()));
                     shiftConfigurationService.save(newShiftConfiguration);
-                    log.info("{}{}", "5号生成储运配置:", JSON.toJSON(newShiftConfiguration));
+                    log.info("{}{}", "5号生成储运配置:", JSON.toJSON(newShiftConfiguration));
                 }
-                result.put("success", "自动化交班操作成功!");
+                result.put("success", "5号机自动化交班操作成功!");
             } catch (Exception e) {
                 log.error("自动化交班操作出现异常", e);
                 // 回滚缓存