From 51bcf3edc0a3ee1ff0e12375f74c1a116c8fb319 Mon Sep 17 00:00:00 2001 From: weitang Date: Wed, 21 May 2025 09:21:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=8061850=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iec104/client/IEC104ClientRunner.java | 48 +++++++------- .../iec104/core/ControlManageUtil.java | 40 ++++++------ .../iec104/core/ScheduledTaskPool.java | 62 +++++++++---------- .../master/handler/Iec104ClientHandler.java | 46 +++++++------- .../slave/handler/Iec104TcpSlaveHandler.java | 46 +++++++------- .../iec61850/client/IEC61850ClientRunner.java | 8 +-- .../impl/AlgorithmParamsServiceImpl.java | 28 +++++++-- .../impl/GatewayDeviceServiceImpl.java | 22 +++---- 8 files changed, 160 insertions(+), 140 deletions(-) diff --git a/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IEC104ClientRunner.java b/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IEC104ClientRunner.java index 3c1be0b..632c098 100644 --- a/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IEC104ClientRunner.java +++ b/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IEC104ClientRunner.java @@ -61,30 +61,30 @@ public class IEC104ClientRunner implements ApplicationRunner { GatewayDevice::getIpAddr, GatewayDevice::getIecAddr); queryWrapper.orderByAsc(GatewayDevice::getDeviceCode); List list = gatewayDeviceMapper.selectList(queryWrapper); -// if (list.size() > 0) { -// for (GatewayDevice gatewayDevice : list) { -// Iec104Config iec104Config = new Iec104Config(); -// iec104Config.setFrameAmountMax((short) 10); -// short terminnalAddress = gatewayDevice.getIecAddr().shortValue(); -// //通讯网关机地址 -// iec104Config.setTerminnalAddress(terminnalAddress); -// iec104Config.setSlaveCode(gatewayDevice.getDeviceCode()); -// iec104Config.setSlaveIP(gatewayDevice.getIpAddr()); -// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); -// threadPool.execute(() -> { -// Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(), -// 2404); -// try { -// iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run(); -// -// } catch (Exception e) { -// log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP())); -// } -// }); -// threadPool.shutdown(); -// } -// -// } + if (list.size() > 0) { + for (GatewayDevice gatewayDevice : list) { + Iec104Config iec104Config = new Iec104Config(); + iec104Config.setFrameAmountMax((short) 10); + short terminnalAddress = gatewayDevice.getIecAddr().shortValue(); + //通讯网关机地址 + iec104Config.setTerminnalAddress(terminnalAddress); + iec104Config.setSlaveCode(gatewayDevice.getDeviceCode()); + iec104Config.setSlaveIP(gatewayDevice.getIpAddr()); + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(), + 2404); + try { + iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run(); + + } catch (Exception e) { + log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP())); + } + }); + threadPool.shutdown(); + } + + } } } diff --git a/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ControlManageUtil.java b/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ControlManageUtil.java index a838e88..8bc0c1b 100644 --- a/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ControlManageUtil.java +++ b/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ControlManageUtil.java @@ -60,26 +60,26 @@ public class ControlManageUtil { * 启动S发送S确认帧 的任务 */ public void startSendFrameTask() { -// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); -// threadPool.execute(() -> { -// while (true) { -// try { -// synchronized (sendSframeLock) { -// if (frameAmount >= frameAmountMax) { -// // 查过最大帧 的数量就要发送一个确认帧出去 -// byte[] control = Iec104Util.getScontrol(accept); -// MessageDetail ruleDetail104 = new MessageDetail(control); -// ctx.channel().writeAndFlush(Encoder104.encoder(ruleDetail104)); -// frameAmount = 0; -// } -// sendSframeLock.wait(); -// } -// } catch (Exception e) { -// LOGGER.error("Exception caught", e); -// } -// } -// }); -// threadPool.shutdown(); + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + while (true) { + try { + synchronized (sendSframeLock) { + if (frameAmount >= frameAmountMax) { + // 查过最大帧 的数量就要发送一个确认帧出去 + byte[] control = Iec104Util.getScontrol(accept); + MessageDetail ruleDetail104 = new MessageDetail(control); + ctx.channel().writeAndFlush(Encoder104.encoder(ruleDetail104)); + frameAmount = 0; + } + sendSframeLock.wait(); + } + } catch (Exception e) { + LOGGER.error("Exception caught", e); + } + } + }); + threadPool.shutdown(); } diff --git a/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ScheduledTaskPool.java b/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ScheduledTaskPool.java index c70cbfa..89e1954 100644 --- a/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ScheduledTaskPool.java +++ b/riis-system/src/main/java/com/yfd/platform/component/iec104/core/ScheduledTaskPool.java @@ -72,22 +72,22 @@ public class ScheduledTaskPool { * @Description: 发送测试帧 */ private void sendTestFrame() { -// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); -// threadPool.execute(() -> { -// try { -// BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText()); -// if(ObjUtil.isNotEmpty(channel )){ -// String slaveIp = channel .getCode(); -// LOGGER.info(String.format("向从站[%s]发送测试链路指令!",slaveIp )); -// ctx.channel().writeAndFlush(BasicInstruction104.TESTFR); -// //对时指令 -// ctx.channel().writeAndFlush(BasicInstruction104.getTimeScale104()); -// } -// } catch (Exception e) { -// LOGGER.error("Exception caught", e); -// } -// }); -// threadPool.shutdown(); + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + try { + BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText()); + if(ObjUtil.isNotEmpty(channel )){ + String slaveIp = channel .getCode(); + LOGGER.info(String.format("向从站[%s]发送测试链路指令!",slaveIp )); + ctx.channel().writeAndFlush(BasicInstruction104.TESTFR); + //对时指令 + ctx.channel().writeAndFlush(BasicInstruction104.getTimeScale104()); + } + } catch (Exception e) { + LOGGER.error("Exception caught", e); + } + }); + threadPool.shutdown(); } @@ -101,21 +101,21 @@ public class ScheduledTaskPool { } private void sendGeneralCall() { -// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); -// threadPool.execute(() -> { -// try { -// BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText()); -// if (ObjUtil.isNotEmpty(channel)) { -// String slaveIp = channel.getCode(); -// MessageDetail messageDetail = BasicInstruction104.getGeneralCallRuleDetail104(); -// LOGGER.info(String.format("向从站[%s]发送总召唤指令[%s]!", slaveIp, messageDetail.getHexString())); -// ctx.channel().writeAndFlush(messageDetail); -// } -// } catch (Exception e) { -// LOGGER.error("Exception caught", e); -// } -// }); -// threadPool.shutdown(); + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + try { + BootNettyClientChannel channel = BootNettyClientChannelCache.get(ctx.channel().id().asShortText()); + if (ObjUtil.isNotEmpty(channel)) { + String slaveIp = channel.getCode(); + MessageDetail messageDetail = BasicInstruction104.getGeneralCallRuleDetail104(); + LOGGER.info(String.format("向从站[%s]发送总召唤指令[%s]!", slaveIp, messageDetail.getHexString())); + ctx.channel().writeAndFlush(messageDetail); + } + } catch (Exception e) { + LOGGER.error("Exception caught", e); + } + }); + threadPool.shutdown(); } public void stopSendCommandTask() { diff --git a/riis-system/src/main/java/com/yfd/platform/component/iec104/server/master/handler/Iec104ClientHandler.java b/riis-system/src/main/java/com/yfd/platform/component/iec104/server/master/handler/Iec104ClientHandler.java index f8eca7f..8cf516d 100644 --- a/riis-system/src/main/java/com/yfd/platform/component/iec104/server/master/handler/Iec104ClientHandler.java +++ b/riis-system/src/main/java/com/yfd/platform/component/iec104/server/master/handler/Iec104ClientHandler.java @@ -49,17 +49,17 @@ public class Iec104ClientHandler extends SimpleChannelInboundHandler { -// try { -// dataHandler.handlerAdded(new ChannelHandlerImpl(ctx)); -// } catch (Exception e) { -// LOGGER.error("Exception caught", e); -// } -// }); -// threadPool.shutdown(); -// } + if (dataHandler != null) { + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + try { + dataHandler.handlerAdded(new ChannelHandlerImpl(ctx)); + } catch (Exception e) { + LOGGER.error("Exception caught", e); + } + }); + threadPool.shutdown(); + } } @Override @@ -76,18 +76,18 @@ public class Iec104ClientHandler extends SimpleChannelInboundHandler { -// try { -// dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104); -// } catch (Exception e) { -// // TODO Auto-generated catch block -// LOGGER.error("Exception caught", e); -// } -// }); -// threadPool.shutdown(); -// } + if (dataHandler != null) { + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + try { + dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104); + } catch (Exception e) { + // TODO Auto-generated catch block + LOGGER.error("Exception caught", e); + } + }); + threadPool.shutdown(); + } } diff --git a/riis-system/src/main/java/com/yfd/platform/component/iec104/server/slave/handler/Iec104TcpSlaveHandler.java b/riis-system/src/main/java/com/yfd/platform/component/iec104/server/slave/handler/Iec104TcpSlaveHandler.java index a6c6663..324cec3 100644 --- a/riis-system/src/main/java/com/yfd/platform/component/iec104/server/slave/handler/Iec104TcpSlaveHandler.java +++ b/riis-system/src/main/java/com/yfd/platform/component/iec104/server/slave/handler/Iec104TcpSlaveHandler.java @@ -40,17 +40,17 @@ public class Iec104TcpSlaveHandler extends SimpleChannelInboundHandler { -// try { -// dataHandler.handlerAdded(new ChannelHandlerImpl(ctx)); -// } catch (Exception e) { -// LOGGER.error("Exception caught", e); -// } -// }); -// threadPool.shutdown(); -// } + if (dataHandler != null) { + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + try { + dataHandler.handlerAdded(new ChannelHandlerImpl(ctx)); + } catch (Exception e) { + LOGGER.error("Exception caught", e); + } + }); + threadPool.shutdown(); + } } /** @@ -65,18 +65,18 @@ public class Iec104TcpSlaveHandler extends SimpleChannelInboundHandler { -// try { -// dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104); -// } catch (Exception e) { -// LOGGER.error("Exception caught", e); -// } -// }); -// threadPool.shutdown(); -// } + if (dataHandler != null) { + + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> { + try { + dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104); + } catch (Exception e) { + LOGGER.error("Exception caught", e); + } + }); + threadPool.shutdown(); + } } /** diff --git a/riis-system/src/main/java/com/yfd/platform/component/iec61850/client/IEC61850ClientRunner.java b/riis-system/src/main/java/com/yfd/platform/component/iec61850/client/IEC61850ClientRunner.java index fcbd915..349c4c2 100644 --- a/riis-system/src/main/java/com/yfd/platform/component/iec61850/client/IEC61850ClientRunner.java +++ b/riis-system/src/main/java/com/yfd/platform/component/iec61850/client/IEC61850ClientRunner.java @@ -45,10 +45,10 @@ public class IEC61850ClientRunner implements ApplicationRunner { queryWrapper.orderByAsc(GatewayDevice::getDeviceCode); List list = gatewayDeviceMapper.selectList(queryWrapper); if (!list.isEmpty()) { -// for (GatewayDevice systemDevice : list) { -// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); -// threadPool.execute(() -> iec61850Service.connect(systemDevice)); -// } + for (GatewayDevice systemDevice : list) { + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(() -> iec61850Service.connect(systemDevice)); + } } } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java index f4dd499..bd59268 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/service/impl/AlgorithmParamsServiceImpl.java @@ -1,17 +1,18 @@ package com.yfd.platform.modules.algorithm.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.net.NetUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.yfd.platform.modules.algorithm.domain.AlgorithmClass; -import com.yfd.platform.modules.algorithm.domain.AlgorithmClassComponent; -import com.yfd.platform.modules.algorithm.domain.AlgorithmDevice; -import com.yfd.platform.modules.algorithm.domain.AlgorithmParams; +import com.yfd.platform.modules.algorithm.domain.*; import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassMapper; import com.yfd.platform.modules.algorithm.mapper.AlgorithmDeviceMapper; +import com.yfd.platform.modules.algorithm.mapper.AlgorithmLogsMapper; import com.yfd.platform.modules.algorithm.mapper.AlgorithmParamsMapper; import com.yfd.platform.modules.algorithm.service.IAlgorithmParamsService; +import com.yfd.platform.modules.basedata.domain.SubstationComponent; +import com.yfd.platform.modules.basedata.mapper.SubstationComponentMapper; import com.yfd.platform.utils.HttpRESTfulUtils; import com.yfd.platform.utils.StringUtils; import org.springframework.stereotype.Service; @@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.net.URI; import java.net.URISyntaxException; +import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,6 +45,13 @@ public class AlgorithmParamsServiceImpl extends ServiceImpl { -// Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(), 2404); -// try { -// iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run(); -// } catch (Exception e) { -// EventLoopGroupManager.shutdownEventLoopGroup(ip); -// log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP())); -// } -// }; -// OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); -// threadPool.execute(runnable); + Runnable runnable = () -> { + Iec104Master iec104server = Iec104MasterFactory.createTcpClientMaster(iec104Config.getSlaveIP(), 2404); + try { + iec104server.setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run(); + } catch (Exception e) { + EventLoopGroupManager.shutdownEventLoopGroup(ip); + log.error(String.format("%s-对应的终端连接失败!", iec104Config.getSlaveIP())); + } + }; + OptimizedThreadPool threadPool = OptimizedThreadPool.getInstance(); + threadPool.execute(runnable); } return true;