win代码上传
parent
1ecdd74611
commit
cb9476cade
|
|
@ -26,6 +26,7 @@ import lombok.Data;
|
||||||
import org.apache.commons.compress.utils.Lists;
|
import org.apache.commons.compress.utils.Lists;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
|
|
@ -41,6 +42,7 @@ import java.sql.ResultSet;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 雷达状态
|
* 雷达状态
|
||||||
|
|
@ -49,7 +51,7 @@ import java.util.concurrent.CompletableFuture;
|
||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/system/radarstatus")
|
@RequestMapping("/system/radarstatus")
|
||||||
public class RadarStatusController {
|
public class RadarStatusController implements InitializingBean {
|
||||||
private static final Logger log = LoggerFactory.getLogger(RadarStatusController.class);
|
private static final Logger log = LoggerFactory.getLogger(RadarStatusController.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -61,6 +63,10 @@ public class RadarStatusController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysIdentifierService identifierService;
|
private ISysIdentifierService identifierService;
|
||||||
|
|
||||||
|
private Timer timer = new Timer();
|
||||||
|
|
||||||
|
public static CopyOnWriteArrayList<SocketModel> allRadar = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
private String prefix = "system/radarstatus";
|
private String prefix = "system/radarstatus";
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,68 +86,6 @@ public class RadarStatusController {
|
||||||
TableDataInfo rspData = new TableDataInfo();
|
TableDataInfo rspData = new TableDataInfo();
|
||||||
List<SysRadar> radarList = service.selectRadarList(sysRadar);
|
List<SysRadar> radarList = service.selectRadarList(sysRadar);
|
||||||
|
|
||||||
List<SocketModel> socketModels = Lists.newArrayList();
|
|
||||||
for (SysRadar radar : radarList) {
|
|
||||||
try {
|
|
||||||
Socket socket = new Socket(radar.getRadarIp(), 23);
|
|
||||||
SocketModel socketModel = new SocketModel();
|
|
||||||
socketModel.setRadarLocation(radar.getRadarLocation());
|
|
||||||
socketModel.setSocket(socket);
|
|
||||||
socketModel.setRadarIp(radar.getRadarIp());
|
|
||||||
socketModels.add(socketModel);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer timer = new Timer();
|
|
||||||
TimerTask task = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
socketModels.forEach(socketModel -> {
|
|
||||||
try {
|
|
||||||
DataResponse data = SocketUtil.getData(socketModel);
|
|
||||||
System.out.println(socketModel.getRadarIp() +": "+ data);
|
|
||||||
ModbusResponse modbusResponse = getModbusResponse(data);
|
|
||||||
String tag = modbusResponse.getTagId();
|
|
||||||
PrimaryRadarData primaryRadarData = new PrimaryRadarData();
|
|
||||||
SysIdentifier sysIdentifier = new SysIdentifier();
|
|
||||||
BeanUtils.copyProperties(modbusResponse, primaryRadarData);
|
|
||||||
if (!"0".equals(modbusResponse.getTagId())) {
|
|
||||||
sysIdentifier = identifierService.selectIdentifierByTag(tag);
|
|
||||||
primaryRadarData.setLadleNumber(sysIdentifier.getLadleNumber());
|
|
||||||
primaryRadarData.setRadarLocation(socketModel.getRadarLocation());
|
|
||||||
primaryRadarData.setRadarIp(socketModel.getRadarIp());
|
|
||||||
} else {
|
|
||||||
primaryRadarData.setLadleNumber(null);
|
|
||||||
primaryRadarData.setRadarLocation(null);
|
|
||||||
primaryRadarData.setRadarIp(socketModel.getRadarIp());
|
|
||||||
}
|
|
||||||
String ip = Inet4Address.getLocalHost().getHostAddress();
|
|
||||||
if (modbusResponse.getValue4() != null && !"0".equals(modbusResponse.getValue4())) {
|
|
||||||
primaryRadarDataService.insertPrimaryRadarData(primaryRadarData);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
RadarStatusWebSocket.sendToAll(JSON.toJSONString(data));
|
|
||||||
} 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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
timer.scheduleAtFixedRate(task, 1, 1000);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 异步连接硬件
|
// 异步连接硬件
|
||||||
// CompletableFuture<List<ModbusResponse>> listCompletableFuture = CompletableFuture.supplyAsync(() -> {
|
// CompletableFuture<List<ModbusResponse>> listCompletableFuture = CompletableFuture.supplyAsync(() -> {
|
||||||
// List<ModbusResponse> responses = new ArrayList<>();
|
// List<ModbusResponse> responses = new ArrayList<>();
|
||||||
|
|
@ -215,6 +159,71 @@ public class RadarStatusController {
|
||||||
return rspData;
|
return rspData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void asyncWebSocket(List<SysRadar> radarList) {
|
||||||
|
CompletableFuture.runAsync(()->{
|
||||||
|
|
||||||
|
buildAllRadar(radarList);
|
||||||
|
|
||||||
|
TimerTask task = new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int count = 0;
|
||||||
|
allRadar.forEach(socketModel -> {
|
||||||
|
asyncReadRadar(socketModel);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
timer.scheduleAtFixedRate(task, 1, 100);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void buildAllRadar(List<SysRadar> radarList) {
|
||||||
|
for (SysRadar radar : radarList) {
|
||||||
|
try {
|
||||||
|
Socket socket = new Socket(radar.getRadarIp(), 23);
|
||||||
|
SocketModel socketModel = new SocketModel();
|
||||||
|
socketModel.setRadarLocation(radar.getRadarLocation());
|
||||||
|
socketModel.setSocket(socket);
|
||||||
|
socketModel.setRadarIp(radar.getRadarIp());
|
||||||
|
allRadar.add(socketModel);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void asyncReadRadar(SocketModel socketModel) {
|
||||||
|
CompletableFuture.runAsync(()->{
|
||||||
|
try {
|
||||||
|
DataResponse data = SocketUtil.getData(socketModel);
|
||||||
|
System.out.println(socketModel.getRadarIp() +": "+ data);
|
||||||
|
ModbusResponse modbusResponse = getModbusResponse(data);
|
||||||
|
String tag = modbusResponse.getTagId();
|
||||||
|
PrimaryRadarData primaryRadarData = new PrimaryRadarData();
|
||||||
|
SysIdentifier sysIdentifier = new SysIdentifier();
|
||||||
|
BeanUtils.copyProperties(modbusResponse, primaryRadarData);
|
||||||
|
if (!"0".equals(modbusResponse.getTagId())) {
|
||||||
|
sysIdentifier = identifierService.selectIdentifierByTag(tag);
|
||||||
|
primaryRadarData.setLadleNumber(sysIdentifier.getLadleNumber());
|
||||||
|
primaryRadarData.setRadarLocation(socketModel.getRadarLocation());
|
||||||
|
primaryRadarData.setRadarIp(socketModel.getRadarIp());
|
||||||
|
} else {
|
||||||
|
primaryRadarData.setLadleNumber(null);
|
||||||
|
primaryRadarData.setRadarLocation(null);
|
||||||
|
primaryRadarData.setRadarIp(socketModel.getRadarIp());
|
||||||
|
}
|
||||||
|
if (modbusResponse.getValue4() != null && !"0".equals(modbusResponse.getValue4())) {
|
||||||
|
primaryRadarDataService.insertPrimaryRadarData(primaryRadarData);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
RadarStatusWebSocket.sendToAll(JSON.toJSONString(data));
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static ModbusResponse getModbusResponse(DataResponse data) {
|
private static ModbusResponse getModbusResponse(DataResponse data) {
|
||||||
ModbusResponse modbusResponse = new ModbusResponse();
|
ModbusResponse modbusResponse = new ModbusResponse();
|
||||||
modbusResponse.setRadarNum(data.getData().get(0).toString());
|
modbusResponse.setRadarNum(data.getData().get(0).toString());
|
||||||
|
|
@ -230,6 +239,13 @@ public class RadarStatusController {
|
||||||
return modbusResponse;
|
return modbusResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
List<SysRadar> radarList = service.selectRadarList(new SysRadar());
|
||||||
|
|
||||||
|
asyncWebSocket(radarList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConnectionStatus {
|
class ConnectionStatus {
|
||||||
boolean connected = false;
|
boolean connected = false;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ public class SysRadarController extends BaseController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult addSave(@Validated SysRadar radar) {
|
public AjaxResult addSave(@Validated SysRadar radar) {
|
||||||
radar.setCreateBy(getLoginName());
|
radar.setCreateBy(getLoginName());
|
||||||
return toAjax(radarService.insertRadar(radar));
|
int result = radarService.insertRadar(radar);
|
||||||
|
RadarStatusController.buildAllRadar(radarService.selectRadarList(new SysRadar()));
|
||||||
|
return toAjax(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -95,14 +97,17 @@ public class SysRadarController extends BaseController {
|
||||||
public AjaxResult editSave(@Validated SysRadar radar) {
|
public AjaxResult editSave(@Validated SysRadar radar) {
|
||||||
|
|
||||||
radar.setUpdateBy(getLoginName());
|
radar.setUpdateBy(getLoginName());
|
||||||
return toAjax(radarService.updateUser(radar));
|
int result = radarService.updateUser(radar);
|
||||||
|
RadarStatusController.buildAllRadar(radarService.selectRadarList(new SysRadar()));
|
||||||
|
return toAjax(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/remove")
|
@PostMapping("/remove")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult remove(String ids) {
|
public AjaxResult remove(String ids) {
|
||||||
|
int result = radarService.deleteRadarByIds(ids);
|
||||||
return toAjax(radarService.deleteRadarByIds(ids));
|
RadarStatusController.buildAllRadar(radarService.selectRadarList(new SysRadar()));
|
||||||
|
return toAjax(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -135,6 +140,7 @@ public class SysRadarController extends BaseController {
|
||||||
ExcelUtil<RadarExcel> util = new ExcelUtil<RadarExcel>(RadarExcel.class);
|
ExcelUtil<RadarExcel> util = new ExcelUtil<RadarExcel>(RadarExcel.class);
|
||||||
List<RadarExcel> radarList = util.importExcel(file.getInputStream());
|
List<RadarExcel> radarList = util.importExcel(file.getInputStream());
|
||||||
String message = radarService.importData(radarList, updateSupport);
|
String message = radarService.importData(radarList, updateSupport);
|
||||||
|
RadarStatusController.buildAllRadar(radarService.selectRadarList(new SysRadar()));
|
||||||
return AjaxResult.success(message);
|
return AjaxResult.success(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue