雷达新增和删除

detached
王宇航 2024-01-25 10:24:14 +08:00
parent c403a9622f
commit f1af214b75
4 changed files with 19 additions and 3 deletions

View File

@ -43,6 +43,7 @@ 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; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
/** /**
* *
@ -183,6 +184,7 @@ public class RadarStatusController implements InitializingBean {
try { try {
Socket socket = new Socket(radar.getRadarIp(), 23); Socket socket = new Socket(radar.getRadarIp(), 23);
SocketModel socketModel = new SocketModel(); SocketModel socketModel = new SocketModel();
socketModel.setId(radar.getId());
socketModel.setRadarLocation(radar.getRadarLocation()); socketModel.setRadarLocation(radar.getRadarLocation());
socketModel.setSocket(socket); socketModel.setSocket(socket);
socketModel.setRadarIp(radar.getRadarIp()); socketModel.setRadarIp(radar.getRadarIp());
@ -193,6 +195,17 @@ public class RadarStatusController implements InitializingBean {
} }
} }
public static void addRadar(List<SysRadar> radarList) {
List<Long> idList = allRadar.stream().map(SocketModel::getId).collect(Collectors.toList());
List<SysRadar> filterList = radarList.stream().filter(item -> !idList.contains(item.getId())).collect(Collectors.toList());
buildAllRadar(filterList);
}
public static void delRadar(Long id) {
allRadar.removeIf(item -> item.getId().equals(id));
}
private void asyncReadRadar(SocketModel socketModel) { private void asyncReadRadar(SocketModel socketModel) {
CompletableFuture.runAsync(()->{ CompletableFuture.runAsync(()->{
try { try {

View File

@ -73,7 +73,8 @@ public class SysRadarController extends BaseController {
public AjaxResult addSave(@Validated SysRadar radar) { public AjaxResult addSave(@Validated SysRadar radar) {
radar.setCreateBy(getLoginName()); radar.setCreateBy(getLoginName());
int result = radarService.insertRadar(radar); int result = radarService.insertRadar(radar);
RadarStatusController.buildAllRadar(radarService.selectRadarList(new SysRadar())); List<SysRadar> sysRadars = radarService.selectRadarList(new SysRadar());
RadarStatusController.addRadar(sysRadars);
return toAjax(result); return toAjax(result);
} }
@ -106,7 +107,7 @@ public class SysRadarController extends BaseController {
@ResponseBody @ResponseBody
public AjaxResult remove(String ids) { public AjaxResult remove(String ids) {
int result = radarService.deleteRadarByIds(ids); int result = radarService.deleteRadarByIds(ids);
RadarStatusController.buildAllRadar(radarService.selectRadarList(new SysRadar())); RadarStatusController.delRadar(Long.valueOf(ids));
return toAjax(result); return toAjax(result);
} }

View File

@ -6,6 +6,8 @@ import java.net.Socket;
@Data @Data
public class SocketModel { public class SocketModel {
private Long id;
private String radarIp; private String radarIp;
private String radarLocation; private String radarLocation;

View File

@ -35,7 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sort != null and sort != 0"> <if test="sort != null and sort != 0">
AND r.sort = #{sort} AND r.sort = #{sort}
</if> </if>
order by id asc order by id desc
</select> </select>
<insert id="insertRadar"> <insert id="insertRadar">