feat: 增加i2同步定时任务并查询数据
parent
e8aa69683f
commit
6bc0d82bc0
@ -0,0 +1,85 @@
|
||||
package com.xydl.cac.task;
|
||||
|
||||
import com.xydl.cac.entity.*;
|
||||
import com.xydl.cac.repository.I2syncFieldRepository;
|
||||
import com.xydl.cac.repository.I2syncRecordRepository;
|
||||
import com.xydl.cac.repository.NSensorRepository;
|
||||
import com.xydl.cac.service.DataService;
|
||||
import com.xydl.cac.service.I2syncService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class I2syncTask {
|
||||
@Resource
|
||||
I2syncService i2syncService;
|
||||
@Resource
|
||||
I2syncFieldRepository syncFieldRepository;
|
||||
@Resource
|
||||
I2syncRecordRepository recordRepository;
|
||||
@Resource
|
||||
NSensorRepository sensorRepository;
|
||||
@Resource
|
||||
DataService dataService;
|
||||
|
||||
@Scheduled(initialDelay = 60 * 1000, fixedDelay = 3600 * 1000)
|
||||
public void syncAll() {
|
||||
List<I2syncConfig> configList = i2syncService.listConfig();
|
||||
if (!CollectionUtils.isEmpty(configList)) {
|
||||
log.info("I2syncTask.syncAll 开始.");
|
||||
try {
|
||||
for (I2syncConfig config : configList) {
|
||||
this.syncConfig(config);
|
||||
}
|
||||
log.info("I2syncTask.syncAll 结束.");
|
||||
} catch (Exception e) {
|
||||
log.error("I2syncTask.syncAll error.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 同步一个类型
|
||||
private void syncConfig(I2syncConfig config) throws Exception {
|
||||
List<I2syncField> fieldList = syncFieldRepository.findByTableName(config.getTableName());
|
||||
if (CollectionUtils.isEmpty(fieldList)) {
|
||||
return;
|
||||
}
|
||||
List<ModevTypePoint> points = new ArrayList<>();
|
||||
for (I2syncField field : fieldList) {
|
||||
ModevTypePoint point = new ModevTypePoint();
|
||||
point.setField(field.getFieldName());
|
||||
}
|
||||
List<NSensor> list = sensorRepository.findByTypeId(config.getModevtypeId());
|
||||
for (NSensor sensor : list) {
|
||||
this.syncSensor(sensor, fieldList, points);
|
||||
}
|
||||
}
|
||||
|
||||
// 同步一个装置
|
||||
private void syncSensor(NSensor sensor, List<I2syncField> fieldList, List<ModevTypePoint> points) throws Exception {
|
||||
Date start = null;
|
||||
List<I2syncRecord> recordList = recordRepository.findByEqmid(sensor.getDevId());
|
||||
if (!CollectionUtils.isEmpty(recordList)) {
|
||||
start = recordList.get(0).getLastDTime();
|
||||
}
|
||||
|
||||
// 查询最新数据
|
||||
List<Map<String, Object>> list = dataService.getLatestData(sensor, points, start);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 格式转换
|
||||
|
||||
// 同步导出
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue