eight
2024-08-29 612127d7830372cda153b4af4a41c5e3b9f7e4f0
update  job scheduler
已修改4个文件
75 ■■■■■ 文件已修改
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/config/DynamicSchedulingConfig.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/queue/queueController.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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));
    }
}
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);
    }
}
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();
    /**
     * 创建排队
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());