修改任务调度为动态

master
zengwh 5 years ago
parent 729eede60e
commit 569e5370f2

@ -1,11 +1,5 @@
package com.emr.config;
import com.emr.dao.EmrOvertimeSetMapper;
import com.emr.dao.Emr_Commom_SetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @ProjectName:
* @Description:
@ -18,7 +12,7 @@ import org.springframework.context.annotation.Configuration;
* @UpdateRemark:
* @Version: 1.0
*/
@Configuration
/*@Configuration
public class CronValueConfig {
@Autowired
private EmrOvertimeSetMapper overtimeSetMapper;
@ -28,4 +22,4 @@ public class CronValueConfig {
String remindTime = overtimeSetMapper.selectByPrimaryKey(1).getRemindTime();
return remindTime;
}
}
}*/

@ -0,0 +1,18 @@
package com.emr.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/**
* 线
* @author
* @date 20190127
*/
@Configuration
public class ScheduleConfig {
@Bean
public ThreadPoolTaskScheduler threadPoolTaskScheduler(){
return new ThreadPoolTaskScheduler();
}
}

@ -1,8 +1,9 @@
package com.emr.controller;
import com.emr.util.PropertiesUtils;
import org.apache.cxf.endpoint.Client;
import org.springframework.beans.factory.annotation.Value;
import com.emr.dao.EmrOvertimeSetMapper;
import com.emr.entity.EmrOvertimeSet;
import com.emr.quart.DynamicScheduleTaskSecond;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@ -21,10 +22,16 @@ import javax.annotation.PostConstruct;
*/
@Component
public class WebServiceLoad {
@Autowired
private DynamicScheduleTaskSecond dynamicScheduleTaskSecond;
@Autowired
private EmrOvertimeSetMapper overtimeSetMapper;
@PostConstruct
public void contextInitialized() {
/*new Thread(() -> {
String token = "ORsaVDUBE1RFRFRETE5BR05ERVQ3JyBURkRGRA==";
new Thread(() -> {
EmrOvertimeSet emrOvertimeSet = overtimeSetMapper.selectByPrimaryKey(1);
dynamicScheduleTaskSecond.setCron(emrOvertimeSet.getRemindTime());
/*String token = "ORsaVDUBE1RFRFRETE5BR05ERVQ3JyBURkRGRA==";
String POWER_IP = PropertiesUtils.getProperty("POWER_IP");
String POWER_PORT = PropertiesUtils.getProperty("POWER_PORT");
//创建连接工厂
@ -41,7 +48,7 @@ public class WebServiceLoad {
if(null != client) {
client.destroy();
}
}
}).start();*/
}*/
}).start();
}
}

@ -0,0 +1,52 @@
package com.emr.quart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.concurrent.ScheduledFuture;
@Component
public class DynamicScheduleTaskSecond {
@Autowired
private ThreadPoolTaskScheduler threadPoolTaskScheduler;
@Autowired
private Task1 scheduleExport;
private ScheduledFuture<?> future;
public void setCron(String cron) {
stopCron();
future = threadPoolTaskScheduler.schedule(new Runnable() {
@Override
public void run() {
try {
scheduleExport.task1();// 执行任务
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Trigger() {
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
if ("".equals(cron) || cron == null) {
return null;
}
CronTrigger trigger = new CronTrigger(cron);// 定时任务触发,可修改定时任务的执行周期
Date nextExecDate = trigger.nextExecutionTime(triggerContext);
return nextExecDate;
}
});
}
public void stopCron() {
if (future != null) {
future.cancel(true);//取消任务调度
}
}
}

@ -19,7 +19,6 @@ import org.apache.log4j.Logger;
import org.apache.shiro.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
@ -56,7 +55,7 @@ public class Task1 {
private CommomService commomService;
@Autowired
private ArchiveRemindDeptUserInfoMapper remindDeptUserInfoMapper;
@Scheduled(cron="#{@getCronValue}")
//@Scheduled(cron="#{@getCronValue}")
public void task1(){
try {
long start = System.currentTimeMillis();

@ -8,6 +8,7 @@ import com.emr.entity.ArchiveRemindDeptUser;
import com.emr.entity.ArchiveRemindcancleDept;
import com.emr.entity.EmrOvertimeSet;
import com.emr.entity.Emr_Dictionary;
import com.emr.quart.DynamicScheduleTaskSecond;
import com.emr.service.Emr_DictionaryService;
import com.emr.vo.CommomTree;
import com.emr.vo.User;
@ -17,7 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
/**
* @ProjectName:
@ -46,6 +48,8 @@ public class EmrOvertimeSetService {
private ArchiveRemindDeptUserMapper remindDeptUserMapper;
@Autowired
private CommomService commomService;
@Autowired
private DynamicScheduleTaskSecond dynamicScheduleTaskSecond;
/**
*
* @return
@ -60,6 +64,8 @@ public class EmrOvertimeSetService {
*/
public void updateOverTimeSet(EmrOvertimeSet overtimeSet){
overtimeSetMapper.updateByPrimaryKeySelective(overtimeSet);
//重新执行任务
dynamicScheduleTaskSecond.setCron(overtimeSet.getRemindTime());
}
/**

@ -1,9 +1,9 @@
#power\u6743\u9650\u7CFB\u7EDFIP\u548C\u7AEF\u53E3
POWER_IP = localhost
POWER_PORT = 8080
#POWER_IP = localhost
#POWER_PORT = 8080
#POWER_IP = 200.100.104.40
#POWER_PORT = 8081
POWER_IP = 200.100.104.40
POWER_PORT = 8081
#power\u6743\u9650\u7CFB\u7EDF\u7684\u670D\u52A1\u5668\u5730\u5740\u5934
POWER_URLHEAD = http://${POWER_IP}:${POWER_PORT}/power
@ -52,7 +52,7 @@ allAddortIds = 00000000
nurseAssortIds = 'C70E8C427A3648B79BE80798C08F4D12','85DAE73A87D047D28C222E878C78C670'
#\u7528\u4E8E\u8D85\u671F\u901A\u77E5\uFF0C\u53EA\u901A\u77E5\u8BE5\u65E5\u671F\u4EE5\u540E\u7684\u51FA\u9662\u8D85\u671F\u7684\u8BB0\u5F55
overDateSet = 2020-07-26
overDateSet = 2020-10-26
#\u5404\u5BA1\u6838\u89D2\u8272\u7528\u6237id 1\uFF1A\u533B\u751F\uFF1B2\uFF1A\u62A4\u58EB\uFF1B3\uFF1A\u75C5\u6848\u5BA4\u4EBA\u5458\uFF1B5\uFF1A\u533B\u751F\u8D28\u63A7\u5458\uFF1B6\uFF1A\u79D1\u4E3B\u4EFB\uFF1B7\uFF1A\u62A4\u58EB\u957F\uFF1B8\uFF1A\u62A4\u58EB\u8D28\u63A7\u5458

@ -1,11 +1,11 @@
jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc\:sqlserver\://localhost:1433;databaseName=gm_record
jdbc.username=sa
jdbc.password=docus702
#jdbc.url=jdbc\:sqlserver\://localhost:1433;databaseName=emr_record
#jdbc.url=jdbc\:sqlserver\://localhost:1433;databaseName=gm_record
#jdbc.username=sa
#jdbc.password=AbcXyz123
#jdbc.password=docus702
jdbc.url=jdbc\:sqlserver\://200.100.104.40:1433;databaseName=emr_record
jdbc.username=sa
jdbc.password=AbcXyz123
filters=stat
maxWait=60000

@ -354,7 +354,7 @@
</div>
<footer class="main-footer">
<div class="pull-right">
<b>Version</b> 20201030
<b>Version</b> 20201102
</div>
<strong>Copyright &copy; 2019-2090 厦门嘉时软件.</strong> All rights
reserved.

Loading…
Cancel
Save