Browse Source

定时任务开关

java8
常熟吴彦祖 5 months ago
parent
commit
d7d19fe385
  1. 48
      src/main/java/com/xujie/sys/common/utils/TaskUtils.java
  2. 2
      src/main/resources/application-dev.yml

48
src/main/java/com/xujie/sys/common/utils/TaskUtils.java

@ -7,6 +7,7 @@ import com.xujie.sys.modules.pms.service.Impl.QcServiceImpl;
import com.xujie.sys.modules.reader.service.GetInformationForExcelService; import com.xujie.sys.modules.reader.service.GetInformationForExcelService;
import com.xujie.sys.modules.reader.service.ModbusCommunicateService; import com.xujie.sys.modules.reader.service.ModbusCommunicateService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
@ -34,6 +35,9 @@ public class TaskUtils {
@Autowired @Autowired
private ModbusCommunicateService modbusCommunicateService; private ModbusCommunicateService modbusCommunicateService;
// 全局任务开关
@Value("${task.enabled:true}")
private boolean taskEnabled;
/** /**
@ -41,6 +45,9 @@ public class TaskUtils {
*/ */
@Scheduled(cron = "${task.data.eamWorkPlanTime}") @Scheduled(cron = "${task.data.eamWorkPlanTime}")
public void doTask() { public void doTask() {
if(!taskEnabled){
return;
}
eamService.eamWorkPlanTask(); eamService.eamWorkPlanTask();
} }
@ -49,6 +56,10 @@ public class TaskUtils {
*/ */
@Scheduled(cron = "${task.data.getExcelInformation}" ) //每五秒执行 读取文件数据 @Scheduled(cron = "${task.data.getExcelInformation}" ) //每五秒执行 读取文件数据
public void getExcel(){ public void getExcel(){
if(!taskEnabled){
return;
}
getInformationForExcelService.saveByExcel(); getInformationForExcelService.saveByExcel();
} }
@ -57,6 +68,9 @@ public class TaskUtils {
*/ */
@Scheduled(cron = "${task.data.sendEmail}" ) @Scheduled(cron = "${task.data.sendEmail}" )
public void sendEmail() throws MessagingException, UnsupportedEncodingException { public void sendEmail() throws MessagingException, UnsupportedEncodingException {
if(!taskEnabled){
return;
}
eamProjectService.sendEmail(); eamProjectService.sendEmail();
} }
@ -65,33 +79,59 @@ public class TaskUtils {
*/ */
@Scheduled(cron = "${task.data.modbusCommunicate}") @Scheduled(cron = "${task.data.modbusCommunicate}")
public void getModbus(){ public void getModbus(){
if(!taskEnabled){
return;
}
modbusCommunicateService.getInfoByModbus(); modbusCommunicateService.getInfoByModbus();
} }
@Scheduled(cron = "${task.data.readPerSecond}") @Scheduled(cron = "${task.data.readPerSecond}")
public void readPerSecond(){ public void readPerSecond(){
if(!taskEnabled){
return;
}
modbusCommunicateService.readPerSecond(); modbusCommunicateService.readPerSecond();
} }
@Scheduled(cron = "${loraurl.getLoraWatchTime}") @Scheduled(cron = "${loraurl.getLoraWatchTime}")
//@Scheduled(cron = "0/30 * * * * ?") //@Scheduled(cron = "0/30 * * * * ?")
public void getLoraWatchMessage(){eamService.getLoraWatch();};
public void getLoraWatchMessage(){
if(!taskEnabled){
return;
}
eamService.getLoraWatch();};
//@Scheduled(cron = "${loraurl.sendLoraWatchTime}") //@Scheduled(cron = "${loraurl.sendLoraWatchTime}")
public void sendLoraWatchMessage(){eamService.sendLoraWatch();};
public void sendLoraWatchMessage(){
if(!taskEnabled){
return;
}
eamService.sendLoraWatch();};
//@Scheduled(cron = "${loraurl.sendThreeColourTime}") //@Scheduled(cron = "${loraurl.sendThreeColourTime}")
public void sendThreeColourLight(){eamService.sendThreeColourLight();};
public void sendThreeColourLight(){
if(!taskEnabled){
return;
}
eamService.sendThreeColourLight();};
@Scheduled(cron = "${loraurl.sendRedColourTime}") @Scheduled(cron = "${loraurl.sendRedColourTime}")
//@Scheduled(cron = "0/10 * * * * ?") //@Scheduled(cron = "0/10 * * * * ?")
public void sendLoraRedLight(){eamService.sendLoraRedLight();}
public void sendLoraRedLight(){
if(!taskEnabled){
return;
}
eamService.sendLoraRedLight();}
/** /**
* 创建质量任务 * 创建质量任务
*/ */
@Scheduled(cron = "${task.data.createQCInspection}") @Scheduled(cron = "${task.data.createQCInspection}")
public void createQCInspection() { public void createQCInspection() {
if(!taskEnabled){
return;
}
qcService.createQCInspection(); qcService.createQCInspection();
} }

2
src/main/resources/application-dev.yml

@ -6,6 +6,7 @@ spring:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
#url: jdbc:sqlserver://192.168.1.90:1433;databaseName=CKT_MES_II_REAL #url: jdbc:sqlserver://192.168.1.90:1433;databaseName=CKT_MES_II_REAL
url: jdbc:sqlserver://xujiesoft.vicp.net:11515;databaseName=CKT_MES_II_REAL url: jdbc:sqlserver://xujiesoft.vicp.net:11515;databaseName=CKT_MES_II_REAL
# url: jdbc:sqlserver://xujiesoft.vicp.net:11515;databaseName=ckp-srm
username: sa username: sa
password: XJsoft123 password: XJsoft123
initial-size: 10 initial-size: 10
@ -50,6 +51,7 @@ task:
readPerSecond: 0 0 0 * * ? #每天执行一次 readPerSecond: 0 0 0 * * ? #每天执行一次
sendEmail: 0 0 12 ? * MON-FRI #发送邮件 sendEmail: 0 0 12 ? * MON-FRI #发送邮件
createQCInspection: 0 01 17 * * ? # 创建质量任务 createQCInspection: 0 01 17 * * ? # 创建质量任务
enabled: false
#--------------------------------------------接口地址和开关控制------------------------------------------------- #--------------------------------------------接口地址和开关控制-------------------------------------------------

Loading…
Cancel
Save