1.检测模块:预检测框架提交

2.报文通用装置查询编写
This commit is contained in:
wr
2024-12-12 18:40:58 +08:00
parent e432501e99
commit bc0e93b522
20 changed files with 277 additions and 98 deletions

View File

@@ -36,6 +36,11 @@
<version>4.1.68.Final</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,26 @@
package com.njcn.gather.detection.handler;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.web.WebSocketHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class SocketSourceResponseService {
private final WebSocketHandler webSocketHandler;
public void deal(String userId,String msg){
System.out.println("进入deal+++++++++++++++++++");
webSocketHandler.senMsgToUser(userId,msg);
SocketManager.getChannelByUserId(userId).close();
}
}

View File

@@ -4,7 +4,7 @@ import lombok.Data;
/**
* @author wr
* @description
* @description socket 通用发送报文请求
* @date 2024/12/11 15:57
*/
@Data

View File

@@ -8,7 +8,11 @@ package com.njcn.gather.detection.service;
public interface PreDetectionService {
/**
* 源通讯校验
* 源通讯校验socket入参拼接
* @param
* @return: java.lang.String
* @Author: wr
* @Date: 2024/12/11 13:26
*/
void sourceCommunicationCheck();

View File

@@ -1,7 +1,7 @@
package com.njcn.gather.detection.service.impl;
import com.njcn.gather.detection.handler.SocketResponseService;
import com.njcn.gather.detection.handler.SocketSourceResponseService;
import com.njcn.gather.detection.service.PreDetectionService;
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
@@ -21,7 +21,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
@Value("${socket.source.port}")
private static Integer port;
private final SocketResponseService socketResponseService;
private final SocketSourceResponseService sourceResponseService;
@Override
@@ -48,7 +48,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
public void test() {
NettyClient.socketClient(ip,port,"test------------>",new NettySourceClientHandler("aa",socketResponseService));
NettyClient.socketClient(ip,port,"test------------>",new NettySourceClientHandler("aaa",sourceResponseService));
}
}

View File

@@ -1,5 +1,8 @@
package com.njcn.gather.detection.util.socket;
import com.alibaba.fastjson.JSON;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
/**
* @author wr
* @description
@@ -9,4 +12,7 @@ package com.njcn.gather.detection.util.socket;
public class MsgUtil {
public SocketMsg a(String textMsg){
return JSON.parseObject(textMsg,SocketMsg.class);
}
}

View File

@@ -42,8 +42,8 @@ public class WebServiceManager {
public static void sendMsg(String userId,String msg) {
Channel channel = userSessions.get(userId);
TextWebSocketFrame wd1 = new TextWebSocketFrame(msg);
channel.writeAndFlush(wd1);
TextWebSocketFrame wd = new TextWebSocketFrame(msg);
channel.writeAndFlush(wd);
}
}

View File

@@ -8,8 +8,6 @@ import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Value;
import java.util.concurrent.TimeUnit;
@@ -45,7 +43,6 @@ public class NettyClient {
e.printStackTrace();
} finally {
group.shutdownGracefully();
System.out.println("程序结束");
}
}

View File

@@ -1,18 +1,15 @@
package com.njcn.gather.detection.util.socket.cilent;
import com.njcn.gather.detection.handler.SocketResponseService;
import com.njcn.gather.detection.handler.SocketSourceResponseService;
import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.WebServiceManager;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.Scanner;
/**
* @Description: 客户端业务处理(示例)
* @Description: 客户端业务处理(示例)
* @Author: wr
* @Date: 2024/12/10 14:16
*/
@@ -22,14 +19,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<Strin
private final String webUser;
private final SocketResponseService socketResponseService;
private final SocketSourceResponseService sourceResponseService;
/**
@@ -46,17 +36,7 @@ public class NettySourceClientHandler extends SimpleChannelInboundHandler<Strin
*/
@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException {
Channel userId = SocketManager.getChannelByUserId("userId");
if(msg.endsWith("结束")){
WebServiceManager.sendMsg("","第一流程结束");
System.out.println("第一流程结束");
userId.close();
}else{
System.out.println("服务端消息 == " + msg);
socketResponseService.deal(webUser,msg);
}
sourceResponseService.deal(webUser,msg);
}
/**

View File

@@ -21,7 +21,7 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
*/
public class NettyServer {
public static final int port = 8787;
public static final int port = 61000;
public static void main(String[] args) {
NettyServer nettyServer = new NettyServer();

View File

@@ -1,9 +1,12 @@
package com.njcn.gather.detection.util.socket.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.pojo.vo.aa;
import com.njcn.gather.detection.util.socket.WebServiceManager;
import com.njcn.gather.detection.util.socket.cilent.NettyClient;
import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
@@ -25,6 +28,8 @@ import org.springframework.stereotype.Component;
@Slf4j
public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
private final static String QUESTION_MARK = "?";
private final static String EQUAL_TO = "=";
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
@@ -41,10 +46,9 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
String userId = getUrlParams(uri);
WebServiceManager.addUser(userId, ctx.channel());
log.info("登录的用户id是{}", userId);
//如果url包含参数需要处理
if (uri.contains("?")) {
String newUri = uri.substring(0, uri.indexOf("?"));
if (uri.contains(QUESTION_MARK)) {
String newUri = uri.substring(0, uri.indexOf(QUESTION_MARK));
request.setUri(newUri);
}
@@ -52,26 +56,25 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
//正常的TEXT消息类型
TextWebSocketFrame frame = (TextWebSocketFrame) msg;
log.info("客户端收到服务器数据:{}", frame.text());
}
super.channelRead(ctx, msg);
}
/**
* 根据用户地址获取用户名 ws://127.0.0.1:7777/hello?name=aa
* @param url
* @return
*/
private static String getUrlParams(String url) {
if (!url.contains("=")) {
if (!url.contains(EQUAL_TO)) {
return null;
}
String userId = url.substring(url.indexOf("=") + 1);
String userId = url.substring(url.indexOf(EQUAL_TO) + 1);
return userId;
}
@Override
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) {
/* System.out.println("服务端消息 == " + msg.text());
@@ -95,7 +98,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
@Override
public void handlerAdded(ChannelHandlerContext ctx) {
//WebServiceManager.addUser(userId, ctx.channel());
System.out.println("有新的连接接入:"+ctx);
System.out.println("有新的连接接入:" + ctx);
}
@Override
@@ -125,8 +128,8 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
/**
* 推送数据至前台
*/
public void senMsgToUser(String userId,String msg){
WebServiceManager.sendMsg(userId,msg);
public void senMsgToUser(String userId, String msg) {
WebServiceManager.sendMsg(userId, msg);
}
}

View File

@@ -30,7 +30,7 @@ public class WebSocketService {
/**
* 端口号
*/
@Value("${webSocket.netty.port:7777}")
@Value("${webSocket.port}")
int port;
@@ -40,7 +40,7 @@ public class WebSocketService {
@PostConstruct
public void start() throws InterruptedException {
public void start() {
new Thread(() -> {
//可以自定义线程的数量
bossGroup = new NioEventLoopGroup();
@@ -94,41 +94,4 @@ public class WebSocketService {
System.out.println("webSocket销毁---------------");
}
/* public static void main(String[] args) {
//可以自定义线程的数量
EventLoopGroup bossGroup = new NioEventLoopGroup();
// 默认创建的线程数量 = CPU 处理器数量 *2
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler())
//当前连接被阻塞的时候BACKLOG代表的事 阻塞队列的长度
.option(ChannelOption.SO_BACKLOG, 128)
//设置连接保持为活动状态
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(new WebSocketInitializer());
ChannelFuture future = serverBootstrap.bind(7777).sync();
future.addListener(f -> {
if (future.isSuccess()) {
System.out.println("webSocket服务启动成功");
} else {
System.out.println("webSocket服务启动失败");
}
});
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}*/
}

View File

@@ -17,6 +17,7 @@ import com.njcn.gather.device.device.pojo.param.PqDevParam;
import com.njcn.gather.device.device.pojo.po.PqDev;
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.device.pojo.vo.PreDetection;
import com.njcn.gather.device.device.service.IPqDevService;
import com.njcn.gather.device.pojo.constant.DevConst;
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
@@ -37,6 +38,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -56,6 +58,17 @@ public class PqDevController extends BaseController {
private final IDictDataService dictDataService;
@OperateInfo
@GetMapping("/aaa")
@ApiOperation("分页查询被检设备")
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
public HttpResult<List<PreDetection> > aaa() {
String methodDescribe = getMethodDescribe("list");
List<PreDetection> devInfo = pqDevService.getDevInfo(Arrays.asList("578c142b7e4e4978a35bd6225aa62a23", "393504f55f1f79bce255bfc195cfdb56"));
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devInfo, methodDescribe);
}
@OperateInfo
@PostMapping("/list")
@ApiOperation("分页查询被检设备")

View File

@@ -2,6 +2,10 @@ package com.njcn.gather.device.device.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.device.pojo.po.PqDev;
import com.njcn.gather.device.device.pojo.vo.PreDetection;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author caozehui
@@ -9,5 +13,13 @@ import com.njcn.gather.device.device.pojo.po.PqDev;
*/
public interface PqDevMapper extends MPJBaseMapper<PqDev> {
/**
* 根据装置id集合获取装置信息
* @param devIds 装置id
* @return: java.util.List<com.njcn.gather.device.device.pojo.vo.PreDetection>
* @Author: wr
* @Date: 2024/12/12 11:46
*/
List<PreDetection> selectDevInfo(@Param("devIds") List<String> devIds);
}

View File

@@ -2,6 +2,39 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.gather.device.device.mapper.PqDevMapper">
<!-- 通用查询映射结果 -->
<resultMap id="DevResultMap" type="com.njcn.gather.device.device.pojo.vo.PreDetection">
<id column="IP" property="devIP" />
<result column="Port" property="port" />
<result column="Dev_Type" property="devType" />
<result column="" property="icdType" />
<result column="Series" property="devCode" />
<result column="Dev_Key" property="devKey" />
<collection
property="monitorList"
column="{ devId = Id}"
select="com.njcn.gather.device.monitor.mapper.PqMonitorMapper.selectMonitorInfo"
>
</collection>
</resultMap>
<select id="selectDevInfo" resultMap="DevResultMap">
SELECT
d.Id,
d.IP,
( select name from sys_dict_data sd where d.Dev_Type= sd.id) as Dev_Type,
d.Port,
d.Series,
d.Dev_Key
FROM
pq_dev d
<where>
<if test="devIds !=null and devIds.size()!=0">
AND d.Id in
<foreach collection="devIds" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
</where>
</select>
</mapper>

View File

@@ -0,0 +1,98 @@
package com.njcn.gather.device.device.pojo.vo;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.njcn.gather.device.device.util.DeviceUtil;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author wr
* @description 预检测装置报文初始化
* @date 2024/12/12 11:21
*/
@Data
@NoArgsConstructor
public class PreDetection {
/**
* 装置ip
*/
@JsonProperty("devIP")
private String devIP;
/**
* 装置端口
*/
@JsonProperty("port")
private Integer port;
/**
* 设备类型,字典表
*/
@JsonProperty("devType")
private String devType;
/**
* icd设备类型
*/
@JsonProperty("icdType")
private String icdType;
/**
* 装置识别码3ds加密
*/
@JsonProperty("devCode")
private String devCode;
/**
* 装置秘钥3ds加密
*/
@JsonProperty("devKey")
private String devKey;
/**
* 监测点信息
*/
@JsonProperty("monitorList")
private List<MonitorListDTO> monitorList;
@Data
@NoArgsConstructor
public static class MonitorListDTO {
/**
* 监测点id
*/
@JsonProperty("lineId")
private String lineId;
/**
* 监测点线路号
*/
@JsonProperty("line")
private Integer line;
}
public String getDevKey() {
if(StrUtil.isNotBlank(devKey)){
String key = DeviceUtil.decoderString(1, devKey);
if(StrUtil.isNotBlank(key)){
return key;
}
}
return null;
}
public String getDevCode() {
if(StrUtil.isNotBlank(devCode)){
String code= DeviceUtil.decoderString(1,devCode);
if(StrUtil.isNotBlank(code)){
return code;
}
}
return null;
}
}

View File

@@ -7,7 +7,9 @@ import com.njcn.gather.device.device.pojo.param.PqDevParam;
import com.njcn.gather.device.device.pojo.po.PqDev;
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.device.pojo.vo.PreDetection;
import com.njcn.gather.device.plan.pojo.param.AdPlanParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@@ -141,4 +143,13 @@ public interface IPqDevService extends IService<PqDev> {
* @return 所有非未检测状态的设备列表
*/
List<PqDev> listNotUnchecked();
/**
* 获取装置信息和装置下监测点信息
* @param devIds
* @return: java.util.List<com.njcn.gather.device.device.pojo.vo.PreDetection>
* @Author: wr
* @Date: 2024/12/12 15:50
*/
List<PreDetection> getDevInfo(@Param("devIds") List<String> devIds);
}

View File

@@ -17,6 +17,7 @@ import com.njcn.gather.device.device.pojo.param.PqDevParam;
import com.njcn.gather.device.device.pojo.po.PqDev;
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
import com.njcn.gather.device.device.pojo.vo.PqDevVO;
import com.njcn.gather.device.device.pojo.vo.PreDetection;
import com.njcn.gather.device.device.service.IPqDevService;
import com.njcn.gather.device.device.util.DeviceUtil;
import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
@@ -334,6 +335,11 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
return queryWrapper;
}
@Override
public List<PreDetection> getDevInfo(List<String> devIds) {
return this.baseMapper.selectDevInfo(devIds);
}
/**
* 获取检测状态饼状图数据
*

View File

@@ -1,7 +1,11 @@
package com.njcn.gather.device.monitor.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.device.pojo.vo.PreDetection;
import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author caozehui
@@ -9,5 +13,13 @@ import com.njcn.gather.device.monitor.pojo.po.PqMonitor;
*/
public interface PqMonitorMapper extends MPJBaseMapper<PqMonitor> {
/**
* 根据终端id获取监测点集合
* @param devId
* @return: java.util.List<com.njcn.gather.device.device.pojo.vo.PreDetection.MonitorListDTO>
* @Author: wr
* @Date: 2024/12/12 13:15
*/
List<PreDetection.MonitorListDTO> selectMonitorInfo(@Param("devId") String devId);
}

View File

@@ -2,6 +2,16 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.gather.device.monitor.mapper.PqMonitorMapper">
<select id="selectMonitorInfo"
resultType="com.njcn.gather.device.device.pojo.vo.PreDetection$MonitorListDTO">
SELECT
Id as lineId,
Num as line
FROM
pq_monitor
WHERE
dev_id = #{devId}
</select>
</mapper>