|
|
@ -24,22 +24,20 @@ public class IecServerService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
IcdTransformService transformService;
|
|
|
|
IcdTransformService transformService;
|
|
|
|
|
|
|
|
|
|
|
|
IecServer iecServer = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
private void init() {
|
|
|
|
private void init() {
|
|
|
|
iecServer = new IecServer(transformService);
|
|
|
|
|
|
|
|
List<IcdFile> list = fileRepository.findBySrvAndStart(Constants.Server, Constants.TRUE);
|
|
|
|
List<IcdFile> list = fileRepository.findBySrvAndStart(Constants.Server, Constants.TRUE);
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
IcdFile icdFile = list.get(0);
|
|
|
|
for (IcdFile icdFile : list) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.startServer(icdFile.getId());
|
|
|
|
this.startServer(icdFile.getId(), icdFile.getPort());
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void startServer(Integer fileId) throws BusinessException {
|
|
|
|
public void startServer(Integer fileId, int port) throws BusinessException {
|
|
|
|
Optional<IcdFile> optional = fileRepository.findById(fileId);
|
|
|
|
Optional<IcdFile> optional = fileRepository.findById(fileId);
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
throw new BusinessException("未找到该文件");
|
|
|
|
throw new BusinessException("未找到该文件");
|
|
|
@ -49,44 +47,57 @@ public class IecServerService {
|
|
|
|
throw new BusinessException("该文件不是服务端文件");
|
|
|
|
throw new BusinessException("该文件不是服务端文件");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
iecServer.start(icdFile.getXml(), 102);
|
|
|
|
IecServer iecServer = new IecServer(transformService);
|
|
|
|
|
|
|
|
iecServer.start(icdFile.getXml(), port);
|
|
|
|
iecServer.filename = icdFile.getFilename();
|
|
|
|
iecServer.filename = icdFile.getFilename();
|
|
|
|
iecServer.fileId = icdFile.getId();
|
|
|
|
RealTimeDataService.iecServerMap.put(fileId, iecServer);
|
|
|
|
RealTimeDataService.iecServer = iecServer;
|
|
|
|
|
|
|
|
icdFile.setStart(Constants.TRUE);
|
|
|
|
icdFile.setStart(Constants.TRUE);
|
|
|
|
|
|
|
|
icdFile.setPort(port);
|
|
|
|
fileRepository.save(icdFile);
|
|
|
|
fileRepository.save(icdFile);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
icdFile.setStart(Constants.FALSE);
|
|
|
|
|
|
|
|
fileRepository.save(icdFile);
|
|
|
|
log.error("启动IEC61850服务端异常.", e);
|
|
|
|
log.error("启动IEC61850服务端异常.", e);
|
|
|
|
|
|
|
|
throw new BusinessException(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void stopServer() {
|
|
|
|
public void stopServer(Integer fileId) {
|
|
|
|
this.stop();
|
|
|
|
this.onlyStopServer(fileId);
|
|
|
|
if (iecServer.fileId != null) {
|
|
|
|
Optional<IcdFile> optional = fileRepository.findById(fileId);
|
|
|
|
Optional<IcdFile> optional = fileRepository.findById(iecServer.fileId);
|
|
|
|
if (optional.isPresent()) {
|
|
|
|
if (optional.isPresent()) {
|
|
|
|
IcdFile icdFile = optional.get();
|
|
|
|
IcdFile icdFile = optional.get();
|
|
|
|
icdFile.setStart(Constants.FALSE);
|
|
|
|
icdFile.setStart(Constants.FALSE);
|
|
|
|
fileRepository.save(icdFile);
|
|
|
|
fileRepository.save(icdFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void onlyStopServer(Integer fileId) {
|
|
|
|
|
|
|
|
IecServer iecServer = RealTimeDataService.iecServerMap.get(fileId);
|
|
|
|
|
|
|
|
if (iecServer != null) {
|
|
|
|
|
|
|
|
log.info("关闭IecServer服务, port=" + iecServer.port);
|
|
|
|
|
|
|
|
iecServer.close();
|
|
|
|
|
|
|
|
RealTimeDataService.iecServerMap.remove(fileId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PreDestroy
|
|
|
|
@PreDestroy
|
|
|
|
private void stop() {
|
|
|
|
private void stop() {
|
|
|
|
log.info("关闭IecServer服务.");
|
|
|
|
Iterator<Integer> it = RealTimeDataService.iecServerMap.keySet().iterator();
|
|
|
|
RealTimeDataService.iecServer = null;
|
|
|
|
while (it.hasNext()) {
|
|
|
|
iecServer.close();
|
|
|
|
Integer key = it.next();
|
|
|
|
|
|
|
|
this.onlyStopServer(key);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public HashMap<String, Object> status() {
|
|
|
|
// public HashMap<String, Object> status() {
|
|
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
|
|
// HashMap<String, Object> map = new HashMap<>();
|
|
|
|
map.put("port", 102);
|
|
|
|
// map.put("port", 102);
|
|
|
|
map.put("started", iecServer.started);
|
|
|
|
// map.put("started", iecServer.started);
|
|
|
|
map.put("filename", iecServer.filename);
|
|
|
|
// map.put("filename", iecServer.filename);
|
|
|
|
map.put("fileId", iecServer.fileId);
|
|
|
|
// map.put("fileId", iecServer.fileId);
|
|
|
|
return map;
|
|
|
|
// return map;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
public List<IcdConfigTypeInst> listParamindex(Integer fileId) throws Exception {
|
|
|
|
public List<IcdConfigTypeInst> listParamindex(Integer fileId) throws Exception {
|
|
|
|
Optional<IcdFile> optional = fileRepository.findById(fileId);
|
|
|
|
Optional<IcdFile> optional = fileRepository.findById(fileId);
|
|
|
|