From 612127d7830372cda153b4af4a41c5e3b9f7e4f0 Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期四, 29 八月 2024 18:28:32 +0800
Subject: [PATCH] update job scheduler
---
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java | 8 ++++
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/DynamicSchedulingConfig.java | 14 ++++---
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java | 50 +++++++++++++++++++++++++
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java | 3 +
4 files changed, 69 insertions(+), 6 deletions(-)
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/DynamicSchedulingConfig.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/DynamicSchedulingConfig.java
index 0c5d10c..1eccc87 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/DynamicSchedulingConfig.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/DynamicSchedulingConfig.java
@@ -7,6 +7,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.CronTask;
+import org.springframework.scheduling.config.ScheduledTask;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import javax.annotation.Resource;
@@ -46,20 +48,20 @@
LocalTime roomResetTime = Utils.parseTime(strRoomResetTime);
String roomResetCronExpression = String.format("0 %d %d * * ?", roomResetTime.getMinute(), roomResetTime.getHour());
- taskRegistrar.addCronTask(() -> {
+ taskRegistrar.scheduleCronTask(new CronTask(() -> {
System.out.println("Opening Task executed at: " + System.currentTimeMillis());
queueService.startBiz();
- }, openCronExpression);
+ }, openCronExpression));
- taskRegistrar.addCronTask(() -> {
+ taskRegistrar.scheduleCronTask(new CronTask(() -> {
System.out.println("Close Task executed at: " + System.currentTimeMillis());
queueService.closeBiz();
- }, closeCronExpression);
+ }, closeCronExpression));
- taskRegistrar.addCronTask(() -> {
+ taskRegistrar.scheduleCronTask(new CronTask(() -> {
System.out.println("Room Reset Task executed at: " + System.currentTimeMillis());
roomService.resetRoom();
- }, roomResetCronExpression);
+ }, roomResetCronExpression));
}
}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java
index 1dd64b2..bd0b7c6 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java
@@ -3,6 +3,7 @@
import cn.lihu.jh.framework.common.exception.ErrorCode;
import cn.lihu.jh.framework.security.core.util.SecurityFrameworkUtils;
import cn.lihu.jh.module.ecg.controller.admin.room.vo.RoomRespVO;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -230,4 +231,11 @@
return success("success");
}
+ @GetMapping("/reset-scheduler")
+ @Operation(summary = "閲嶇疆璋冨害鍣�")
+ @PreAuthorize("@ss.hasPermission('ecg:queue:setting')")
+ public CommonResult<Integer> resetScheduler() {
+ queueService.resetScheduler();
+ return success(0);
+ }
}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java
index ab66002..7bae87b 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java
@@ -1,5 +1,6 @@
package cn.lihu.jh.module.ecg.service.queue;
+import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
@@ -9,6 +10,7 @@
import cn.lihu.jh.module.ecg.controller.admin.room.vo.RoomRespVO;
import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO;
import cn.lihu.jh.framework.common.pojo.PageResult;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
/**
* 鎺掗槦 Service 鎺ュ彛
@@ -20,6 +22,7 @@
void setQueueReadyMax(Integer max);
void startBiz();
void closeBiz();
+ void resetScheduler();
/**
* 鍒涘缓鎺掗槦
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java
index ae4fdb7..ef629f5 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java
@@ -1,11 +1,17 @@
package cn.lihu.jh.module.ecg.service.queue;
+import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Resource;
+import cn.lihu.jh.module.ecg.Utils;
import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO;
+import cn.lihu.jh.module.ecg.service.room.RoomService;
+import org.springframework.scheduling.config.CronTask;
+import org.springframework.scheduling.config.ScheduledTask;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -28,6 +34,8 @@
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.lihu.jh.framework.common.pojo.CommonResult.error;
import static cn.lihu.jh.framework.common.pojo.CommonResult.success;
+import static cn.lihu.jh.module.ecg.Constants.ECG_OPENING_TIME_KEY;
+import static cn.lihu.jh.module.ecg.Constants.ECG_ROOM_RESET_TIME_KEY;
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
/**
@@ -41,6 +49,16 @@
@Resource
private ConfigApi configApi;
+
+ @Resource
+ private ScheduledTaskRegistrar taskRegistrar;
+
+ @Resource
+ private QueueService queueService;
+
+ @Resource
+ private RoomService roomService;
+
@Resource
private queueMapper queueMapper;
@@ -563,6 +581,38 @@
}
@Override
+ public void resetScheduler() {
+ Set<ScheduledTask> taskList = taskRegistrar.getScheduledTasks();
+ taskList.forEach((task)->task.cancel());
+
+ String strOpenCloseTime = configApi.getConfigValueByKey(ECG_OPENING_TIME_KEY);
+ List<LocalTime> list = Utils.parseOpeningTime(strOpenCloseTime);
+ LocalTime openingTime = list.get(0);
+ LocalTime closeTime = list.get(1);
+ String openCronExpression = String.format("0 %d %d * * ?", openingTime.getMinute(), openingTime.getHour());
+ String closeCronExpression = String.format("0 %d %d * * ?", closeTime.getMinute(), closeTime.getHour());
+
+ String strRoomResetTime = configApi.getConfigValueByKey(ECG_ROOM_RESET_TIME_KEY);
+ LocalTime roomResetTime = Utils.parseTime(strRoomResetTime);
+ String roomResetCronExpression = String.format("0 %d %d * * ?", roomResetTime.getMinute(), roomResetTime.getHour());
+
+ taskRegistrar.scheduleCronTask(new CronTask(() -> {
+ System.out.println("Opening Task executed at: " + System.currentTimeMillis());
+ queueService.startBiz();
+ }, openCronExpression));
+
+ taskRegistrar.scheduleCronTask(new CronTask(() -> {
+ System.out.println("Close Task executed at: " + System.currentTimeMillis());
+ queueService.closeBiz();
+ }, closeCronExpression));
+
+ taskRegistrar.scheduleCronTask(new CronTask(() -> {
+ System.out.println("Room Reset Task executed at: " + System.currentTimeMillis());
+ roomService.resetRoom();
+ }, roomResetCronExpression));
+ }
+
+ @Override
public Integer recallPatient(Long roomId, String bedNo, String patId) {
Integer updateNum = queueMapper.recallPassedPatient(roomId, bedNo, patId,
QueueStatusEnum.PASSED.getStatus(), QueueStatusEnum.PASSED_RETURN.getStatus());
--
Gitblit v1.9.3