Skip to content

Commit

Permalink
添加未知连接明细
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeFJ committed Oct 8, 2023
1 parent 4dc678e commit b2959c4
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 152 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/jfeng/gateway/controller/ReqSingle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jfeng.gateway.controller;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ReqSingle {
private String id;
}
27 changes: 22 additions & 5 deletions src/main/java/com/jfeng/gateway/controller/TcpController.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,33 @@ public Resp connectList(@RequestBody(required = false) Req req) {

@RequestMapping(path = "/single", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
@ResponseBody
public Resp queryDevice(@RequestBody String id) {
if (StringUtils.isEmpty(id)) {
return Resp.fail("请传递设备编号.");
public Resp queryDevice(@RequestBody ReqSingle single) {
if (StringUtils.isEmpty(single.getId())) {
return Resp.fail("缺少设备编号.");
}

TcpSession tcpSession = tcpServer.getOnLines().values().parallelStream()
.filter(device -> device.getDeviceId().equalsIgnoreCase(id))
.filter(device -> device.getDeviceId().equalsIgnoreCase(single.getId()))
.findAny().get();
if (tcpSession != null) {
Resp.success(tcpSession.toSingle());
return Resp.success(tcpSession.toSingle());
}
return Resp.success();
}


@RequestMapping(path = "/singleConnect", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8", produces = "application/json;charset=UTF-8")
@ResponseBody
public Resp queryConnect(@RequestBody ReqSingle single) {
if (StringUtils.isEmpty(single.getId())) {
return Resp.fail("缺少连接id.");
}

TcpSession tcpSession = tcpServer.getConnected().values().parallelStream()
.filter(device -> device.getChannelId().equalsIgnoreCase(single.getId()))
.findAny().get();
if (tcpSession != null) {
return Resp.success(tcpSession.toSingle());
}
return Resp.success();
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/jfeng/gateway/session/TcpSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ public Map<String, Object> toConnectJson() {
Map<String, Object> onlineJson = new HashMap<>();
onlineJson.put("createTime", DateTimeUtils2.outString(createTime, "yyyy-MM-dd HH:mm:ss"));
onlineJson.put("remoteAddress", remoteAddress);
onlineJson.put("channelId", channelId);
onlineJson.put("sendPackets", sendPackets);
onlineJson.put("receivedPackets", receivedPackets);
onlineJson.put("channe", sendPackets);
onlineJson.put("lastReadTime", lastReadTime == 0 ? "" : DateTimeUtils2.outString(lastReadTime, "yyyy-MM-dd HH:mm:ss"));
return onlineJson;
}
Expand All @@ -186,7 +187,7 @@ public Map<String, Object> toSingle() {
basic.put("sessionStatus", sessionStatus.getName());
basic.put("remoteAddress", remoteAddress);
basic.put("createTime", DateTimeUtils2.outString(lastReadTime, "yyyy-MM-dd HH:mm:ss"));
basic.put("channelId", channel);
basic.put("channelId", channelId);

basic.put("deviceId", deviceId);
basic.put("bId", bId);
Expand All @@ -200,7 +201,7 @@ public Map<String, Object> toSingle() {
basic.put("lastReadTime", lastReadTime == 0 ? "" : DateTimeUtils2.outString(lastReadTime, "yyyy-MM-dd HH:mm:ss"));

result.put("basic", basic);
basic.put("history", histroyRecordFIFO.getData());
return basic;
result.put("history", histroyRecordFIFO.getData());
return result;
}
}
25 changes: 20 additions & 5 deletions src/main/resources/static/js/connect.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ConnectDetail from "./connectDetail.js";

export default {
data() {
return {
Expand All @@ -11,6 +13,9 @@ export default {
pageNum: 1
}
},
components:{
ConnectDetail
},
mounted() {
this.search();
},
Expand All @@ -34,9 +39,7 @@ export default {
tmp.receive_packets = element.receivedPackets;
tmp.send_packets = element.sendPackets;
tmp.receive_time = element.lastReadTime;
tmp.device_id = element.deviceId;
tmp.bussiness_id = element.bussinessId;

tmp.channelId = element.channelId;
this.connect_list.push(tmp);
});
}
Expand Down Expand Up @@ -83,6 +86,9 @@ export default {
})
}
return obj;
},
connectDetail(connectId){
this.$refs.child.query(connectId);
}
},
template: `
Expand All @@ -106,7 +112,7 @@ export default {
<th class="text-center">发送数据包</th>
<th class="text-center">接收数据包</th>
<th class="text-center">最后一次接收时间</th>
<th class="text-center">实时</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
Expand All @@ -118,7 +124,7 @@ export default {
<td class="text-center">{{item.send_packets}}</td>
<td class="text-center">{{item.receive_time}}</td>
<td class="text-center">
<input type="checkbox" class="toggle toggle-primary toggle-xs" v-model="item.notify"/>
<label for="my_modal_1" class="link link-primary" @click='connectDetail(item.channelId)'>详情</label>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -149,5 +155,14 @@ export default {
</aside>
</footer>
</div>
<input type="checkbox" id="my_modal_1" class="modal-toggle" />
<div class="modal ">
<div class="modal-box w-11/12 max-w-5xl">
<h1 class="sm:text-3xl text-2xl font-medium text-center title-font text-gray-900 mb-4">连接详情</h1>
<ConnectDetail ref='child' />
</div>
<label class="modal-backdrop" for="my_modal_1">Close</label>
</div>
`
}
148 changes: 148 additions & 0 deletions src/main/resources/static/js/connectDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
export default {
data() {
return {
basic: {},
history: []
}
},
methods: {
parseType(type) {
if (type == 0) {
return "连接"
} if (type == 1) {
return "接收"
} if (type == 2) {
return "发送"
}else{
return "未知"
}
},
query(connectId) {
var config = {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({
id: connectId
})
};
fetch('/singleConnect', config)
.then(resp => resp.json())
.then(res => {
if (res.code != 1) {

} else {
this.basic = res.data.basic;
this.history = res.data.history;
}
});
},
copyTo(value) {
let tempInput = document.createElement('input');//创建input元素
document.body.appendChild(tempInput);//向页面底部追加输入框
tempInput.setAttribute('value', value);//添加属性,将url赋值给input元素的value属性
tempInput.select();//选择input元素
document.execCommand("Copy");//执行复制命令
//复制之后再删除元素,否则无法成功赋值
tempInput.remove();//删除动态创建的节点
}
},
template: `
<h2 class="text-indigo-500 text-lg title-font font-medium mb-1">基础信息</h2>
<hr/>
<div class="flex flex-wrap">
<div class="xl:w-1/4 lg:w-1/2 md:w-full px-1 py-1 border-l-2 border-gray-200 border-opacity-60">
<dl class="flex items-center space-x-6 px-3 py-3">
<div class='w-32 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">会话状态</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.sessionStatus}}</dd>
</div>
<div class='w-32 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">远程地址</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.remoteAddress}}</dd>
</div>
<div class='w-48 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">创建时间</dt>
<dd class="mb-4 whitespace-nowrap font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.createTime}}</dd>
</div>
</dl>
</div>
<div class="xl:w-1/4 lg:w-1/2 md:w-full px-1 py-1 border-l-2 border-gray-200 border-opacity-60">
<dl class="flex items-center space-x-6 px-3 py-3">
<div class='w-32 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">接收包数</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.receivedPackets}}</dd>
</div>
<div class='w-32 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">接收字节数</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.receivedBytes}}</dd>
</div>
<div class='w-48 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">最后接收时间</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.lastReadTime}}</dd>
</div>
</dl>
</div>
<div class="xl:w-1/4 lg:w-1/2 md:w-full px-1 py-1 border-l-2 border-gray-200 border-opacity-60">
<dl class="flex items-center space-x-6 px-3 py-3">
<div class='w-48 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">设备编号</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.deviceId}}</dd>
</div>
<div class='w-48 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">业务编号</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.bId}}</dd>
</div>
</dl>
</div>
<div class="xl:w-1/4 lg:w-1/2 md:w-full px-1 py-1 border-l-2 border-gray-200 border-opacity-60">
<dl class="flex items-center space-x-6 px-3 py-3">
<div class='w-32 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">发送包数</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.sendPackets}}</dd>
</div>
<div class='w-32 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">发送字节数</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.sendBytes}}</dd>
</div>
<div class='w-48 h-14'>
<dt class="mb-2 leading-none text-gray-900 dark:text-white">最后发送时间</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">{{basic.lastWriteTime}}</dd>
</div>
</dl>
</div>
</div>
<h2 class="text-indigo-500 text-lg title-font font-medium mb-1">历史数据</h2>
<hr/>
<div class="h-4/5">
<table class="table table-sm">
<thead>
<tr>
<th class="text-center whitespace-nowrap w-5">序号</th>
<th class="text-center whitespace-nowrap w-10">发生时间</th>
<th class="text-center whitespace-nowrap w-5">类型</th>
<th class="text-center whitespace-nowrap">数据</th>
<th class="text-center whitespace-nowrap w-10">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in history" :key="item.device_id" >
<td class="text-center whitespace-nowrap w-5">{{index+1}}</td>
<td class="text-center whitespace-nowrap w-10">{{item.time}}</td>
<td class="text-center whitespace-nowrap w-5" :class="{'text-error':item.dataType==0,'text-info':item.dataType==1,'text-warning':item.dataType==2}">{{parseType(item.dataType)}}</td>
<td class="text-left">
<p class="w-11/12 overflow-hidden whitespace-nowrap overflow-ellipsis">
{{item.data}}
</p>
</td>
<td class="text-center whitespace-nowrap w-10">
<button class="btn btn-sm btn-outline p-1" @click="copyTo(item.data)">复制</button>
</td>
</tr>
</tbody>
</table>
</div>
`
}
Loading

0 comments on commit b2959c4

Please sign in to comment.