From dbc07b2cf3f15442d1696b486e0e70f85b21ee8e Mon Sep 17 00:00:00 2001 From: wr <1754607820@qq.com> Date: Tue, 17 Dec 2024 19:22:54 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=BA=90=E8=A3=85=E7=BD=AE=EF=BC=8C=E5=85=A5?= =?UTF-8?q?=E5=8F=82=E5=92=8C=E5=8F=91=E9=80=81=E6=8C=87=E4=BB=A4=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PreDetectionController.java | 16 ++- .../handler/SocketSourceResponseService.java | 45 ++++++- .../pojo/enums/SourceOperateCodeEnum.java | 32 +++++ .../pojo/enums/SourceResponseCodeEnum.java | 53 ++++++++ .../pojo/param/PreDetectionParam.java | 2 +- .../detection/pojo/vo/SocketDataMsg.java | 7 +- .../service/PreDetectionService.java | 17 --- .../service/impl/PreDetectionServiceImpl.java | 123 ++++++++---------- .../gather/detection/util/socket/MsgUtil.java | 2 +- .../detection/util/socket/SocketManager.java | 4 +- .../util/socket/cilent/NettyClient.java | 12 +- .../cilent/NettySourceClientHandler.java | 12 +- .../util/socket/web/WebSocketHandler.java | 5 - .../gather/plan/pojo/po/AdPlanSource.java | 5 + .../script/pojo/param/PqScriptIssueParam.java | 7 + .../device/script/pojo/po/PqScriptDtls.java | 2 + .../service/impl/PqScriptDtlsServiceImpl.java | 120 +++++++++++------ entrance/src/main/resources/application.yml | 20 ++- 18 files changed, 315 insertions(+), 169 deletions(-) create mode 100644 detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java create mode 100644 detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java diff --git a/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java b/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java index 8b985627..7bdcc3d1 100644 --- a/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java +++ b/detection/src/main/java/com/njcn/gather/detection/controller/PreDetectionController.java @@ -12,10 +12,8 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.Get; import org.springframework.web.bind.annotation.*; -import java.util.List; @Slf4j @Api(tags = "预检测") @@ -41,4 +39,18 @@ public class PreDetectionController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } + + /** + * 开始检测 + */ + @PostMapping("/startTest2") + @OperateInfo + @ApiOperation("开始检测") + @ApiImplicitParam(name = "param", value = "查询参数", required = true) + public HttpResult startTest2(@RequestBody PreDetectionParam param){ + String methodDescribe = getMethodDescribe("startTest"); + preDetectionService.sourceCommunicationCheck(param); + + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } } diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java index 440c8f0f..24b74883 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketSourceResponseService.java @@ -1,8 +1,18 @@ package com.njcn.gather.detection.handler; +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSON; +import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; +import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum; +import com.njcn.gather.detection.pojo.vo.SocketDataMsg; +import com.njcn.gather.detection.pojo.vo.SocketMsg; +import com.njcn.gather.detection.util.socket.MsgUtil; import com.njcn.gather.detection.util.socket.SocketManager; +import com.njcn.gather.detection.util.socket.cilent.NettyClient; +import com.njcn.gather.detection.util.socket.cilent.NettyDevClientHandler; import com.njcn.gather.detection.util.socket.web.WebSocketHandler; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service @@ -14,12 +24,39 @@ public class SocketSourceResponseService { */ private final WebSocketHandler webSocketHandler; + private final SocketResponseService sourceResponseService; + + @Value("${socket.device.ip}") + private String ip; + + @Value("${socket.device.port}") + private Integer port; public void deal(String userId,String msg){ + SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg); + if(SourceOperateCodeEnum.YJC_YTXJY.getValue().equals(socketDataMsg.getRequestId())){ + SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); + if(ObjectUtil.isNotNull(dictDataEnumByCode)){ + switch (dictDataEnumByCode){ + case SUCCESS: + webSocketHandler.sendMsgToUser(userId,msg); + String s = userId + "_Dev"; + //todo 创建终端socket连接 + NettyClient.socketClient(ip, port, s, new NettyDevClientHandler(s, sourceResponseService)); + SocketManager.sendMsg(s,"向127服务器发送"); + break; + case UNPROCESSED_BUSINESS: + break; + default: + SocketMsg socketMsg=new SocketMsg(); + socketMsg.setRequestId(socketDataMsg.getRequestId()); + socketMsg.setOperateCode(socketDataMsg.getOperateCode()); + socketMsg.setData(dictDataEnumByCode.getMessage()); + webSocketHandler.sendMsgToUser(userId, JSON.toJSONString(socketMsg)); + break; + } + } - System.out.println("进入deal+++++++++++++++++++"); - webSocketHandler.sendMsgToUser(userId,msg); - - SocketManager.getChannelByUserId(userId).close(); + } } diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java new file mode 100644 index 00000000..5ff1c0b3 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceOperateCodeEnum.java @@ -0,0 +1,32 @@ +package com.njcn.gather.detection.pojo.enums; + +import lombok.Getter; + +/** + * @Description: + * @Author: wr + * @Date: 2024/12/17 15:37 + */ +@Getter +public enum SourceOperateCodeEnum { + + /** + * 源状态 + */ + INIT_GATHER("INIT_GATHER", "源初始化"), + OPER_GATHER("OPER_GATHER", "源输出"), + CLOSE_GATHER("CLOSE_GATHER", "源停止"), + + YJC_YTXJY("yjc_ytxjy", "预检测_源通讯检测"); + + + + + private String value; + private String msg; + + SourceOperateCodeEnum(String value, String msg) { + this.value = value; + this.msg = msg; + } +} diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java new file mode 100644 index 00000000..6728a453 --- /dev/null +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java @@ -0,0 +1,53 @@ +package com.njcn.gather.detection.pojo.enums; + +import cn.hutool.core.util.ObjectUtil; +import lombok.Getter; + +/** + * @Author: wr + * @Date: 2024/12/17 15:37 + */ +@Getter +public enum SourceResponseCodeEnum { + + SUCCESS(10200, "请求成功"), + UNPROCESSED_BUSINESS(10201, "立即响应,业务还未处理,类似肯定应答"), + NORMAL_RESPONSE(10202, "正常响应中间状态码"), + MESSAGE_PARSING_ERROR(10520, "报文解析有误"), + CONTROLLED_SOURCE_ERROR(10521, "程控源参数有误"), + TEST_ITEM_PARSING_ERROR(10522, "测试项解析有误"), + SOURCE_CONNECTION_ERROR(10523, "源连接失败"), + SOURCE_CONTROL_ERROR(10524, "获取源控制权失败"), + RESET_ERROR(10525, "重置源失败"), + STOP_ERROR(10526, "停止源失败"), + NOT_INITIALIZED(10527, "源未进行初始化"), + TARGET_SOURCE_ERROR(10528, "目标源有误(该用户已控制其他源,在关闭前无法操作新的源)"), + UNABLE_TO_RESPOND(10529, "源状态有误,无法响应报文(例如源处于输出状态,无法响应初始化报文)"); + + + private Integer code; + private String message; + + SourceResponseCodeEnum(Integer code, String message) { + this.code = code; + this.message = message; + } + + public static String getMsgByValue(Integer code) { + for (SourceResponseCodeEnum state : SourceResponseCodeEnum.values()) { + if (state.getCode().equals(code)) { + return state.getMessage(); + } + } + return null; + } + + public static SourceResponseCodeEnum getDictDataEnumByCode(Integer code) { + for (SourceResponseCodeEnum sourceResponseCodeEnum : SourceResponseCodeEnum.values()) { + if (ObjectUtil.equals(code, sourceResponseCodeEnum.getCode())) { + return sourceResponseCodeEnum; + } + } + return null; + } +} diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java b/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java index e40fd67f..7155a514 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/param/PreDetectionParam.java @@ -15,7 +15,7 @@ public class PreDetectionParam { /** * 检测计划id */ - private String plan; + private String planId; /** * 用户功能组成唯一标识 zhangsan_test diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/SocketDataMsg.java b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/SocketDataMsg.java index bce729b0..0448a7b6 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/SocketDataMsg.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/SocketDataMsg.java @@ -1,5 +1,6 @@ package com.njcn.gather.detection.pojo.vo; +import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; /** @@ -13,21 +14,25 @@ public class SocketDataMsg { /** * 请求id,确保接收到响应时,知晓是针对的哪次请求的应答 */ + @JSONField(ordinal = 1) private String requestId; /** * 源初始化 INIT_GATHER$01 INIT_GATHER采集初始化,01 统计采集、02 暂态采集、03 实时采集 */ + @JSONField(ordinal = 2) private String operateCode; /** * 数据体,传输前需要将对象、Array等转为String */ + @JSONField(ordinal = 4) private String data; /** * code码 */ - private String code; + @JSONField(ordinal = 3) + private Integer code; } diff --git a/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java b/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java index 081eb5a2..81e011d0 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/PreDetectionService.java @@ -2,9 +2,7 @@ package com.njcn.gather.detection.service; import com.njcn.gather.detection.pojo.param.PreDetectionParam; -import java.util.List; -import com.njcn.gather.detection.pojo.param.PreDetectionParam; /** * @author wr @@ -21,21 +19,6 @@ public interface PreDetectionService { */ void sourceCommunicationCheck(PreDetectionParam param); - /** - * 装置通讯校验 - */ - void deviceCommunicationCheck(); - - /** - * 协议校验 - */ - void agreementCheck(); - - /** - * 相序校验 - */ - void phaseSequenceCheck(); - boolean startTest(PreDetectionParam param); diff --git a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java index f9cf60de..6dd62b10 100644 --- a/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java +++ b/detection/src/main/java/com/njcn/gather/detection/service/impl/PreDetectionServiceImpl.java @@ -3,7 +3,9 @@ package com.njcn.gather.detection.service.impl; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.gather.detection.handler.SocketSourceResponseService; +import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.vo.SocketMsg; import com.njcn.gather.detection.service.PreDetectionService; @@ -24,8 +26,6 @@ import com.njcn.gather.plan.service.IAdPlanService; import com.njcn.gather.plan.service.IAdPlanSourceService; import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum; import com.njcn.gather.system.dictionary.service.IDictDataService; -import io.netty.channel.Channel; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -53,25 +53,24 @@ public class PreDetectionServiceImpl implements PreDetectionService { - private final String userId = "aaa"; - @Override public void sourceCommunicationCheck(PreDetectionParam param) { /* 先组装源通讯协议 查询计划什么模式的(除了对比式,其他都是一个计划对应一个源) */ - AdPlan plan = iAdPlanService.getById(param.getPlan()); + AdPlan plan = iAdPlanService.getById(param.getPlanId()); if (ObjectUtil.isNotNull(plan)) { String code = dictDataService.getDictDataById(plan.getPattern()).getCode(); DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code); switch (dictDataEnumByCode) { case DIGITAL: case SIMULATE: - sendYtxSocket(plan.getId()); + sendYtxSocket(plan.getId(),param.getUserPageId()); break; case CONTRAST: //todo 对比式可以是多个源 + sendYtxSocket(plan.getId(),param.getUserPageId()); break; default: //todo 没有找到对应的模式 @@ -84,27 +83,23 @@ public class PreDetectionServiceImpl implements PreDetectionService { } - - /** - * 源参数下发 - * @param scriptId - */ - private void sendSourceIssue(String scriptId){ - - - - } - private void sendYtxSocket(String planId){ - AdPlanSource planSource = adPlanSourceService.getById(planId); + private void sendYtxSocket(String planId,String userPageId){ + AdPlanSource planSource = adPlanSourceService.getOne(new LambdaQueryWrapper() + .eq(AdPlanSource::getPlanId,planId) + ); if(ObjectUtil.isNotNull(planSource)){ SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId()); if(ObjectUtil.isNotNull(sourceParam)){ //开始组装socket报文请求头 SocketMsg msg=new SocketMsg(); - msg.setRequestId("yjc_ytxjy"); - msg.setOperateCode(""); + msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue()); + msg.setOperateCode(SourceOperateCodeEnum.OPER_GATHER.getValue()); msg.setData(JSON.toJSONString(sourceParam)); - NettyClient.socketClient(ip, port, JSON.toJSONString(msg), new NettySourceClientHandler(ip, sourceResponseService)); + String s = userPageId + "_Source"; + NettyClient.socketClient(ip, port, s, new NettySourceClientHandler(s, sourceResponseService)); + SocketManager.sendMsg(s,JSON.toJSONString(msg)); + + PqScriptIssueParam param=new PqScriptIssueParam(); param.setScriptId(planSource.getSourceId()); param.setPlanId(planId); @@ -122,63 +117,51 @@ public class PreDetectionServiceImpl implements PreDetectionService { } } - @Override - public void deviceCommunicationCheck() { - - } - - @Override - public void agreementCheck() { - - } - - @Override - public void phaseSequenceCheck() { - - } @Override public boolean startTest(PreDetectionParam param) { List pqDevList = iPqDevService.getDevInfo(Arrays.asList("578c142b7e4e4978a35bd6225aa62a23", "393504f55f1f79bce255bfc195cfdb56")); System.out.println(pqDevList); //校验 - - //组装请求数据 - SocketMsg socketMsg = new SocketMsg(); - Map> map = new HashMap(); - map.put("deviceList", pqDevList); - String jsonString = JSON.toJSONString(map); - socketMsg.setRequestId("adawdawd"); - socketMsg.setOperateCode("INIT_GATHER$03"); - socketMsg.setData(jsonString); - String json = JSON.toJSONString(socketMsg); - - String tem = "{\"data\":\"{\\\"deviceList\\\":[{\\\"devIP\\\":\\\"192.168.1.186\\\",\\\"port\\\":102,\\\"devType\\\":\\\"PQS882B\\\",\\\"icdType\\\":\\\"PQS882_VX_ZJ_1(V102)\\\",\\\"devCode\\\":\\\"Pqs\\u0026cn870299\\\",\\\"devKey\\\":\\\"!qaz@wsx3edc4rfv\\\",\\\"monitorList\\\":[{\\\"lineId\\\":\\\"1_192.168.1.186_102_1\\\",\\\"line\\\":1}]}]}\",\"operateCode\":\"INIT_GATHER$03\",\"requestId\":\"dansldquiwdlandalksn\"}"; - - - - Runnable runnable = new Runnable() { - - @Override - public void run() { - Channel channel = null; - if(SocketManager.getChannelByUserId(param.getUserPageId()) == null || !SocketManager.getChannelByUserId(param.getUserPageId()).isActive()){ - channel = NettyClient.socketClient(ip, port,param.getUserPageId(),new NettySourceClientHandler(param.getUserPageId(), sourceResponseService)); +// List pqDevList = iPqDevService.getDevInfo(Arrays.asList("578c142b7e4e4978a35bd6225aa62a23", "393504f55f1f79bce255bfc195cfdb56")); +// System.out.println(pqDevList); +// //校验 +// +// //组装请求数据 +// SocketMsg socketMsg = new SocketMsg(); +// Map> map = new HashMap(); +// map.put("deviceList", pqDevList); +// String jsonString = JSON.toJSONString(map); +// socketMsg.setRequestId("adawdawd"); +// socketMsg.setOperateCode("INIT_GATHER$03"); +// socketMsg.setData(jsonString); +// String json = JSON.toJSONString(socketMsg); +// +// NettyClient.socketClient(ip, port, "{\"data\":\"{\\\"deviceList\\\":[{\\\"devIP\\\":\\\"192.168.1.186\\\",\\\"port\\\":102,\\\"devType\\\":\\\"PQS882B\\\",\\\"icdType\\\":\\\"PQS882_VX_ZJ_1(V102)\\\",\\\"devCode\\\":\\\"Pqs\\u0026cn870299\\\",\\\"devKey\\\":\\\"!qaz@wsx3edc4rfv\\\",\\\"monitorList\\\":[{\\\"lineId\\\":\\\"1_192.168.1.186_102_1\\\",\\\"line\\\":1}]}]}\",\"operateCode\":\"INIT_GATHER$03\",\"requestId\":\"dansldquiwdlandalksn\"}", new NettySourceClientHandler(param.getUserPageId(), sourceResponseService)); + Runnable runnable = new Runnable() { + @Override + public void run() { +// NettyClient.socketClient(ip, port, "源客户端初始化发送", new NettySourceClientHandler(ip + "_" + port, sourceResponseService)); } - if(Objects.nonNull(channel)){ - try { - channel.writeAndFlush(tem).sync(); - } catch (InterruptedException e) { - System.out.println("发送异常====="); - e.printStackTrace(); - throw new RuntimeException(e); - } - } - } - }; - runnable.run(); + }; + runnable.run(); + System.out.println("111111111111111111111+++++++++++++++"); +// Runnable runnable2 = new Runnable() { +// @Override +// public void run() { +// NettyClient.socketClient(ip, 61001, "装置客户端初始化发送", new NettySourceClientHandler(ip + "_" + 61001, sourceResponseService2)); +// } +// }; +// runnable2.run(); - return true; + String tem = "{\"data\":\"{\\\"deviceList\\\":[{\\\"devIP\\\":\\\"192.168.1.186\\\",\\\"port\\\":102,\\\"devType\\\":\\\"PQS882B\\\",\\\"icdType\\\":\\\"PQS882_VX_ZJ_1(V102)\\\",\\\"devCode\\\":\\\"Pqs\\u0026cn870299\\\",\\\"devKey\\\":\\\"!qaz@wsx3edc4rfv\\\",\\\"monitorList\\\":[{\\\"lineId\\\":\\\"1_192.168.1.186_102_1\\\",\\\"line\\\":1}]}]}\",\"operateCode\":\"INIT_GATHER$03\",\"requestId\":\"dansldquiwdlandalksn\"}"; + + + return false; } + +// public static void main(String[] args) { +// NettyClient.socketClient("192.168.1.121", 61000, "源客户端初始化发送", new NettySourceClientHandler( "192.168.1.121_61000")); +// } } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/MsgUtil.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/MsgUtil.java index 0d6357e5..d013a75e 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/MsgUtil.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/MsgUtil.java @@ -12,7 +12,7 @@ import com.njcn.gather.detection.pojo.vo.SocketDataMsg; public class MsgUtil { - public SocketDataMsg socketDataMsg(String textMsg){ + public static SocketDataMsg socketDataMsg(String textMsg){ return JSON.parseObject(textMsg,SocketDataMsg.class); } } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java index c23fbac9..1818942a 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/SocketManager.java @@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentHashMap; * @Date: 2024/12/11 13:04 */ public class SocketManager { + private static final Map userSessions = new ConcurrentHashMap<>(); public static void addUser(String userId, Channel channel) { @@ -28,8 +29,7 @@ public class SocketManager { public static void sendMsg(String userId,String msg) { Channel channel = userSessions.get(userId); - TextWebSocketFrame wd1 = new TextWebSocketFrame(msg); - channel.writeAndFlush(wd1); + channel.writeAndFlush(msg); } } \ No newline at end of file diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java index 62365170..f4957930 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java @@ -9,7 +9,6 @@ import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.codec.LineBasedFrameDecoder; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; import io.netty.handler.timeout.TimeoutException; @@ -18,7 +17,6 @@ import io.netty.util.CharsetUtil; import java.io.IOException; import java.net.ConnectException; import java.net.ProtocolException; -import java.net.SocketTimeoutException; import java.util.concurrent.TimeUnit; /** @@ -29,11 +27,9 @@ import java.util.concurrent.TimeUnit; public class NettyClient { - public static Channel socketClient(String ip, Integer port,String userId, ChannelHandler handler) { + public static void socketClient(String ip, Integer port,String userId, ChannelHandler handler) { NioEventLoopGroup group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); - Channel channel = null; - try { bootstrap.group(group) .channel(NioSocketChannel.class) @@ -81,14 +77,10 @@ public class NettyClient { } }); ChannelFuture channelFuture = bootstrap.connect(ip, port).sync(); - channel = channelFuture.channel(); - SocketManager.addUser(userId,channel); - return channel; + SocketManager.addUser(userId,channelFuture.channel()); } catch (Exception e) { System.out.println("进入异常............"); e.printStackTrace(); - return null; - }finally { System.out.println("进入clientSocket最后步骤---------------------"); } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java index 2663918e..e3ae2153 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettySourceClientHandler.java @@ -2,13 +2,10 @@ package com.njcn.gather.detection.util.socket.cilent; import com.njcn.gather.detection.handler.SocketSourceResponseService; import com.njcn.gather.detection.util.socket.SocketManager; -import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import java.util.Objects; /** @@ -24,13 +21,6 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler devIds; + + @ApiModelProperty("是否是相序校验") + private Boolean isPhaseSequence; + @ApiModelProperty("源id") private String sourceId ="111"; } diff --git a/device/src/main/java/com/njcn/gather/device/script/pojo/po/PqScriptDtls.java b/device/src/main/java/com/njcn/gather/device/script/pojo/po/PqScriptDtls.java index 979d4c4c..a039cf13 100644 --- a/device/src/main/java/com/njcn/gather/device/script/pojo/po/PqScriptDtls.java +++ b/device/src/main/java/com/njcn/gather/device/script/pojo/po/PqScriptDtls.java @@ -28,6 +28,7 @@ public class PqScriptDtls implements Serializable { /** * 总检测脚本中的测试项序号 */ + @TableField("Index") private Integer index; /** @@ -88,6 +89,7 @@ public class PqScriptDtls implements Serializable { /** * 状态:0-不启用 1-启用 */ + @TableField("Enable") private Integer enable; } diff --git a/device/src/main/java/com/njcn/gather/device/script/service/impl/PqScriptDtlsServiceImpl.java b/device/src/main/java/com/njcn/gather/device/script/service/impl/PqScriptDtlsServiceImpl.java index d2ef1149..aefa6b3b 100644 --- a/device/src/main/java/com/njcn/gather/device/script/service/impl/PqScriptDtlsServiceImpl.java +++ b/device/src/main/java/com/njcn/gather/device/script/service/impl/PqScriptDtlsServiceImpl.java @@ -1,6 +1,7 @@ package com.njcn.gather.device.script.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.yulichang.wrapper.MPJLambdaWrapper; @@ -16,6 +17,7 @@ import com.njcn.gather.device.script.pojo.po.SourceIssue; import com.njcn.gather.device.script.service.IPqScriptDtlsService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,6 +42,20 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl list = pqDevService.list(new LambdaQueryWrapper() .eq(PqDev::getPlanId, param.getPlanId()) + .in(PqDev::getId, param.getDevIds()) .eq(PqDev::getState, DataStateEnum.ENABLE.getCode()) ); //额定电压信息 @@ -98,7 +115,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl pqScriptDtls = this.pqScriptDtls(param.getScriptId(), volt, curr); + List pqScriptDtls = this.pqScriptDtls(param.getScriptId(),param.getIsPhaseSequence(), volt, curr); if (CollUtil.isNotEmpty(pqScriptDtls)) { /** * 1.获取全部检测点脚本 @@ -134,10 +151,15 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl dtlsVList = value.stream().filter(x -> HARM_V.equals(x.getValueType()) || INHARM_V.equals(x.getValueType())) + List dtlsVList = value.stream().filter(x -> HARM_V.equals(x.getValueType()) || + INHARM_V.equals(x.getValueType()) || + DIP.equals(x.getValueType()) || + FLICKER.equals(x.getValueType()) + + ) .sorted(Comparator.comparing(PqScriptDtls::getPhase)) .collect(Collectors.toList()); - issueAdd(volList, dtlsVList, HARM_V, INHARM_V, "U", channelListDTOS); + issueAdd(volList, dtlsVList, HARM_V, INHARM_V, freqDtls.getValue(), "U", channelListDTOS); //2.通道电流(ABC) List curList = value.stream().filter(x -> CUR.equals(x.getValueType())) @@ -147,9 +169,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl dtlsIList = value.stream().filter(x -> HARM_I.equals(x.getValueType()) || HARM_I.equals(x.getValueType())) .sorted(Comparator.comparing(PqScriptDtls::getPhase)) .collect(Collectors.toList()); - issueAdd(curList, dtlsIList, HARM_I, INHARM_I, "I", channelListDTOS); + issueAdd(curList, dtlsIList, HARM_I, INHARM_I, freqDtls.getValue(), "I", channelListDTOS); - //todo 暂降和闪变没写 issue.setChannelList(channelListDTOS); sourceIssues.add(issue); } @@ -161,20 +182,29 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl pqScriptDtls(String scriptId, Float volt, Float curr) { - //先获取检测脚本类型是否相对值 true相对值 false绝对值(相对值要乘额定值,绝对值不需要处理) - Boolean isValueType = pqScriptMapper.selectScriptIsValueType(scriptId); - List pqScriptDtls = this.listPqScriptDtlByScriptId(scriptId); - if (isValueType) { - for (PqScriptDtls pqScriptDtl : pqScriptDtls) { - if (VOL.equals(pqScriptDtl.getValueType())) { - pqScriptDtl.setValue(pqScriptDtl.getChagValue() * volt); - } - if (CUR.equals(pqScriptDtl.getValueType())) { - pqScriptDtl.setValue(pqScriptDtl.getChagValue() * curr); + private List pqScriptDtls(String scriptId,Boolean isPhaseSequence,Float volt, Float curr) { + List pqScriptDtls; + if(isPhaseSequence){ + pqScriptDtls = this.list(new MPJLambdaWrapper() + .eq(PqScriptDtls::getIndex, -1) + .eq(PqScriptDtls::getEnable, 1) + ); + }else{ + //先获取检测脚本类型是否相对值 true相对值 false绝对值(相对值要乘额定值,绝对值不需要处理) + Boolean isValueType = pqScriptMapper.selectScriptIsValueType(scriptId); + pqScriptDtls = this.listPqScriptDtlByScriptId(scriptId); + if (isValueType) { + for (PqScriptDtls pqScriptDtl : pqScriptDtls) { + if (VOL.equals(pqScriptDtl.getValueType())) { + pqScriptDtl.setValue(pqScriptDtl.getChagValue() * volt); + } + if (CUR.equals(pqScriptDtl.getValueType())) { + pqScriptDtl.setValue(pqScriptDtl.getChagValue() * curr); + } } } } + return pqScriptDtls; } @@ -184,6 +214,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl dtlsList, - List dtlsOtherList, - String harm, - String inHarm, - String code, - List channelListDTOS) { + private void issueAdd(List dtlsList, + List dtlsOtherList, + String harm, + String inHarm, + Float fFreq, + String code, + List channelListDTOS) { for (PqScriptDtls dtls : dtlsList) { SourceIssue.ChannelListDTO channelListDTO = new SourceIssue.ChannelListDTO(); channelListDTO.setChannelFlag(true); @@ -212,20 +244,26 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl phaseList = dtlsOtherList.stream().filter(x -> dtls.getPhase().equals(x.getPhase())) .sorted(Comparator.comparing(PqScriptDtls::getHarmNum)) @@ -238,7 +276,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl inHarmList = phaseList.stream().filter(x -> inHarm.equals(x.getValueType())) .collect(Collectors.toList()); if (CollUtil.isNotEmpty(inHarmList)) { @@ -251,11 +289,8 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl flickeRList = phaseList.stream().filter(x -> FLICKER.equals(x.getValueType())) .collect(Collectors.toList()); if (CollUtil.isNotEmpty(flickeRList)) { - PqScriptDtls flicke = flickeRList.get(0); - flickerDataDTO.setWaveFluType(null); - flickerDataDTO.setWaveType(null); - flickerDataDTO.setFDutyCycle(0.0f); - flickerDataDTO.setFChagFre(0.0f); - flickerDataDTO.setFChagValue(0.0f); + PqScriptDtls flicker = flickeRList.get(0); + + flickerDataDTO.setFChagFre(flicker.getChagFre()); + flickerDataDTO.setFChagValue(flicker.getChagValue()); + channelListDTO.setFlickerFlag(true); channelListDTO.setFlickerData(flickerDataDTO); } @@ -285,7 +319,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl getHarmModels(List phaseHarmVList) { + private List getHarmModels(List phaseHarmVList) { List info = new ArrayList<>(); SourceIssue.ChannelListDTO.HarmModel harmModel; for (PqScriptDtls pqScriptDtls : phaseHarmVList) { @@ -304,7 +338,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl getInHarmModels(List phaseHarmVList) { + private List getInHarmModels(List phaseHarmVList) { List info = new ArrayList<>(); SourceIssue.ChannelListDTO.InharmModel inHarmModel; for (PqScriptDtls pqScriptDtls : phaseHarmVList) { diff --git a/entrance/src/main/resources/application.yml b/entrance/src/main/resources/application.yml index 29bd65c1..16d15e73 100644 --- a/entrance/src/main/resources/application.yml +++ b/entrance/src/main/resources/application.yml @@ -45,15 +45,31 @@ mybatis-plus: socket: source: - ip: 192.168.1.138 + ip: 192.168.1.121 port: 61000 device: ip: 192.168.1.127 - port: 7777 + port: 8574 webSocket: port: 7777 +#源参数下发,暂态数据默认值 +Dip: + #暂态前时间(s) + fPreTime: 2f + #写入时间(s) + fRampIn: 0.001f + #写出时间(s) + fRampOut: 0.001f + #暂态后时间(s) + fAfterTime: 3f + + +Flicker: + waveFluType: SQU + waveType: CPM + fDutyCycle: 50f log: homeDir: D:\logs