1.源装置,入参和发送指令业务编写
This commit is contained in:
@@ -17,7 +17,7 @@ public class SocketResponseService {
|
||||
|
||||
|
||||
System.out.println("进入deal+++++++++++++++++++");
|
||||
webSocketHandler.senMsgToUser(userId,msg);
|
||||
webSocketHandler.sendMsgToUser(userId,msg);
|
||||
|
||||
SocketManager.getChannelByUserId(userId).close();
|
||||
|
||||
|
||||
@@ -9,12 +9,15 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class SocketSourceResponseService {
|
||||
|
||||
/**
|
||||
* 向webSocket客户端发送消息
|
||||
*/
|
||||
private final WebSocketHandler webSocketHandler;
|
||||
|
||||
public void deal(String userId,String msg){
|
||||
|
||||
System.out.println("进入deal+++++++++++++++++++");
|
||||
webSocketHandler.senMsgToUser(userId,msg);
|
||||
webSocketHandler.sendMsgToUser(userId,msg);
|
||||
|
||||
SocketManager.getChannelByUserId(userId).close();
|
||||
|
||||
|
||||
@@ -12,10 +12,19 @@ import java.util.List;
|
||||
@Data
|
||||
public class PreDetectionParam {
|
||||
|
||||
//用户功能组成唯一标识 zhangsan_test
|
||||
/**
|
||||
* 检测计划id
|
||||
*/
|
||||
private String plan;
|
||||
|
||||
/**
|
||||
* 用户功能组成唯一标识 zhangsan_test
|
||||
*/
|
||||
private String userPageId;
|
||||
|
||||
/**
|
||||
* 检测终端id集合
|
||||
*/
|
||||
private List<String> devIds;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.gather.detection.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description
|
||||
* @date 2024/12/13 9:09
|
||||
*/
|
||||
@Data
|
||||
public class SocketDataMsg {
|
||||
|
||||
/**
|
||||
* 请求id,确保接收到响应时,知晓是针对的哪次请求的应答
|
||||
*/
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* 源初始化 INIT_GATHER$01 INIT_GATHER采集初始化,01 统计采集、02 暂态采集、03 实时采集
|
||||
*/
|
||||
private String operateCode;
|
||||
|
||||
/**
|
||||
* 数据体,传输前需要将对象、Array等转为String
|
||||
*/
|
||||
private String data;
|
||||
|
||||
/**
|
||||
* code码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
* @description 预检测流程
|
||||
@@ -13,12 +15,11 @@ public interface PreDetectionService {
|
||||
|
||||
/**
|
||||
* 源通讯校验socket入参拼接
|
||||
* @param
|
||||
* @return: java.lang.String
|
||||
* @param param
|
||||
* @Author: wr
|
||||
* @Date: 2024/12/11 13:26
|
||||
*/
|
||||
void sourceCommunicationCheck();
|
||||
void sourceCommunicationCheck(PreDetectionParam param);
|
||||
|
||||
/**
|
||||
* 装置通讯校验
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
package com.njcn.gather.detection.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.njcn.gather.detection.handler.SocketSourceResponseService;
|
||||
import com.njcn.gather.detection.handler.SocketResponseService;
|
||||
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.service.PreDetectionService;
|
||||
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
|
||||
import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler;
|
||||
import com.njcn.gather.device.device.mapper.PqDevMapper;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
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.device.source.pojo.po.SourceInitialize;
|
||||
import com.njcn.gather.device.source.service.IPqSourceService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -30,7 +37,11 @@ import java.util.Map;
|
||||
public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
|
||||
private final IPqDevService iPqDevService;
|
||||
|
||||
private final IDictDataService dictDataService;
|
||||
private final IAdPlanService iAdPlanService;
|
||||
private final IAdPlanSourceService adPlanSourceService;
|
||||
private final IPqSourceService pqSourceService;
|
||||
private final IPqScriptDtlsService pqScriptDtlsService;
|
||||
|
||||
@Value("${socket.source.ip}")
|
||||
private String ip;
|
||||
@@ -41,9 +52,74 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
private final SocketSourceResponseService sourceResponseService;
|
||||
|
||||
|
||||
@Override
|
||||
public void sourceCommunicationCheck() {
|
||||
|
||||
private final String userId = "aaa";
|
||||
|
||||
@Override
|
||||
public void sourceCommunicationCheck(PreDetectionParam param) {
|
||||
/*
|
||||
先组装源通讯协议
|
||||
查询计划什么模式的(除了对比式,其他都是一个计划对应一个源)
|
||||
*/
|
||||
AdPlan plan = iAdPlanService.getById(param.getPlan());
|
||||
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());
|
||||
break;
|
||||
case CONTRAST:
|
||||
//todo 对比式可以是多个源
|
||||
break;
|
||||
default:
|
||||
//todo 没有找到对应的模式
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
//todo 需要向前端推送消息查不到检测计划
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 源参数下发
|
||||
* @param scriptId
|
||||
*/
|
||||
private void sendSourceIssue(String scriptId){
|
||||
|
||||
|
||||
|
||||
}
|
||||
private void sendYtxSocket(String planId){
|
||||
AdPlanSource planSource = adPlanSourceService.getById(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.setData(JSON.toJSONString(sourceParam));
|
||||
NettyClient.socketClient(ip, port, JSON.toJSONString(msg), new NettySourceClientHandler(ip, sourceResponseService));
|
||||
PqScriptIssueParam param=new PqScriptIssueParam();
|
||||
param.setScriptId(planSource.getSourceId());
|
||||
param.setPlanId(planId);
|
||||
param.setSourceId(planSource.getSourceId());
|
||||
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(param);
|
||||
for (SourceIssue sourceIssue : sourceIssues) {
|
||||
String jsonString = JSON.toJSONString(sourceIssue);
|
||||
}
|
||||
|
||||
}else{
|
||||
//todo 提示处理源表信息不存在
|
||||
}
|
||||
}else{
|
||||
//todo 提示处理计划和源关系不存在
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,15 +145,15 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
||||
|
||||
//组装请求数据
|
||||
SocketMsg socketMsg = new SocketMsg();
|
||||
Map<String,List<PreDetection> > map=new HashMap();
|
||||
map.put("deviceList",pqDevList);
|
||||
Map<String, List<PreDetection>> 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));
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.njcn.gather.detection.util.socket;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
|
||||
|
||||
/**
|
||||
* @author wr
|
||||
@@ -12,7 +12,7 @@ import com.njcn.gather.detection.pojo.vo.SocketMsg;
|
||||
public class MsgUtil {
|
||||
|
||||
|
||||
public SocketMsg a(String textMsg){
|
||||
return JSON.parseObject(textMsg,SocketMsg.class);
|
||||
public SocketDataMsg socketDataMsg(String textMsg){
|
||||
return JSON.parseObject(textMsg,SocketDataMsg.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
|
||||
/**
|
||||
* 推送数据至前台
|
||||
*/
|
||||
public void senMsgToUser(String userId, String msg) {
|
||||
public void sendMsgToUser(String userId, String msg) {
|
||||
WebServiceManager.sendMsg(userId, msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user