|
|
|
@ -1,16 +1,19 @@
|
|
|
|
|
package com.xydl.cac.iec;
|
|
|
|
|
|
|
|
|
|
import com.beanit.iec61850bean.BasicDataAttribute;
|
|
|
|
|
import com.beanit.iec61850bean.FileInformation;
|
|
|
|
|
import com.xydl.cac.config.BizConfig;
|
|
|
|
|
import com.xydl.cac.entity.*;
|
|
|
|
|
import com.xydl.cac.repository.IcdConfigTypeAttRepository;
|
|
|
|
|
import com.xydl.cac.repository.IcdConfigTypeInstRepository;
|
|
|
|
|
import com.xydl.cac.repository.IcdConfigTypeRepository;
|
|
|
|
|
import com.xydl.cac.repository.RptparamindexRepository;
|
|
|
|
|
import com.xydl.cac.entity.constants.Constants;
|
|
|
|
|
import com.xydl.cac.repository.*;
|
|
|
|
|
import com.xydl.cac.service.DataService;
|
|
|
|
|
import com.xydl.cac.service.IedDlRecordService;
|
|
|
|
|
import com.xydl.cac.socket.WebSocketServer;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -20,27 +23,34 @@ public class IEDCollectService {
|
|
|
|
|
IcdConfigTypeAttRepository _attRepository;
|
|
|
|
|
IcdConfigTypeInstRepository _instRepository;
|
|
|
|
|
RptparamindexRepository _rptparamindexRepository;
|
|
|
|
|
IedDlRecordService _dlRecordService;
|
|
|
|
|
DataService _dataService;
|
|
|
|
|
IecClient iecClient;
|
|
|
|
|
IcdIed ied;
|
|
|
|
|
String xml;
|
|
|
|
|
WebSocketServer _webSocketServer;
|
|
|
|
|
BizConfig _bizConfig;
|
|
|
|
|
|
|
|
|
|
String folder = "/record";
|
|
|
|
|
|
|
|
|
|
public static HashMap<Integer, HashMap<String, String>> lastDataMap = new HashMap<>();
|
|
|
|
|
public static HashMap<String, String> relationMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
public IEDCollectService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository,
|
|
|
|
|
IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository,
|
|
|
|
|
DataService dataService, String xml, IcdIed ied,
|
|
|
|
|
WebSocketServer webSocketServer) {
|
|
|
|
|
IedDlRecordService dlRecordService, DataService dataService,
|
|
|
|
|
String xml, IcdIed ied,
|
|
|
|
|
WebSocketServer webSocketServer, BizConfig bizConfig) {
|
|
|
|
|
_configRepository = configRepository;
|
|
|
|
|
_attRepository = attRepository;
|
|
|
|
|
_instRepository = instRepository;
|
|
|
|
|
_rptparamindexRepository = rptparamindexRepository;
|
|
|
|
|
_dlRecordService = dlRecordService;
|
|
|
|
|
_dataService = dataService;
|
|
|
|
|
this.xml = xml;
|
|
|
|
|
this.ied = ied;
|
|
|
|
|
_webSocketServer = webSocketServer;
|
|
|
|
|
_bizConfig = bizConfig;
|
|
|
|
|
iecClient = new IecClient();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -52,7 +62,7 @@ public class IEDCollectService {
|
|
|
|
|
iecClient.disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void collectAndSave(List<Rptparamindex> rptList) {
|
|
|
|
|
public void collectAndSave(List<Rptparamindex> rptList, List<IedDlConfig> dlList) {
|
|
|
|
|
List<IcdConfigType> configTypeList = _configRepository.findByIcdIedId(ied.getId());
|
|
|
|
|
if (CollectionUtils.isEmpty(configTypeList)) {
|
|
|
|
|
return;
|
|
|
|
@ -61,8 +71,13 @@ public class IEDCollectService {
|
|
|
|
|
try {
|
|
|
|
|
log.info("61850开始采集数据, ied=" + ied.getName() + ", ip=" + ied.getIp());
|
|
|
|
|
this.connect();
|
|
|
|
|
this.doCollectAndSave(configTypeList, rptList);
|
|
|
|
|
if (!CollectionUtils.isEmpty(rptList)) {
|
|
|
|
|
this.doCollectAndSave(configTypeList, rptList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(dlList)) {
|
|
|
|
|
this.doDownload(dlList);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
String err = "61850采集数据异常, ied=" + ied.getName() + ", ip=" + ied.getIp();
|
|
|
|
|
log.error(err, ex);
|
|
|
|
@ -122,6 +137,51 @@ public class IEDCollectService {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void doDownload(List<IedDlConfig> dlList) {
|
|
|
|
|
for (IedDlConfig config : dlList) {
|
|
|
|
|
this.downloadOne(config);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void downloadOne(IedDlConfig config) {
|
|
|
|
|
if (config.getActive() == null || config.getActive().intValue() == Constants.FALSE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(config.getPath())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (config.getDevId() == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
String localPath = folder + "/" + config.getDevId();
|
|
|
|
|
List<FileInformation> fileList = iecClient.listFile(config.getPath());
|
|
|
|
|
for (FileInformation file : fileList) {
|
|
|
|
|
String filename = file.getFilename();
|
|
|
|
|
if (!filename.endsWith("/")) {
|
|
|
|
|
if (StringUtils.isBlank(config.getSuffix()) ||
|
|
|
|
|
filename.toLowerCase().endsWith(config.getSuffix().toLowerCase())) {
|
|
|
|
|
IedDlRecord record = new IedDlRecord();
|
|
|
|
|
record.setConfigId(config.getId());
|
|
|
|
|
record.setFilename(filename);
|
|
|
|
|
boolean exist = _dlRecordService.exist(record);
|
|
|
|
|
if (!exist) {
|
|
|
|
|
String localFilePath = localPath + "/" + filename;
|
|
|
|
|
iecClient.getFile(config.getPath(), filename, _bizConfig.getDatapath() + localFilePath, config.getTodel());
|
|
|
|
|
record.setPath(_bizConfig.getDataNginxPath() + localFilePath);
|
|
|
|
|
record.setCreateTime(new Date());
|
|
|
|
|
_dlRecordService.add(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
String err = "61850下载文件异常, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", path=" + config.getPath();
|
|
|
|
|
log.error(err, ex);
|
|
|
|
|
_webSocketServer.sendMessage(err, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void updateLastData(Integer eqmid, String colname, String value, String time) {
|
|
|
|
|
HashMap<String, String> map = lastDataMap.get(eqmid);
|
|
|
|
|
if (map == null) {
|
|
|
|
|