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 79958a7e..95422970 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 @@ -282,7 +282,7 @@ public class SocketDevResponseService { webSocketVO.setOperateCode(SourceOperateCodeEnum.DATA_CHNFACTOR$02.getValue()); webSocketVO.setData(coefficientVO); - WebServiceManager.sendMessage(param.getUserPageId(),webSocketVO); + WebServiceManager.sendMessage(param.getUserPageId(), webSocketVO); }); DevXiNumData devXiNumData = new DevXiNumData(); devXiNumData.setChnNum(0); @@ -417,7 +417,7 @@ public class SocketDevResponseService { } break; case UNPROCESSED_BUSINESS: - WebServiceManager.sendMsg(param.getUserPageId(),JSON.toJSONString(socketDataMsg)); + WebServiceManager.sendMsg(param.getUserPageId(), JSON.toJSONString(socketDataMsg)); break; case NORMAL_RESPONSE: realDataXiList.add(devData); @@ -455,12 +455,12 @@ public class SocketDevResponseService { return percentage <= limit; } - private BigDecimal rangeNum(double num1, double num2,String type) { + private BigDecimal rangeNum(double num1, double num2, String type) { double diff = Math.abs(num1 - num2); double larger = Math.max(num1, num2); - if(DicDataEnum.V.getCode().equals(type)){ + if (DicDataEnum.V.getCode().equals(type)) { return BigDecimal.valueOf(num1 - num2).setScale(4, RoundingMode.HALF_UP); - }else { + } else { return BigDecimal.valueOf(diff / larger).multiply(BigDecimal.valueOf(100)).setScale(4, RoundingMode.HALF_UP); } } @@ -524,12 +524,12 @@ public class SocketDevResponseService { coefficientVO.setBIeXi(isWithinTenPercent(optionalIB, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格"); coefficientVO.setCIeXi(isWithinTenPercent(optionalIC, devParameter.getDevCurr(), iLimit) ? "合格" : "不合格"); - coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(),DicDataEnum.V.getCode()).toString()); - coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(),DicDataEnum.V.getCode()).toString()); - coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(),DicDataEnum.V.getCode()).toString()); - coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(),DicDataEnum.I.getCode()).toString()); - coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(),DicDataEnum.I.getCode()).toString()); - coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(),DicDataEnum.I.getCode()).toString()); + coefficientVO.setAV(rangeNum(optionalA, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString()); + coefficientVO.setBV(rangeNum(optionalB, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString()); + coefficientVO.setCV(rangeNum(optionalC, devParameter.getDevVolt(), DicDataEnum.V.getCode()).toString()); + coefficientVO.setAI(rangeNum(optionalIA, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString()); + coefficientVO.setBI(rangeNum(optionalIB, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString()); + coefficientVO.setCI(rangeNum(optionalIC, devParameter.getDevCurr(), DicDataEnum.I.getCode()).toString()); if ("不合格".equals(coefficientVO.getAVuXi()) || "不合格".equals(coefficientVO.getBVuXi()) || "不合格".equals(coefficientVO.getCVuXi()) || "不合格".equals(coefficientVO.getAIeXi()) || "不合格".equals(coefficientVO.getBIeXi()) || "不合格".equals(coefficientVO.getCIeXi())) { coefficientVO.setResultFlag(0); @@ -906,9 +906,7 @@ public class SocketDevResponseService { } - - - Map> targetTestMap = new HashMap<>(); + Map> targetTestMap = new HashMap<>(); /** * 正式检测 @@ -939,7 +937,7 @@ public class SocketDevResponseService { Map textResult = detectionServiceImpl.processing(realDataXiList, param, FormalTestManager.devIdMapComm, sourceIssue, dataRule); //组装实体推送给前台 - assWebJson(param,textResult,socketDataMsg,sourceIssue); + assWebJson(param, textResult, socketDataMsg, sourceIssue); //当小项结束后需要删除集合中的小项 SocketManager.delSource(sourceIssue.getIndex()); @@ -967,7 +965,7 @@ public class SocketDevResponseService { resultList.add(devTem); }); allDevTestList.clear(); - CnSocketUtil.sendToWebSocket(param.getUserPageId(),socketDataMsg.getRequestId().split(stepTag)[1] + stepEnd,null,resultList,null); + CnSocketUtil.sendToWebSocket(param.getUserPageId(), socketDataMsg.getRequestId().split(stepTag)[1] + stepEnd, null, resultList, null); } //在这一步判断是否已经触发暂停按钮 @@ -985,7 +983,7 @@ public class SocketDevResponseService { if (CollUtil.isNotEmpty(sourceIssueList)) { SourceIssue sourceIssues = SocketManager.getSourceList().get(0); if (residueCount == 0) { - CnSocketUtil.sendToWebSocket(param.getUserPageId(),sourceIssues.getType() + stepBegin,null,new ArrayList<>(),null); + CnSocketUtil.sendToWebSocket(param.getUserPageId(), sourceIssues.getType() + stepBegin, null, new ArrayList<>(), null); } SocketMsg xuMsg = new SocketMsg<>(); @@ -1036,7 +1034,7 @@ public class SocketDevResponseService { /** * 组装实体推送给前端 */ - private void assWebJson(PreDetectionParam param,Map textResult,SocketDataMsg socketDataMsg,SourceIssue sourceIssue){ + private void assWebJson(PreDetectionParam param, Map textResult, SocketDataMsg socketDataMsg, SourceIssue sourceIssue) { List devListRes = new ArrayList<>(); FormalTestManager.devList.forEach(dev -> { DevLineTestResult devLineTestResult = new DevLineTestResult(); @@ -1053,11 +1051,11 @@ public class SocketDevResponseService { devListRes.add(devLineTestResult); }); - if(targetTestMap.containsKey(sourceIssue.getType())){ + if (targetTestMap.containsKey(sourceIssue.getType())) { List devLineTestResultList = targetTestMap.get(sourceIssue.getType()); devLineTestResultList.addAll(devListRes); - }else { - targetTestMap.put(sourceIssue.getType(),devListRes); + } else { + targetTestMap.put(sourceIssue.getType(), devListRes); } WebSocketVO> webSocketVO = new WebSocketVO<>(); @@ -1077,15 +1075,15 @@ public class SocketDevResponseService { int maxValue = -1; for (Integer[] array : arrays) { int value = array[i]; - if(value != 4) { + if (value != 4) { if (value > maxValue) { maxValue = value; } } } - if(maxValue == -1){ + if (maxValue == -1) { maxArray[i] = 4; - }else { + } else { maxArray[i] = maxValue; } } @@ -1190,7 +1188,7 @@ public class SocketDevResponseService { private List devIsSource(List dev, SourceIssue issue) { List info = new ArrayList<>(); - //相序校验信息个 + //相序校验信息 LinkedHashMap> devMap = dev.stream() .sorted(Comparator.comparing(DevData::getId)) .collect(Collectors.groupingBy(DevData::getId, LinkedHashMap::new, Collectors.toList())); @@ -1203,11 +1201,13 @@ public class SocketDevResponseService { .sorted(Comparator.comparing(SourceIssue.ChannelListDTO::getChannelType)) .collect(Collectors.toList()); Map sourceMessageMap = sourceMessage(issue); - List v = Arrays.asList("VRMS", "VA", "U", "V","电压"); - List i = Arrays.asList("IRMS", "IA", "I", "I","电流"); + List v = Arrays.asList("VRMS", "VA", "U", "V", "电压"); + List i = Arrays.asList("IRMS", "IA", "I", "I", "电流"); devMap.forEach((key, value) -> { List sqlData = value.stream().flatMap(x -> x.getSqlData().stream()).collect(Collectors.toList()); + //电压 getResult(key, sqlData, sourceMessageMap, sourceV, info, v); + //电流 getResult(key, sqlData, sourceMessageMap, sourceI, info, i); }); return info; @@ -1259,7 +1259,7 @@ public class SocketDevResponseService { Boolean b = getaBoolean(sourceMap.get(type + "b"), data.get(0).getList().getB(), dataPhase.get(0).getList().getB()); Boolean c = getaBoolean(sourceMap.get(type + "c"), data.get(0).getList().getC(), dataPhase.get(0).getList().getC()); compareDev.setIsQualified(a && b && c); - compareDev.setDesc(name + (compareDev.getIsQualified() ? "合格->" : "不合格->") +stepTag + desc + stepTag + devMessage(type, data, dataPhase)); + compareDev.setDesc(name + (compareDev.getIsQualified() ? "合格->" : "不合格->") + stepTag + desc + stepTag + devMessage(type, data, dataPhase)); return compareDev; } @@ -1268,7 +1268,28 @@ public class SocketDevResponseService { BigDecimal.valueOf(channelListDTO.getFAmp() * 0.95), BigDecimal.valueOf(channelListDTO.getFAmp() * 1.05)) && - NumberUtil.isIn(BigDecimal.valueOf(devPhase), + phaseBoolean(channelListDTO, devPhase); + + } + + /** + * 判断相角(-180° ~ 180°) + * (+360° ~ -360°) + * + * @param channelListDTO 源下发角度 + * @param devPhase 装置返回角度 + * @return + */ + private static Boolean phaseBoolean(SourceIssue.ChannelListDTO channelListDTO, Double devPhase) { + Double phase = devPhase; + if (devPhase < -180) { + phase = devPhase + 360; + } + if (devPhase > 180) { + phase = devPhase - 360; + } + return + NumberUtil.isIn(BigDecimal.valueOf(phase), BigDecimal.valueOf(channelListDTO.getFPhase() - 1), BigDecimal.valueOf(channelListDTO.getFPhase() + 1)); @@ -1552,7 +1573,7 @@ public class SocketDevResponseService { } public void backCheckState(PreDetectionParam param) { - if (CollUtil.isNotEmpty(param.getDevIds()) && StrUtil.isNotBlank(param.getPlanId())&&"1".equals(param.getOperateType())) { + if (CollUtil.isNotEmpty(param.getDevIds()) && StrUtil.isNotBlank(param.getPlanId()) && "1".equals(param.getOperateType())) { adPlanService.updateBackTestState(param.getPlanId(), param.getDevIds()); } }