代码调整
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
package com.njcn.gather.detection.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.po.DevData;
|
||||
import com.njcn.gather.detection.service.PreDetectionService;
|
||||
import com.njcn.gather.detection.service.impl.DetectionServiceImpl;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.device.device.pojo.vo.PreDetection;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
|
||||
import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -14,6 +24,11 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "预检测")
|
||||
@@ -24,6 +39,12 @@ public class PreDetectionController extends BaseController {
|
||||
|
||||
private final PreDetectionService preDetectionService;
|
||||
|
||||
private final DetectionServiceImpl detectionServiceImpl;
|
||||
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
|
||||
private final IPqDevService iPqDevService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,7 +85,44 @@ public class PreDetectionController extends BaseController {
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<String> startTest(@RequestBody PreDetectionParam param){
|
||||
String methodDescribe = getMethodDescribe("startTest");
|
||||
preDetectionService.startTest(param);
|
||||
//preDetectionService.startTest(param);
|
||||
|
||||
String a = "{\"Time\":\"2025-01-02T14:14:44.958\",\"ID\":\"192.168.1.186_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.035600\"}}],\"SqlDataHarm\":[]}";
|
||||
String b = "{\"Time\":\"2025-01-02T14:14:39.004\",\"ID\":\"192.168.1.203_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
String c = "{\"Time\":\"2025-01-02T14:14:39.004\",\"ID\":\"192.168.1.203_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
String d = "{\"Time\":\"2025-01-02T14:14:47.956\",\"ID\":\"192.168.1.186_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.032300\"}}],\"SqlDataHarm\":[]}";
|
||||
String e = "{\"Time\":\"2025-01-02T14:14:42.004\",\"ID\":\"192.168.1.203_1\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
String f = "{\"Time\":\"2025-01-02T14:14:42.004\",\"ID\":\"192.168.1.203_2\",\"result\":false,\"SqlData\":[{\"type\":\"real\",\"desc\":\"FREQ\",\"list\":{\"A\":null,\"B\":null,\"C\":null,\"T\":\"50.000000\"}}],\"SqlDataHarm\":[]}";
|
||||
|
||||
List<DevData> devDataList = new ArrayList<>();
|
||||
DevData aa = JSON.parseObject(a, DevData.class);
|
||||
DevData bb = JSON.parseObject(a, DevData.class);
|
||||
DevData cc = JSON.parseObject(a, DevData.class);
|
||||
DevData dd = JSON.parseObject(a, DevData.class);
|
||||
DevData ee = JSON.parseObject(a, DevData.class);
|
||||
DevData ff = JSON.parseObject(a, DevData.class);
|
||||
devDataList.add(aa);
|
||||
devDataList.add(bb);
|
||||
devDataList.add(cc);
|
||||
devDataList.add(dd);
|
||||
devDataList.add(ee);
|
||||
devDataList.add(ff);
|
||||
|
||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||
issueParam.setPlanId(param.getPlanId());
|
||||
issueParam.setSourceId(param.getSourceId());
|
||||
issueParam.setDevIds(param.getDevIds());
|
||||
issueParam.setScriptId("a303b2224845fcc6f60198b8ca23dca9");
|
||||
issueParam.setIsPhaseSequence(false);
|
||||
SourceIssue sourceIssues = pqScriptDtlsService.listSourceIssue(issueParam).get(0);
|
||||
|
||||
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
Map<String, String> devIdMapComm = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, PreDetection::getDevId));
|
||||
|
||||
detectionServiceImpl.text(devDataList,param.getErrorSysId(),devIdMapComm,sourceIssues, DictDataEnum.AT_WILL_VALUE);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.njcn.gather.device.script.pojo.po.SourceIssue;
|
||||
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
|
||||
import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
|
||||
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
|
||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -54,6 +55,8 @@ public class SocketDevResponseService {
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
private final DetectionServiceImpl detectionServiceImpl;
|
||||
|
||||
private final DetectionDataDealService detectionDataDealService;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -99,7 +102,7 @@ public class SocketDevResponseService {
|
||||
List<AdNonHarmonicResult> adNonHarmonicResultList = new ArrayList<>();
|
||||
|
||||
|
||||
public void deal(PreDetectionParam param, String msg) {
|
||||
public void deal(PreDetectionParam param, String msg) throws Exception{
|
||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||
String[] tem = socketDataMsg.getRequestId().split("&&");
|
||||
|
||||
@@ -455,12 +458,16 @@ public class SocketDevResponseService {
|
||||
System.out.println(flag);
|
||||
|
||||
long tem = SocketManager.getSourceTarget(sourceIssue.getType()) - 1;
|
||||
SocketManager.addTargetMap(sourceIssue.getSubType(), tem);
|
||||
SocketManager.addTargetMap(sourceIssue.getType(), tem);
|
||||
|
||||
System.out.println("该大项还有"+tem+"个小项没有进行检测!!!!!!!!");
|
||||
|
||||
if (tem == 0) {
|
||||
System.out.println(sourceIssue.getType() + sourceIssue.getIndex() + "当前测试大项已经全部结束》》》》》》》》");
|
||||
|
||||
|
||||
baseDataInsert(devDataList,sourceIssue,param);
|
||||
|
||||
//当val为0则认为大项中的小项已经全部跑完,开始组装信息推送给前端
|
||||
WebSocketVO<List<DevLineTestResult>> webSocketVO = new WebSocketVO<>();
|
||||
webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1] + "_End");
|
||||
@@ -738,7 +745,7 @@ public class SocketDevResponseService {
|
||||
* @author cdf
|
||||
* @date 2024/12/29
|
||||
*/
|
||||
private void baseDataInsert(List<DevData> devDataList,Integer index,PreDetectionParam param){
|
||||
private void baseDataInsert(List<DevData> devDataList,SourceIssue sourceIssue,PreDetectionParam param){
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -753,14 +760,15 @@ public class SocketDevResponseService {
|
||||
adNonHarmonicResult.setTimeId(localDateTime);
|
||||
adNonHarmonicResult.setMonitorId(data.getId());
|
||||
adNonHarmonicResult.setScriptId(param.getScriptId());
|
||||
adNonHarmonicResult.setIndex(index);
|
||||
adNonHarmonicResult.setSort(sourceIssue.getIndex());
|
||||
adNonHarmonicResult.setAdType(sourceIssue.getSourceId());
|
||||
adNonHarmonicResult.setAValue(data.getSqlData().get(0).getList().getA().toString());
|
||||
adNonHarmonicResult.setBValue(data.getSqlData().get(0).getList().getB().toString());
|
||||
adNonHarmonicResult.setCValue(data.getSqlData().get(0).getList().getC().toString());
|
||||
adHarmonicResultList.add(adNonHarmonicResult);
|
||||
}
|
||||
}
|
||||
//detectionDataDealService.acceptAdNon(adHarmonicResultList,"1");
|
||||
detectionDataDealService.acceptAdNon(adHarmonicResultList,"1");
|
||||
}
|
||||
};
|
||||
runnable.run();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SocketSourceResponseService {
|
||||
|
||||
|
||||
|
||||
public void deal(PreDetectionParam param, String msg) {
|
||||
public void deal(PreDetectionParam param, String msg) throws Exception {
|
||||
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
|
||||
String[] tem = socketDataMsg.getRequestId().split("&&");
|
||||
SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(tem[0]);
|
||||
@@ -90,7 +90,7 @@ public class SocketSourceResponseService {
|
||||
private void detectionDev(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
@@ -114,7 +114,7 @@ public class SocketSourceResponseService {
|
||||
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
|
||||
break;
|
||||
default:
|
||||
socketMsg = new SocketMsg();
|
||||
socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(socketDataMsg.getRequestId());
|
||||
socketMsg.setOperateCode(socketDataMsg.getOperateCode());
|
||||
socketMsg.setData(dictDataEnumByCode.getMessage());
|
||||
@@ -133,7 +133,7 @@ public class SocketSourceResponseService {
|
||||
private void phaseSequenceDev(PreDetectionParam param, SocketDataMsg socketDataMsg) {
|
||||
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
|
||||
if (ObjectUtil.isNotNull(dictDataEnumByCode)) {
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
SocketMsg<String> socketMsg = new SocketMsg();
|
||||
switch (dictDataEnumByCode) {
|
||||
case SUCCESS:
|
||||
//向前端推送信息
|
||||
@@ -196,7 +196,7 @@ public class SocketSourceResponseService {
|
||||
System.out.println("向装置下发的参数"+comm);
|
||||
phaseSequenceParam.setMoniterIdList(moniterIdList);
|
||||
phaseSequenceParam.setDataType(Arrays.asList(comm));
|
||||
phaseSequenceParam.setReadCount(5);
|
||||
phaseSequenceParam.setReadCount(2);
|
||||
phaseSequenceParam.setIgnoreCount(10);
|
||||
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
|
||||
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
|
||||
|
||||
@@ -208,7 +208,7 @@ public class DetectionServiceImpl {
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
result.setMonitorId(devID + "_" + split[1]);
|
||||
result.setScriptId(sourceIssue.getScriptId());
|
||||
result.setIndex(sourceIssue.getIndex());
|
||||
result.setSort(sourceIssue.getIndex());
|
||||
result.setAdType(pqErrSysDtls.get(0).getScriptType());
|
||||
result.setDataType("avg");
|
||||
if (map.containsKey(TYPE_T)) {
|
||||
@@ -275,7 +275,7 @@ public class DetectionServiceImpl {
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
harmonicResult.setMonitorId(devID + "_" + split[1]);
|
||||
harmonicResult.setScriptId(sourceIssue.getScriptId());
|
||||
harmonicResult.setIndex(sourceIssue.getIndex());
|
||||
harmonicResult.setSort(sourceIssue.getIndex());
|
||||
harmonicResult.setAdType(pqErrSysDtls.get(0).getScriptType());
|
||||
harmonicResult.setDataType("avg");
|
||||
reflectHarmonic("a", integerBooleanA, harmonicResult);
|
||||
@@ -324,7 +324,7 @@ public class DetectionServiceImpl {
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
result.setMonitorId(devID + "_" + split[1]);
|
||||
result.setScriptId(sourceIssue.getScriptId());
|
||||
result.setIndex(sourceIssue.getIndex());
|
||||
result.setSort(sourceIssue.getIndex());
|
||||
result.setAdType(pqErrSysDtls.get(0).getScriptType());
|
||||
result.setDataType("avg");
|
||||
//取出源所对应的相别信息
|
||||
@@ -418,7 +418,7 @@ public class DetectionServiceImpl {
|
||||
String devID = devIdMapComm.get(split[0]);
|
||||
result.setMonitorId(devID + "_" + split[1]);
|
||||
result.setScriptId(sourceIssue.getScriptId());
|
||||
result.setIndex(sourceIssue.getIndex());
|
||||
result.setSort(sourceIssue.getIndex());
|
||||
result.setDataType("avg");
|
||||
//取出源所对应的相别信息
|
||||
List<SourceIssue.ChannelListDTO> channelTypeAList = sourceIssue.getChannelList().stream()
|
||||
|
||||
@@ -69,8 +69,10 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
public void sourceCommunicationCheck(PreDetectionParam param) {
|
||||
|
||||
|
||||
System.out.println("进来了啊啊啊啊啊啊啊啊啊啊啊啊啊");
|
||||
System.out.println("进来了啊啊啊啊啊啊啊啊啊啊啊啊啊----------------------------------------------------------------");
|
||||
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source);
|
||||
System.out.println("存活的源=========================="+channel);
|
||||
|
||||
if (Objects.nonNull(channel) && channel.isActive()) {
|
||||
System.out.println("进入关闭源。。//////");
|
||||
SocketDataMsg socketDataMsg = new SocketDataMsg();
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.gather.detection.util.socket;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
|
||||
/**
|
||||
* @Author: cdf
|
||||
* @CreateTime: 2025-01-02
|
||||
* @Description: 工具类
|
||||
*/
|
||||
public class CnSocketUtil {
|
||||
|
||||
private final static String handlerStr = "_Dev";
|
||||
private final static String handlerSourceStr = "_Source";
|
||||
|
||||
/**
|
||||
* 退出检测
|
||||
*/
|
||||
public static void quitSend(PreDetectionParam param) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.QUIT_INIT_03.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerStr, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭源连接
|
||||
*/
|
||||
public static void quitSendSource(PreDetectionParam param) {
|
||||
SocketMsg<String> socketMsg = new SocketMsg<>();
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||
SocketManager.sendMsg(param.getUserPageId() + handlerSourceStr, JSON.toJSONString(socketMsg));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,10 @@ package com.njcn.gather.detection.util.socket;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -16,6 +19,7 @@ import java.util.Map;
|
||||
public class MsgUtil {
|
||||
|
||||
|
||||
|
||||
public static SocketDataMsg socketDataMsg(String textMsg){
|
||||
return JSON.parseObject(textMsg,SocketDataMsg.class);
|
||||
}
|
||||
@@ -68,4 +72,5 @@ public class MsgUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.gather.detection.util.socket.cilent;
|
||||
|
||||
import com.njcn.gather.detection.handler.SocketDevResponseService;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -51,7 +52,12 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException {
|
||||
System.out.println("devhandler接收server端数据>>>>>>"+msg);
|
||||
socketResponseService.deal(param,msg);
|
||||
try {
|
||||
socketResponseService.deal(param,msg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CnSocketUtil.quitSend(param);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.util.socket.CnSocketUtil;
|
||||
import com.njcn.gather.detection.util.socket.MsgUtil;
|
||||
import com.njcn.gather.detection.util.socket.SocketManager;
|
||||
import io.netty.channel.Channel;
|
||||
@@ -51,7 +52,12 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException {
|
||||
System.out.println("接收server端数据>>>>>>" + msg);
|
||||
sourceResponseService.deal(webUser, msg);
|
||||
try {
|
||||
sourceResponseService.deal(webUser, msg);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CnSocketUtil.quitSend(webUser);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -90,7 +96,8 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<String
|
||||
ctx.writeAndFlush(MsgUtil.toJsonWithNewLinePlain(msg));
|
||||
}
|
||||
} else {
|
||||
userEventTriggered(ctx, evt);
|
||||
//防止堆栈溢出
|
||||
//userEventTriggered(ctx, evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user