75 lines
3.0 KiB
Java
75 lines
3.0 KiB
Java
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 0/1 * * ?")//数据转发
|
|
public void job2() {
|
|
if (!scheduledEnabled) return; // 手动拦截
|
|
String addstr = "zhuanfa";
|
|
System.out.println("开始定时器-----------------" + CommUtil.nowDate() + "-----------------" + addstr);
|
|
// List<MPoint> list2 = this.mPointService.selectListByWhere("where bizid = '0533JS' and SignalType='AI' and MeasureDT>DATE_SUB(NOW(), INTERVAL 5 MINUTE) and source_type='auto' ");
|
|
List<MPoint> list2 = this.mPointService.selectListByWhere("where bizid = '0533JS' and SignalType='AI' and source_type='auto' ");
|
|
if (list2 != null && !list2.isEmpty()) {
|
|
for (MPoint mPoint : list2) {
|
|
MPointHistory mPointHistory = new MPointHistory();
|
|
mPointHistory.setParmvalue(mPoint.getParmvalue());
|
|
mPointHistory.setMeasuredt(mPoint.getMeasuredt());
|
|
mPointHistory.setTbName(mPoint.getMpointcode());
|
|
mPointHistory.setUserid("data_job");
|
|
mPointHistory.setInsdt(new Date());
|
|
mPointHistoryService.saveByCreate(mPoint.getBizid(), mPointHistory);
|
|
}
|
|
System.out.println("完成一次(有数据)转发,执行了" + list2.size() + "次点");
|
|
} else {
|
|
System.out.println("完成一次(无数据)转发,执行了" + 0 + "次点");
|
|
}
|
|
System.out.println("结束定时器-----------------" + CommUtil.nowDate());
|
|
}
|
|
|
|
}
|