win代码上传
parent
d54c1285eb
commit
ce243f7e0a
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.web.controller.system;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.common.core.domain.entity.DataResponse;
|
||||
import com.ruoyi.common.core.domain.entity.PrimaryRadarData;
|
||||
import com.ruoyi.common.core.domain.entity.SysIdentifier;
|
||||
|
|
@ -29,6 +30,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.xml.crypto.Data;
|
||||
import java.net.Inet4Address;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
|
@ -81,8 +83,9 @@ public class RadarStatusController {
|
|||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
for (SysRadar radar : radarList) {
|
||||
try {
|
||||
// ModbusResponse modbusResponse = new ModbusResponse();
|
||||
ModbusMaster master = ModbusUtils.getSlave(radar.getRadarIp(), 23);
|
||||
DataResponse dataResponse = new DataResponse();
|
||||
|
|
@ -90,7 +93,7 @@ public class RadarStatusController {
|
|||
System.out.println(radar.getRadarIp());
|
||||
ModbusResponse modbusResponse = ModbusUtils.holdingRegister();
|
||||
if (modbusResponse == null){
|
||||
dataResponse.setStatus("0");
|
||||
dataResponse.setStatus(0);
|
||||
}
|
||||
System.out.println(modbusResponse);
|
||||
String tag = modbusResponse.getTagId();
|
||||
|
|
@ -111,19 +114,23 @@ public class RadarStatusController {
|
|||
String ip = Inet4Address.getLocalHost().getHostAddress();
|
||||
if (modbusResponse.getValue4() != null && !"0".equals(modbusResponse.getValue4())) {
|
||||
primaryRadarDataService.insertPrimaryRadarData(primaryRadarData);
|
||||
dataResponse.setStatus("1");
|
||||
dataResponse.setStatus(1);
|
||||
dataResponse.setRadarLocation(primaryRadarData.getRadarLocation());
|
||||
} else {
|
||||
dataResponse.setStatus("0");
|
||||
dataResponse.setStatus(0);
|
||||
}
|
||||
RadarStatusWebSocket.sendToAll(JSON.toJSONString(dataResponse));
|
||||
}catch (Exception e) {
|
||||
if (e.equals("java.net.SocketTimeoutException: connect timed out")) {
|
||||
System.err.println("从串口读取失败:" + "连接超时");
|
||||
}
|
||||
DataResponse dataResponse = new DataResponse();
|
||||
dataResponse.setRadarIp(radar.getRadarIp());
|
||||
dataResponse.setRadarLocation(radar.getRadarLocation());
|
||||
dataResponse.setStatus(0);
|
||||
RadarStatusWebSocket.sendToAll(JSON.toJSONString(dataResponse));
|
||||
e.printStackTrace();
|
||||
}
|
||||
RadarStatusWebSocket.sendToAll(dataResponse);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e.equals("java.net.SocketTimeoutException: connect timed out")) {
|
||||
System.err.println("从串口读取失败:" + "连接超时");
|
||||
}
|
||||
// RadarStatusWebSocket.sendToAll(dataResponse.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class RadarStatusWebSocket {
|
|||
}
|
||||
}
|
||||
|
||||
public static void sendToAll(DataResponse dataResponse) {
|
||||
public static void sendToAll(Object dataResponse) {
|
||||
for (Session session : sessions) {
|
||||
try {
|
||||
session.getBasicRemote().sendObject(dataResponse);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@
|
|||
var prefix = ctx + "system/radarStatus";
|
||||
var datas = [[${@dict.getType('sys_normal_disable')}]];
|
||||
|
||||
var tableData = [];
|
||||
|
||||
$(function() {
|
||||
var options = {
|
||||
url: prefix + "/list",
|
||||
|
|
@ -85,18 +87,35 @@
|
|||
console.log("WebSocket连接已打开");
|
||||
};
|
||||
|
||||
socket.onmessage = function(event) {
|
||||
var data = event.data;
|
||||
// console.log("接收到数据:" + data);
|
||||
// 在这里更新前端界面,显示接收到的数据
|
||||
let parse = JSON.parse(data);
|
||||
console.log("接收到数据:" + parse);
|
||||
socket.onmessage = (event)=> {
|
||||
|
||||
var data = JSON.parse(event.data);
|
||||
console.log("接收到数据:" + data);
|
||||
$.each($.tableData, function (i, row) {
|
||||
if(row.radarIp === data.radarIp){
|
||||
console.log("rowbefore"+JSON.stringify(row))
|
||||
|
||||
row.status = data.status;
|
||||
console.log("rowafter"+JSON.stringify(row))
|
||||
}
|
||||
})
|
||||
var template = $('#profileTemplate').html()
|
||||
var view = ''
|
||||
$.each(data, function (i, row) {
|
||||
view += template
|
||||
.replace('%IMAGE%', getImageUrl(row.status))
|
||||
.replace('%radarIp%', row.radarIp)
|
||||
.replace('%radarLocation%', row.radarLocation)
|
||||
})
|
||||
|
||||
return `<div class="row mx-0">${view}</div>`
|
||||
};
|
||||
|
||||
socket.onclose = function(event) {
|
||||
console.log("WebSocket连接已关闭");
|
||||
};
|
||||
function customViewFormatter (data) {
|
||||
$.tableData = data
|
||||
var template = $('#profileTemplate').html()
|
||||
var view = ''
|
||||
$.each(data, function (i, row) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class DataResponse implements Serializable {
|
|||
/**
|
||||
* 雷达连接状态
|
||||
*/
|
||||
private String status = "0" ;
|
||||
private Integer status = 0 ;
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue