feat: 增加61850订阅实时数据
parent
e1248945a5
commit
2ceaadb1e2
@ -0,0 +1,8 @@
|
||||
package com.xydl.cac.service;
|
||||
|
||||
public interface RealTimeService {
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.xydl.cac.service.impl;
|
||||
|
||||
import com.xydl.cac.entity.IcdFile;
|
||||
import com.xydl.cac.entity.IcdIed;
|
||||
import com.xydl.cac.iec.IecClient;
|
||||
import com.xydl.cac.repository.*;
|
||||
import com.xydl.cac.service.RealTimeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class RealTimeServiceImpl implements RealTimeService {
|
||||
|
||||
@Resource
|
||||
IcdFileRepository fileRepository;
|
||||
@Resource
|
||||
IcdIedRepository iedRepository;
|
||||
|
||||
HashMap<String, IecClient> clientMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
List<IcdFile> icdFileList = fileRepository.findAll();
|
||||
if (CollectionUtils.isEmpty(icdFileList)) {
|
||||
return;
|
||||
}
|
||||
for (IcdFile icdFile : icdFileList) {
|
||||
List<IcdIed> iedList = iedRepository.findByIcdFileId(icdFile.getId());
|
||||
if (!CollectionUtils.isEmpty(iedList)) {
|
||||
for (IcdIed ied : iedList) {
|
||||
try {
|
||||
IecClient iecClient = new IecClient();
|
||||
iecClient.connect(ied.getIp(), 102, ied.getApTitle(), icdFile.getXml());
|
||||
iecClient.enableReporting();
|
||||
clientMap.put(ied.getIp(), iecClient);
|
||||
} catch (Exception ex) {
|
||||
log.error("61850连接异常, ied=" + ied.getName() + ", ip=" + ied.getIp(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
@Override
|
||||
public void stop() {
|
||||
Iterator<String> it = clientMap.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = it.next();
|
||||
IecClient iecClient = clientMap.get(key);
|
||||
iecClient.disconnect();
|
||||
clientMap.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue