initial
This commit is contained in:
73
src/main/java/com/sipai/schedule/DataSynJob.java
Normal file
73
src/main/java/com/sipai/schedule/DataSynJob.java
Normal file
@ -0,0 +1,73 @@
|
||||
package com.sipai.schedule;
|
||||
|
||||
import com.sipai.entity.scada.MPoint;
|
||||
import com.sipai.entity.scada.MPointHistory;
|
||||
import com.sipai.service.mqtt.MqttConfigService;
|
||||
import com.sipai.service.opc.InitOpcUaService;
|
||||
import com.sipai.service.scada.MPointHistoryService;
|
||||
import com.sipai.service.scada.MPointService;
|
||||
import com.sipai.tools.CommUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 定时将总表数据插入到子表
|
||||
*/
|
||||
@Service
|
||||
public class DataSynJob {
|
||||
@Autowired
|
||||
private MPointService mPointService;
|
||||
@Autowired
|
||||
private MPointHistoryService mPointHistoryService;
|
||||
@Autowired
|
||||
private MqttConfigService mqttConfigService;
|
||||
@Autowired
|
||||
private InitOpcUaService initOpcUaService;
|
||||
|
||||
//定时器yml配置是否启动
|
||||
@Value("${scheduled.enabled:true}")
|
||||
private boolean scheduledEnabled;
|
||||
|
||||
// @Scheduled(fixedRate = 3600000) // 同步一次opcua的订阅
|
||||
public void syncSubscriptions() {
|
||||
initOpcUaService.manualSyncSubscriptions();
|
||||
}
|
||||
|
||||
@Async
|
||||
@Scheduled(initialDelay = 10000, fixedRate = 600000)//自动订阅mqtt
|
||||
public void job1() {
|
||||
if (!scheduledEnabled) return; // 手动拦截
|
||||
System.out.println("自动订阅========" + CommUtil.nowDate());
|
||||
mqttConfigService.connect("1");
|
||||
}
|
||||
|
||||
@Async
|
||||
// @Scheduled(cron = "0 0/3 * * * ?")//数据转发
|
||||
public void job2() {
|
||||
if (!scheduledEnabled) return; // 手动拦截
|
||||
String addstr = "zhuanfa";
|
||||
System.out.println("开始定时器-----------------" + CommUtil.nowDate() + "-----------------" + addstr);
|
||||
List<MPoint> list2 = this.mPointService.selectListByWhere("where bizid = '0791CNWS' and SignalType='AI' and MeasureDT>DATE_SUB(NOW(), INTERVAL 5 MINUTE) and source_type='auto' ");
|
||||
if (list2 != null && list2.size() > 0) {
|
||||
for (int j = 0; j < list2.size(); ++j) {
|
||||
MPointHistory mPointHistory = new MPointHistory();
|
||||
mPointHistory.setParmvalue(list2.get(j).getParmvalue());
|
||||
mPointHistory.setMeasuredt(list2.get(j).getMeasuredt());
|
||||
mPointHistory.setTbName(list2.get(j).getMpointcode());
|
||||
mPointHistory.setUserid("data_job");
|
||||
mPointHistory.setInsdt(CommUtil.nowDate());
|
||||
mPointHistoryService.saveByCreate(list2.get(j).getBizid(), mPointHistory);
|
||||
}
|
||||
System.out.println("完成一次(有数据)转发,执行了" + list2.size() + "次点");
|
||||
} else {
|
||||
System.out.println("完成一次(无数据)转发,执行了" + 0 + "次点");
|
||||
}
|
||||
System.out.println("结束定时器-----------------" + CommUtil.nowDate());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user