feat: 定时任务61850下载文件保存本地

dev
huangfeng 8 months ago
parent 020fde5202
commit 47e260cb08

@ -17,5 +17,6 @@ public class BizConfig {
private String rsakey;
private String datapath;
private String dataNginxPath = "/data";
}

@ -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();
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) {

@ -1,6 +1,7 @@
package com.xydl.cac.iec;
import com.beanit.iec61850bean.*;
import com.xydl.cac.entity.constants.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
@ -99,10 +100,10 @@ public class IecClient implements ClientEventListener {
return list;
}
public void getFile(String remotePath, String filename, String localPath, boolean todel) throws Exception {
public void getFile(String remotePath, String filename, String localPath, Integer todel) throws Exception {
GetFileAction gfa = new GetFileAction(localPath);
clientAssociation.getFile(remotePath + filename, gfa);
if (todel) {
if (todel != null && todel == Constants.TRUE) {
clientAssociation.deleteFile(remotePath + filename);
}
}
@ -128,7 +129,7 @@ public class IecClient implements ClientEventListener {
str = iecClient.getValue("OMDLMONT/SPDC1.MaxDsch.t", "MX");
System.out.println(str);
List<FileInformation> list = iecClient.listFile("/fdata");
iecClient.getFile("/fdata/web/comtrade/1/18/6/", "20241021_113736_703_0_0.dat", "/eqmid/20241021_113736_703_0_0.dat", true);
iecClient.getFile("/fdata/web/comtrade/1/18/6/", "20241021_113736_703_0_0.dat", "/eqmid/20241021_113736_703_0_0.dat", 1);
} catch (Exception ex) {
ex.printStackTrace();

@ -12,4 +12,6 @@ import java.util.List;
public interface IedDlConfigRepository extends JpaRepository<IedDlConfig, Integer>, JpaSpecificationExecutor<IedDlConfig> {
List<IedDlConfig> findByDevId(Integer devId);
List<IedDlConfig> findByDevIdIn(List<Integer> idList);
}

@ -1,10 +1,13 @@
package com.xydl.cac.task;
import com.xydl.cac.config.BizConfig;
import com.xydl.cac.entity.IcdIed;
import com.xydl.cac.entity.IedDlConfig;
import com.xydl.cac.entity.Rptparamindex;
import com.xydl.cac.iec.IEDCollectService;
import com.xydl.cac.repository.*;
import com.xydl.cac.service.DataService;
import com.xydl.cac.service.IedDlRecordService;
import com.xydl.cac.socket.WebSocketServer;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@ -23,14 +26,21 @@ public class AsyncTask {
@Resource
RptparamindexRepository rptparamindexRepository;
@Resource
IedDlRecordService dlRecordService;
@Resource
DataService dataService;
@Resource
WebSocketServer webSocketServer;
@Resource
BizConfig bizConfig;
@Async
public void collectIed(String xml, IcdIed ied, List<Rptparamindex> rptList) {
IEDCollectService iedService = new IEDCollectService(configRepository, attRepository, instRepository,
rptparamindexRepository, dataService, xml, ied, webSocketServer);
iedService.collectAndSave(rptList);
public void collectIed(String xml, IcdIed ied, List<Rptparamindex> rptList, List<IedDlConfig> dlList) {
IEDCollectService iedService = new IEDCollectService(configRepository, attRepository,
instRepository, rptparamindexRepository,
dlRecordService, dataService,
xml, ied,
webSocketServer, bizConfig);
iedService.collectAndSave(rptList, dlList);
}
}

@ -33,6 +33,8 @@ public class Client61850Task {
ModevTypeService modevTypeService;
@Resource
NSensorRepository sensorRepository;
@Resource
IedDlConfigRepository dlConfigRepository;
int shutdown = 0;
@ -79,26 +81,27 @@ public class Client61850Task {
}
List<Rptparamindex> rptList = rptparamindexRepository.findAllByEqmidInAndColnameIsNotNull(eqmidList);
if (CollectionUtils.isEmpty(rptList)) {
List<IedDlConfig> dlList = dlConfigRepository.findByDevIdIn(eqmidList);
if (CollectionUtils.isEmpty(rptList) && CollectionUtils.isEmpty(dlList)) {
return;
}
List<IcdFile> icdFileList = fileRepository.findAll();
if (!CollectionUtils.isEmpty(icdFileList)) {
for (IcdFile icdFile : icdFileList) {
this.collectIcdFile(icdFile, rptList);
this.collectIcdFile(icdFile, rptList, dlList);
}
}
}
private void collectIcdFile(IcdFile icdFile, List<Rptparamindex> rptList) {
private void collectIcdFile(IcdFile icdFile, List<Rptparamindex> rptList, List<IedDlConfig> dlList) {
if (shutdown == 1) {
return;
}
List<IcdIed> iedList = iedRepository.findByIcdFileId(icdFile.getId());
if (!CollectionUtils.isEmpty(iedList)) {
for (IcdIed ied : iedList) {
asyncTask.collectIed(icdFile.getXml(), ied, rptList);
asyncTask.collectIed(icdFile.getXml(), ied, rptList, dlList);
}
}
}

@ -24,10 +24,9 @@ import java.util.Vector;
@Service
@Slf4j
public class AmpliDownloadTask {
public class SftpDownloadTask {
String nginxPath = "/data";
String folder = "/ampli";
String folder = "/sftp";
@Resource
BizConfig bizConfig;
@ -130,7 +129,7 @@ public class AmpliDownloadTask {
if (config.getTodel() != null && config.getTodel().intValue() == Constants.TRUE) {
sftpTool.delete(filename);
}
item.setPath(nginxPath + localFilePath);
item.setPath(bizConfig.getDataNginxPath() + localFilePath);
item.setCreateTime(new Date());
downloadService.add(item);
}
Loading…
Cancel
Save