|
|
@ -3,17 +3,20 @@ package com.xydl.cac.iec;
|
|
|
|
import com.beanit.iec61850bean.*;
|
|
|
|
import com.beanit.iec61850bean.*;
|
|
|
|
import com.xydl.cac.entity.IcdFile;
|
|
|
|
import com.xydl.cac.entity.IcdFile;
|
|
|
|
import com.xydl.cac.entity.IcdIed;
|
|
|
|
import com.xydl.cac.entity.IcdIed;
|
|
|
|
|
|
|
|
import com.xydl.cac.exception.BusinessException;
|
|
|
|
import com.xydl.cac.repository.IcdFileRepository;
|
|
|
|
import com.xydl.cac.repository.IcdFileRepository;
|
|
|
|
import com.xydl.cac.repository.IcdIedRepository;
|
|
|
|
import com.xydl.cac.repository.IcdIedRepository;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
@ -26,38 +29,67 @@ public class RealTimeDataService {
|
|
|
|
public static HashMap<String, String> dataMap = new HashMap<>();
|
|
|
|
public static HashMap<String, String> dataMap = new HashMap<>();
|
|
|
|
public static IecServer iecServer = null;
|
|
|
|
public static IecServer iecServer = null;
|
|
|
|
public static boolean inDoing = false;
|
|
|
|
public static boolean inDoing = false;
|
|
|
|
HashMap<String, IecClient> clientMap = new HashMap<>();
|
|
|
|
HashMap<Integer, IecClient> clientMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
public void start() {
|
|
|
|
@PostConstruct
|
|
|
|
inDoing = true;
|
|
|
|
private void init() {
|
|
|
|
List<IcdFile> icdFileList = fileRepository.findAll();
|
|
|
|
List<IcdIed> list = iedRepository.findByStart(1);
|
|
|
|
if (CollectionUtils.isEmpty(icdFileList)) {
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
return;
|
|
|
|
for (IcdIed ied : list) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
for (IcdFile icdFile : icdFileList) {
|
|
|
|
this.startCollect(ied.getId());
|
|
|
|
List<IcdIed> iedList = iedRepository.findByIcdFileId(icdFile.getId());
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
if (!CollectionUtils.isEmpty(iedList)) {
|
|
|
|
|
|
|
|
for (IcdIed ied : iedList) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
IecClient iecClient = new IecClient();
|
|
|
|
|
|
|
|
iecClient.connect(ied.getIp(), 102, ied.getApTitle(), icdFile.getXml());
|
|
|
|
|
|
|
|
iecClient.enableReporting();
|
|
|
|
|
|
|
|
log.info("61850订阅成功, ied=" + ied.getName() + ", ip=" + ied.getIp());
|
|
|
|
|
|
|
|
clientMap.put(ied.getIp(), iecClient);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
log.error("61850订阅异常, ied=" + ied.getName() + ", ip=" + ied.getIp(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void startCollect(Integer iedId) throws BusinessException {
|
|
|
|
|
|
|
|
inDoing = true;
|
|
|
|
|
|
|
|
Optional<IcdIed> optional = iedRepository.findById(iedId);
|
|
|
|
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
|
|
|
|
throw new BusinessException("未找到该IED");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IcdIed ied = optional.get();
|
|
|
|
|
|
|
|
Optional<IcdFile> optionalFile = fileRepository.findById(ied.getIcdFileId());
|
|
|
|
|
|
|
|
if (!optionalFile.isPresent()) {
|
|
|
|
|
|
|
|
throw new BusinessException("未找到该icd文件");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IcdFile icdFile = optionalFile.get();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
IecClient iecClient = new IecClient();
|
|
|
|
|
|
|
|
iecClient.connect(ied.getIp(), 102, ied.getApTitle(), icdFile.getXml());
|
|
|
|
|
|
|
|
iecClient.enableReporting();
|
|
|
|
|
|
|
|
log.info("61850订阅成功, ied=" + ied.getName() + ", ip=" + ied.getIp());
|
|
|
|
|
|
|
|
ied.setStart(1);
|
|
|
|
|
|
|
|
iedRepository.save(ied);
|
|
|
|
|
|
|
|
clientMap.put(ied.getId(), iecClient);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
log.error("61850订阅异常, ied=" + ied.getName() + ", ip=" + ied.getIp(), ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
inDoing = false;
|
|
|
|
inDoing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void stopCollect(Integer iedId) {
|
|
|
|
|
|
|
|
IecClient iecClient = clientMap.get(iedId);
|
|
|
|
|
|
|
|
if (iecClient != null) {
|
|
|
|
|
|
|
|
iecClient.disableReporting();
|
|
|
|
|
|
|
|
iecClient.disconnect();
|
|
|
|
|
|
|
|
clientMap.remove(iedId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<IcdIed> optional = iedRepository.findById(iedId);
|
|
|
|
|
|
|
|
if (optional.isPresent()) {
|
|
|
|
|
|
|
|
IcdIed ied = optional.get();
|
|
|
|
|
|
|
|
ied.setStart(0);
|
|
|
|
|
|
|
|
iedRepository.save(ied);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PreDestroy
|
|
|
|
@PreDestroy
|
|
|
|
public void stop() {
|
|
|
|
private void stop() {
|
|
|
|
Iterator<String> it = clientMap.keySet().iterator();
|
|
|
|
Iterator<Integer> it = clientMap.keySet().iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
while (it.hasNext()) {
|
|
|
|
String key = it.next();
|
|
|
|
Integer key = it.next();
|
|
|
|
IecClient iecClient = clientMap.get(key);
|
|
|
|
IecClient iecClient = clientMap.get(key);
|
|
|
|
iecClient.disableReporting();
|
|
|
|
iecClient.disableReporting();
|
|
|
|
iecClient.disconnect();
|
|
|
|
iecClient.disconnect();
|
|
|
|