From 97e009c84cb72e2dca993c767f995ef6c9d0ab4e Mon Sep 17 00:00:00 2001 From: chendaofei <857448963@qq.com> Date: Wed, 18 Dec 2024 16:19:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E7=BD=AE=E9=80=9A=E8=AE=AF=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/SocketDevResponseService.java | 175 +++++++++++++----- .../service/impl/PreDetectionServiceImpl.java | 7 + 2 files changed, 131 insertions(+), 51 deletions(-) diff --git a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java index 508f7daf..2e2ccd55 100644 --- a/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java +++ b/detection/src/main/java/com/njcn/gather/detection/handler/SocketDevResponseService.java @@ -54,26 +54,52 @@ public class SocketDevResponseService { /** * 装置名称 */ - Map devNameMap = new HashMap<>(); + Map devNameMap = new HashMap<>(); - public void deal(PreDetectionParam param,String msg){ + + /** + * 所有装置通道信息 + */ + List moniterIdListComm = new ArrayList<>(); + /** + * 成功结束的装置 + */ + List successComm = new ArrayList<>(); + /** + * 装置名称 + */ + Map devNameMapComm = new HashMap<>(); + + + /** + * 所有装置通道信息 + */ + List moniterIdListXieyi = new ArrayList<>(); + /** + * 成功结束的装置 + */ + List successXieyi = new ArrayList<>(); + /** + * 装置名称 + */ + Map devNameMapXieyi = new HashMap<>(); + + public void deal(PreDetectionParam param, String msg) { SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg); SourceOperateCodeEnum sourceOperateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getRequestId()); switch (sourceOperateCodeEnum) { case YJC_SBTXJY: - devComm(socketDataMsg,param,msg); + devComm(socketDataMsg, param, msg); break; case QUITE: SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); - String userKey = param.getUserPageId()+handlerStr; - switch (dictDataEnumByCode){ + String userKey = param.getUserPageId() + handlerStr; + switch (dictDataEnumByCode) { case SUCCESS: //通讯校验成功 webSocketHandler.sendMsgToUser(userKey, msg); - Channel channel = SocketManager.getChannelByUserId(userKey); - channel.close(); - SocketManager.removeUser(userKey); + break; case UNPROCESSED_BUSINESS: break; @@ -84,39 +110,45 @@ public class SocketDevResponseService { } break; case YJC_XYJY: - devXieyi(socketDataMsg,param,msg); + devXieyi(socketDataMsg, param, msg); break; case YJC_XUJY: break; } - } + private Map> reloverMap = new HashMap<>(); - - private void devComm(SocketDataMsg socketDataMsg,PreDetectionParam param,String msg){ + private void devComm(SocketDataMsg socketDataMsg, PreDetectionParam param, String msg) { SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); String s = param.getUserPageId() + handlerStr; - SocketMsg socketMsg=new SocketMsg(); - switch (dictDataEnumByCode){ + SocketMsg socketMsg = new SocketMsg(); + switch (dictDataEnumByCode) { case SUCCESS: //通讯校验成功 webSocketHandler.sendMsgToUser(param.getUserPageId(), msg); - //开始进行协议校验 - /* List devList = iPqDevService.getDevInfo(param.getDevIds()); - Map> map = new HashMap(1); - map.put("deviceList", devList); - String jsonString = JSON.toJSONString(map); - socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue()); - socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_02.getValue()); - socketMsg.setData(jsonString); - String json = JSON.toJSONString(socketMsg);*/ - // - System.out.println("开始协议校验++++++++++"); - //SocketManager.sendMsg(s,json); + String mId = JSON.parseObject(msg).get("data").toString(); + successComm.add(mId); + + System.out.println(successComm.size()+"====="+moniterIdListComm.size()); + if (successComm.size() == moniterIdListComm.size()) { + //开始进行协议校验 + List devList = iPqDevService.getDevInfo(param.getDevIds()); + Map> map = new HashMap(1); + map.put("deviceList", devList); + String jsonString = JSON.toJSONString(map); + socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue()); + socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_02.getValue()); + socketMsg.setData(jsonString); + String json = JSON.toJSONString(socketMsg); + + System.out.println("开始协议校验++++++++++"); + SocketManager.sendMsg(s, json); + } + break; case UNPROCESSED_BUSINESS: @@ -134,8 +166,11 @@ public class SocketDevResponseService { //发起关闭操作 socketMsg.setRequestId("quit"); socketMsg.setOperateCode("QUIT_FUNEND$01"); - SocketManager.sendMsg(s,JSON.toJSONString(socketMsg)); - + SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); + socketMsg.setOperateCode("QUIT_FUNEND$02"); + SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); + socketMsg.setOperateCode("QUIT_FUNEND$03"); + SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); break; default: WebSocketVO webSocketVO = new WebSocketVO(); @@ -146,18 +181,34 @@ public class SocketDevResponseService { } - private void devXieyi(SocketDataMsg socketDataMsg,PreDetectionParam param,String msg){ + private void devXieyi(SocketDataMsg socketDataMsg, PreDetectionParam param, String msg) { SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode()); - switch (dictDataEnumByCode){ + SocketMsg socketMsg = new SocketMsg(); + String s = param.getUserPageId() + handlerStr; + + switch (dictDataEnumByCode) { case SUCCESS: webSocketHandler.sendMsgToUser(param.getUserPageId(), msg); - String s = param.getUserPageId() + handlerStr; + System.out.println(successXieyi.size()+"====="+moniterIdListXieyi.size()); + String mId = JSON.parseObject(msg).get("data").toString(); + successXieyi.add(mId); + if (successXieyi.size() == moniterIdListXieyi.size()) { + //开始相序校验 + } break; case UNPROCESSED_BUSINESS: break; case RE_OPERATE: //发起关闭操作 + //发起关闭操作 + socketMsg.setRequestId("quit"); + socketMsg.setOperateCode("QUIT_FUNEND$01"); + SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); + socketMsg.setOperateCode("QUIT_FUNEND$02"); + SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); + socketMsg.setOperateCode("QUIT_FUNEND$03"); + SocketManager.sendMsg(s, JSON.toJSONString(socketMsg)); break; default: WebSocketVO webSocketVO = new WebSocketVO(); @@ -174,7 +225,7 @@ public class SocketDevResponseService { moniterIdList = pqDevList.stream().flatMap(x -> x.getMonitorList().stream()) .map(PreDetection.MonitorListDTO::getLineId) .collect(Collectors.toList()); - devNameMap = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, PreDetection::getDevName)); + devNameMap = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, PreDetection::getDevName)); // moniterIdList.add("192.168.1.186_1"); } @@ -188,9 +239,9 @@ public class SocketDevResponseService { case SUCCESS: success.add(devData.getId()); if (success.size() == moniterIdList.size()) { - PqScriptIssueParam sourceParam=new PqScriptIssueParam(); + PqScriptIssueParam sourceParam = new PqScriptIssueParam(); List sourceIssues = scriptDtlsService.listSourceIssue(sourceParam); - if(CollUtil.isNotEmpty(sourceIssues)){ + if (CollUtil.isNotEmpty(sourceIssues)) { List info = new ArrayList<>(); for (DevData dev : devInfo) { info.addAll(devIsSource(dev, sourceIssues.get(0))); @@ -235,7 +286,7 @@ public class SocketDevResponseService { // list.add(socketDataMsg); list.add(socketDataMsgb); - String is="\n" + + String is = "\n" + " {\n" + " \"sourceId\": \"1111\",\n" + " \"type\": \"Freq\",\n" + @@ -428,8 +479,8 @@ public class SocketDevResponseService { } - private List devIsSource(DevData dev, SourceIssue issue) { - List info=new ArrayList<>(); + private List devIsSource(DevData dev, SourceIssue issue) { + List info = new ArrayList<>(); String[] split = dev.getId().split("_"); List channelList = issue.getChannelList(); @@ -437,11 +488,11 @@ public class SocketDevResponseService { List dataV = sqlData.stream().filter(x -> "电压有效值".equals(x.getDesc())).collect(Collectors.toList()); List dataI = sqlData.stream().filter(x -> "电流有效值".equals(x.getDesc())).collect(Collectors.toList()); if (CollUtil.isNotEmpty(dataV)) { - SourceCompareDev compareDev = getSourceCompareDev(split, dataV,"电压有效值","U", channelList); + SourceCompareDev compareDev = getSourceCompareDev(split, dataV, "电压有效值", "U", channelList); info.add(compareDev); } if (CollUtil.isNotEmpty(dataI)) { - SourceCompareDev compareDev = getSourceCompareDev(split, dataI,"电流有效值","I", channelList); + SourceCompareDev compareDev = getSourceCompareDev(split, dataI, "电流有效值", "I", channelList); info.add(compareDev); } @@ -450,10 +501,11 @@ public class SocketDevResponseService { /** * 计算是否合格 + * * @param split * @param data - * @param name 指标名称 - * @param type U,I + * @param name 指标名称 + * @param type U,I * @param channelList * @return */ @@ -469,33 +521,33 @@ public class SocketDevResponseService { compareDev.setDesc(name); //装置数据 DevData.SqlDataDTO.ListDTO devData = data.get(0).getList(); - List sourceList = channelList.stream().filter(x -> (type+"a").equals(x.getChannelType()) || - (type+"b").equals(x.getChannelType()) || - (type+"c").equals(x.getChannelType()) + List sourceList = channelList.stream().filter(x -> (type + "a").equals(x.getChannelType()) || + (type + "b").equals(x.getChannelType()) || + (type + "c").equals(x.getChannelType()) ).collect(Collectors.toList()); Map sourceMap = sourceList.stream() .collect(Collectors.toMap(x -> x.getChannelType().toUpperCase().replace(type, "") , SourceIssue.ChannelListDTO::getFAmp)); - Map devMap =new HashMap<>(3); - devMap.put("A",devData.getA()); - devMap.put("B",devData.getB()); - devMap.put("C",devData.getC()); + Map devMap = new HashMap<>(3); + devMap.put("A", devData.getA()); + devMap.put("B", devData.getB()); + devMap.put("C", devData.getC()); Boolean is = true; for (SourceIssue.ChannelListDTO channelListDTO : sourceList) { if (!is) { break; } - if (channelListDTO.getChannelType().equals((type+"a"))) { + if (channelListDTO.getChannelType().equals((type + "a"))) { is = NumberUtil.isIn(BigDecimal.valueOf(devData.getA()), BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95), BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05)); } - if (channelListDTO.getChannelType().equals((type+"b"))) { + if (channelListDTO.getChannelType().equals((type + "b"))) { is = NumberUtil.isIn(BigDecimal.valueOf(devData.getB()), BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95), BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05)); } - if (channelListDTO.getChannelType().equals((type+"c"))) { + if (channelListDTO.getChannelType().equals((type + "c"))) { is = NumberUtil.isIn(BigDecimal.valueOf(devData.getC()), BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95), BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05)); @@ -509,4 +561,25 @@ public class SocketDevResponseService { } + /** + * 初始化集合 + */ + public void initList(PreDetectionParam param) { + this.moniterIdListComm = new ArrayList<>(); + this.successComm = new ArrayList<>(); + this.devNameMapComm = new HashMap<>(); + + this.moniterIdListXieyi = new ArrayList<>(); + this.successXieyi = new ArrayList<>(); + this.devNameMapXieyi = new HashMap<>(); + + List pqDevList = iPqDevService.getDevInfo(param.getDevIds()); + this.moniterIdListComm = pqDevList.stream().flatMap(x -> x.getMonitorList().stream()) + .map(PreDetection.MonitorListDTO::getLineId) + .collect(Collectors.toList()); + } + + + + } 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 e75bc7fa..e244efc3 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 @@ -4,6 +4,7 @@ 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.SocketDevResponseService; import com.njcn.gather.detection.handler.SocketSourceResponseService; import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum; import com.njcn.gather.detection.pojo.param.PreDetectionParam; @@ -45,6 +46,8 @@ public class PreDetectionServiceImpl implements PreDetectionService { private final IPqSourceService pqSourceService; private final IPqScriptDtlsService pqScriptDtlsService; + private final SocketDevResponseService socketDevResponseService; + @Value("${socket.source.ip}") private String ip; @@ -124,6 +127,10 @@ public class PreDetectionServiceImpl implements PreDetectionService { @Override public boolean startTest(PreDetectionParam param) { + socketDevResponseService.initList(param); + + + Runnable runnable = new Runnable() { @Override public void run() {