Browse Source

巡检定时优化

guarantee-lsq 2 years ago
parent
commit
f481b516f9

+ 5 - 0
platform-common/src/main/java/com/platform/common/util/DateUtils.java

@@ -45,6 +45,11 @@ public class DateUtils {
         return monday;
     }
 
+    public static int getCurrentHour() {
+        LocalDateTime now = LocalDateTime.now();
+        return now.getHour();
+    }
+
     /**
      * 得到本周周日:23:59:59
      *

+ 38 - 3
platform-rest/src/main/java/com/platform/rest/task/FillGatherTaskTask.java

@@ -61,12 +61,41 @@ public class FillGatherTaskTask {
         // 生成巡检任务
         for(FillGatherTask task : handleList){
             FillGatherTask newTask = BeanConverterUtil.copyObjectProperties(task,FillGatherTask.class);
-            newTask.setCreatedTime(LocalDateTime.now());
             newTask.setId(IdGeneratorUtils.getObjectId());
             newTask.setStatus(FillGatherTaskStatusEnum.PROCESSING.getValue());
             newTask.setWaitNum(task.getTotalNum());
-            newTask.setName(task.getName() + "_" + nowDateStr);
+            String originName = task.getName().split("_")[0];
+            newTask.setName(originName + "_" + nowDateStr);
             newTask.setLateHistoryHours(0);
+            // 巡检开始时间
+            int period = newTask.getPeriod();
+            int currentHour = DateUtils.getCurrentHour();
+            LocalDateTime startTime = null;
+            int diffHour = 0; // 当前时间距离巡检时间间隔小时
+            if(period <= 12){
+                // 12小时周期的,21点之后到次日的8点,任务开始时间T+1 早上八点
+                if(currentHour >= 0 && currentHour <= 8){ // 当日八点
+                    startTime = LocalDateTime.now().withHour(8);
+                    diffHour = 8-currentHour;
+                }else if(currentHour > 21){
+                    startTime = LocalDateTime.now().plusDays(1).withHour(8);
+                    diffHour = 24-currentHour + 8;
+                }else{
+                    startTime = LocalDateTime.now();
+                }
+            }else{
+                // 24小时制的,晚上六点之后到第二天八点,统一到明日八点
+                if(currentHour >= 0 && currentHour <= 8){
+                    startTime = LocalDateTime.now().withHour(8);
+                    diffHour = 8-currentHour;
+                }else if(currentHour > 17){
+                    startTime = LocalDateTime.now().plusDays(1).withHour(8);
+                    diffHour = 24-currentHour + 8;
+                }else{
+                    startTime = LocalDateTime.now();
+                }
+            }
+            newTask.setCreatedTime(startTime); // 巡检开始时间
             fillGatherTaskService.saveModelNoId(newTask);
             // 老旧巡检任务,修改为已生成
             FillGatherTask updTask = new FillGatherTask();
@@ -81,12 +110,18 @@ public class FillGatherTaskTask {
             sendMessageToChecker(newTask,1);
             sendMessageToChecker(newTask,2);
             // 4、启动超时监控预警信息
-            int initMin = newTask.getRequireHour()*60;
+            int initMin = newTask.getRequireHour()*60 + diffHour*60;
             int hours = newTask.getWarningHour() == null ? initMin + 120 : newTask.getWarningHour()*60 + initMin;
             RedisUtils.setString(RedisKeyConstants.EXPIRE_BUSINESS_KEY_FILL_PREFIX + RedisKeyConstants.EXPIRE_BUSINESS_SEP + task.getId(), task.getId(), hours, TimeUnit.MINUTES);
         }
     }
 
+    public static void main(String[] args) {
+        String name = "甲三巡检_2023-02-23_2023-02-24_2023-02-24_2023-02-25";
+        String[] arr = name.split("_");
+        System.out.println(LocalDateTime.now().plusDays(1).withHour(8));
+    }
+
     private void saveDetails(String content,String newTaskId,String taskId){
         List<FillGatherTaskDetail> details = new ArrayList<>();
         FillGatherTaskDetail queryDetail = new FillGatherTaskDetail();

+ 3 - 4
platform-service/src/main/java/com/platform/service/store/impl/OutStoreFormServiceImpl.java

@@ -131,12 +131,11 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
     @Override
     public OutStoreFormVO getDetail(Object id) {
         OutStoreForm outStoreForm = this.getModelById(id);
-        RepairApplicationForm form = new RepairApplicationForm();
-        form.setId(outStoreForm.getPickId());
-
         OutStoreFormVO outStoreFormVO = new OutStoreFormVO();
         BeanConverterUtil.copyObjectProperties(outStoreForm, outStoreFormVO);
-        outStoreFormVO.setRepairNo(repairApplicationFormMapper.selectOne(form).getNo());
+        if(StringUtils.isNotBlank(outStoreForm.getPickId())){
+            outStoreFormVO.setRepairNo(repairApplicationFormMapper.selectByPrimaryKey(outStoreForm.getPickId()).getNo());
+        }
         // 详情列表
       /*  if (StringUtils.isNotBlank(outStoreForm.getStoreId())) {
             Store store = storeService.getModelById(outStoreForm.getStoreId());