This commit is contained in:
2024-12-27 15:08:13 +08:00
parent 338e426017
commit 2b9cce41aa
7 changed files with 122 additions and 15 deletions

View File

@@ -6,8 +6,10 @@ import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.DevLineTestResult;
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
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;
@@ -19,10 +21,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -46,9 +45,14 @@ public class SocketSourceResponseService {
@Value("${socket.device.port}")
private Integer port;
private List<PreDetection> devList = new ArrayList<>();
public void deal(PreDetectionParam param, String msg) {
SocketDataMsg socketDataMsg = MsgUtil.socketDataMsg(msg);
SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getRequestId());
String[] tem = socketDataMsg.getRequestId().split("&&");
SourceOperateCodeEnum enumByCode = SourceOperateCodeEnum.getDictDataEnumByCode(tem[0]);
if (ObjectUtil.isNotNull(enumByCode)) {
switch (enumByCode) {
//源初始化
@@ -64,8 +68,8 @@ public class SocketSourceResponseService {
openSource(param, socketDataMsg);
break;
case QUITE_SOURCE:
quitDeal(socketDataMsg,param);
// System.out.println("关闭源回调:"+msg);
SocketManager.removeUser(param.getUserPageId() + source);
break;
}
@@ -92,7 +96,7 @@ public class SocketSourceResponseService {
//todo 前端推送收到的消息暂未处理好
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
String s = param.getUserPageId() + "_Dev";
String s = param.getUserPageId() + DEV;
//开始设备通讯检测(发送设备初始化)
List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
Map<String, List<PreDetection>> map = new HashMap(1);
@@ -180,19 +184,32 @@ public class SocketSourceResponseService {
// webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
String s = param.getUserPageId() + DEV;
socketMsg.setRequestId(SourceOperateCodeEnum.FORMAL_REAL.getValue());
socketMsg.setRequestId(SourceOperateCodeEnum.Test_VOL.getValue());
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_DATA_REQUEST_02.getValue());
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
List<String> moniterIdList = pqDevList.stream().flatMap(x -> x.getMonitorList().stream())
List<String> moniterIdList = devList.stream().flatMap(x -> x.getMonitorList().stream())
.map(PreDetection.MonitorListDTO::getLineId)
.collect(Collectors.toList());
DevPhaseSequenceParam phaseSequenceParam = new DevPhaseSequenceParam();
phaseSequenceParam.setMoniterIdList(moniterIdList);
phaseSequenceParam.setDataType(Arrays.asList("实时数据/电压有效值", "实时数据/电流有效值"));
phaseSequenceParam.setDataType(Arrays.asList("real$VRMS"));
phaseSequenceParam.setReadCount(20);
phaseSequenceParam.setIgnoreCount(10);
socketMsg.setData(JSON.toJSONString(phaseSequenceParam));
SocketManager.sendMsg(s, JSON.toJSONString(socketMsg));
WebSocketVO<List<DevLineTestResult>> webSocketVO = new WebSocketVO<>();
webSocketVO.setRequestId(socketDataMsg.getRequestId().split("&&")[1]+"_Start");
List<DevLineTestResult> devListRes = new ArrayList<>();
devList.forEach(item->{
DevLineTestResult devLineTestResult = new DevLineTestResult();
devLineTestResult.setDeviceId(item.getDevId());
devLineTestResult.setDeviceName(item.getDevName());
devListRes.add(devLineTestResult);
});
webSocketVO.setData(devListRes);
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(webSocketVO));
break;
case UNPROCESSED_BUSINESS:
webSocketHandler.sendMsgToUser(param.getUserPageId(), JSON.toJSONString(socketDataMsg));
@@ -207,4 +224,33 @@ public class SocketSourceResponseService {
}
}
/**
* 退出检测返回
*/
private void quitDeal(SocketDataMsg socketDataMsg, PreDetectionParam param) {
SourceResponseCodeEnum dictDataEnumByCode = SourceResponseCodeEnum.getDictDataEnumByCode(socketDataMsg.getCode());
SourceOperateCodeEnum operateCodeEnum = SourceOperateCodeEnum.getDictDataEnumByCode(socketDataMsg.getOperateCode());
SocketMsg socketMsg = new SocketMsg();
switch (dictDataEnumByCode) {
case SUCCESS:
//通讯校验成功
SocketManager.removeUser(param.getUserPageId() + source);
break;
case UNPROCESSED_BUSINESS:
break;
default:
WebSocketVO webSocketVO = new WebSocketVO();
break;
}
}
public void initList(PreDetectionParam param){
devList.clear();
this.devList = iPqDevService.getDevInfo(param.getDevIds());
}
}

View File

@@ -54,7 +54,16 @@ public enum SourceOperateCodeEnum {
PRE_TEST("0","预检测"),
FORMAL_TEST("1","正式检测"),
TIME_TEST("2","守时检测")
TIME_TEST("2","守时检测"),
/**
* 检测类型
*/
Test_Freq("formal_real&&Test_Freq","频率检测"),
Test_VOL("formal_real&&Test_VOL","电压检测"),
;

View File

@@ -0,0 +1,21 @@
package com.njcn.gather.detection.pojo.vo;
import io.swagger.models.auth.In;
import lombok.Data;
import java.util.List;
/**
* @Author: cdf
* @CreateTime: 2024-12-26
* @Description: 装置测点检测结果
*/
@Data
public class DevLineTestResult {
private String deviceId;
private String deviceName;
private Integer[] chnResult;
}

View File

@@ -47,7 +47,7 @@ public class DetectionServiceImpl {
devDataMap.forEach(((key, value) -> {
Integer num;
Boolean b = DetectionIndexProcessing(value, dataRule, issue);
if (ObjectUtil.isNull(b)) {
if (ObjectUtil.isNotNull(b)) {
if (b) {
num = 1;
} else {
@@ -74,7 +74,7 @@ public class DetectionServiceImpl {
public Boolean DetectionIndexProcessing(List<DevData> dev, DictDataEnum dataRule, SourceIssue sourceIssue) {
PqErrSysParam.DetectionParam param = new PqErrSysParam.DetectionParam();
List<PqErrSysDtls> pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysIdAndTypes(param);
switch (sourceIssue.getType()) {
switch ("V") {
/**
* 频率
*/

View File

@@ -53,6 +53,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
private final IPqScriptDtlsService pqScriptDtlsService;
private final SocketDevResponseService socketDevResponseService;
private final SocketSourceResponseService socketSourceResponseService;
@Value("${socket.source.ip:192.168.1.136}")
@@ -68,6 +69,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
public void sourceCommunicationCheck(PreDetectionParam param) {
System.out.println("进来了啊啊啊啊啊啊啊啊啊啊啊啊啊");
Channel channel = SocketManager.getChannelByUserId(param.getUserPageId() + source);
if (Objects.nonNull(channel) && channel.isActive()) {
System.out.println("进入关闭源。。//////");
@@ -133,6 +135,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
if (ObjectUtil.isNotNull(sourceParam)) {
//开始组装socket报文请求头
socketDevResponseService.initList(param);
socketSourceResponseService.initList(param);
SocketMsg msg = new SocketMsg();
msg.setRequestId(SourceOperateCodeEnum.YJC_YTXJY.getValue());
msg.setOperateCode(SourceOperateCodeEnum.INIT_GATHER.getValue());

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.detection.util.socket;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.gather.device.script.pojo.po.SourceIssue;
import io.netty.channel.Channel;
import io.netty.channel.nio.NioEventLoopGroup;
@@ -60,5 +61,26 @@ public class SocketManager {
}
}
/**
* 用于存储源操作的脚本信息
* key:
*/
private static final Map<String, SourceIssue> targetMap = new ConcurrentHashMap<>();
public static void addSourceTarget(String sourceTag, SourceIssue sourceIssue) {
targetMap.put(sourceTag, sourceIssue);
}
public static void delSourceTarget(String sourceTag) {
targetMap.remove(sourceTag);
}
public static SourceIssue getSourceTarget(String sourceTag) {
return targetMap.get(sourceTag);
}
}