Commit 77c1b559 authored by duanruiming's avatar duanruiming

[update] 代码优化

parent af7a9b2f
......@@ -2,6 +2,7 @@ package net.wanji.web.task;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.databus.po.BaseCrossInfoPO;
......@@ -13,7 +14,6 @@ import net.wanji.web.mapper.TDeviceStatusMapper;
import net.wanji.web.service.SituationDetectionService;
import net.wanji.web.vo.situationDetection.CommonEventAlarmOutVo;
import net.wanji.web.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
......@@ -30,16 +30,13 @@ import java.util.*;
*/
@Component
@Slf4j
@SuppressWarnings("all")
@RequiredArgsConstructor
public class CommonEventWarnTask {
@Autowired
private UtcFeignClients utcFeignClients;
@Autowired
private SituationDetectionService situationDetectionService;
@Autowired
private TDeviceStatusMapper tDeviceStatusMapper;
private final UtcFeignClients utcFeignClients;
private final SituationDetectionService situationDetectionService;
private final TDeviceStatusMapper tDeviceStatusMapper;
@Scheduled(fixedRate = 30 * 1000)
public void pushEvenWarnData() {
......@@ -49,7 +46,7 @@ public class CommonEventWarnTask {
log.info("告警socket连接数量:{},告警信息:{}", events.size(), events);
for (WebSocketServer entry : events) {
String userId = entry.getUserId();
commonEnventWarnDataSend(userId);
commonEventWarnDataSend(userId);
}
}
} catch (Exception e) {
......@@ -57,7 +54,7 @@ public class CommonEventWarnTask {
}
}
private void commonEnventWarnDataSend(String userId) throws IOException {
private void commonEventWarnDataSend(String userId) throws IOException {
// 信号机故障
JsonViewObject signalWarnData = getSignalWarnData();
if (Objects.nonNull(signalWarnData)) {
......@@ -94,8 +91,7 @@ public class CommonEventWarnTask {
LocalDateTime now = LocalDateTime.now();
String formatNow = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(now);
List<Map<String, Object>> content = (List<Map<String, Object>>) jsonViewObject.getContent();
content.forEach(map -> {
Map<String, Object> result = map;
content.forEach(result -> {
String signalId = (String) result.get("signalId");
String crossId = (String) result.get("crossId");
Integer currentStatus = (Integer) result.get("status");
......@@ -145,7 +141,7 @@ public class CommonEventWarnTask {
*/
private static void buildSignalWarnData(List<CommonEventAlarmOutVo> results, String formatNow, String signalId, Integer currentStatus, Integer currentFaultType, String coordinate, String crossName, TDeviceStatusInfo tDeviceStatusInfo1) {
try {
if (SignalStatusTask.isExucuteUpdate(currentStatus, currentFaultType, tDeviceStatusInfo1)) {
if (SignalStatusTask.isExecuteUpdate(currentStatus, currentFaultType, tDeviceStatusInfo1)) {
log.error("测试日志,执行信号机状态修改成功");
CommonEventAlarmOutVo commonEventAlarmOutVo = new CommonEventAlarmOutVo();
commonEventAlarmOutVo.setEventType(3);
......
......@@ -49,7 +49,6 @@ public class RealTimeCarTask {
tempList.add(new TempPojo(112.963046, 28.182838));
tempList.add(new TempPojo(112.963092, 28.184083));
tempList.add(new TempPojo(112.963606, 28.188246));
tempList.add(new TempPojo(112.963711, 28.189290));
tempList.add(new TempPojo(112.967486, 28.187118));
}
......@@ -58,7 +57,7 @@ public class RealTimeCarTask {
// threadPoolExecutor.execute(() -> {
int i = atomicInteger.get();
atomicInteger.incrementAndGet();
if (i == 7) {
if (i == 6) {
atomicInteger.set(0);
}
Set<WebSocketServer> events = WebSocketServer.getWebSocketSet(Constant.WEBSOCKET_TOPIC_CAR_TRAIL_INFO);
......
......@@ -38,7 +38,7 @@ public class SignalStatusTask {
private final TDeviceStatusLogMapper tDeviceStatusLogMapper;
private final BaseCrossInfoMapper baseCrossInfoMapper;
@Scheduled(fixedRate = 1 * 30 * 1000)
@Scheduled(fixedRate = 30 * 1000)
@Transactional
public void syncSignalStatus() {
try {
......@@ -102,7 +102,7 @@ public class SignalStatusTask {
lambdaQueryWrapper.eq(TDeviceStatusInfo::getCode, crossId);
TDeviceStatusInfo tDeviceStatusInfo = tDeviceStatusMapper.selectOne(lambdaQueryWrapper);
if (Objects.nonNull(tDeviceStatusInfo)) {
if (isExucuteUpdate(currentSignalStatus, currentFaultType, tDeviceStatusInfo)) {
if (isExecuteUpdate(currentSignalStatus, currentFaultType, tDeviceStatusInfo)) {
tDeviceStatusInfo.setStatus(currentSignalStatus);
tDeviceStatusInfo.setFaultType(currentFaultType);
tDeviceStatusInfo.setGmtCreate(new Date()); // 实时数据,创建和修改时间一致
......@@ -168,9 +168,9 @@ public class SignalStatusTask {
}
}
public static boolean isExucuteUpdate(Integer currentSignalStatus, Integer currentFaultType, TDeviceStatusInfo tDeviceStatusInfo) {
public static boolean isExecuteUpdate(Integer currentSignalStatus, Integer currentFaultType, TDeviceStatusInfo tDeviceStatusInfo) {
// 故障自定义,当故障时,状态对应海康在线
int status = tDeviceStatusInfo.getStatus() == 2 ? 1 : tDeviceStatusInfo.getStatus();
return Objects.nonNull(tDeviceStatusInfo) && (currentSignalStatus != status || currentFaultType != tDeviceStatusInfo.getFaultType());
return currentSignalStatus != status || currentFaultType != tDeviceStatusInfo.getFaultType();
}
}
......@@ -29,7 +29,7 @@ public class SystemServiceStatusTask {
private static final String HIK_LOCAL_IP = "10.102.1.183";
public static final List<SystemServiceStatusDTO> sysList = new ArrayList<SystemServiceStatusDTO>();
public static final List<SystemServiceStatusDTO> sysList = new ArrayList<>();
static {
sysList.add(new SystemServiceStatusDTO("MYSQL", LOCAL_IP, 3306, 30000, 0, null, null));
......@@ -37,7 +37,7 @@ public class SystemServiceStatusTask {
sysList.add(new SystemServiceStatusDTO("海康", HIK_LOCAL_IP, 80, 30000, 0, null, null));
}
@Scheduled(fixedRate = 1 * 60 * 1000)
@Scheduled(fixedRate = 60 * 1000)
public void telnetStatus() throws Exception {
Set<WebSocketServer> webSocketSet = WebSocketServer.getWebSocketSet(Constant.WEBSOCKET_TOPIC_SYS_SERVICE_STATUS);
if (!CollectionUtils.isEmpty(webSocketSet)) {
......@@ -46,7 +46,7 @@ public class SystemServiceStatusTask {
int port = dto.getPort();
int timeout = dto.getTimeout();
int lastStatus = dto.getStatus();
int currentStatus = SocketUtil.telnet(ip, port, timeout) == true ? 0 : 1;
int currentStatus = SocketUtil.telnet(ip, port, timeout) ? 0 : 1;
if (currentStatus != lastStatus) {
dto.setStatus(currentStatus);
}
......
......@@ -31,7 +31,7 @@ public class WebSocketServer {
/**
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
*/
private static ConcurrentHashMap<String, Set<WebSocketServer>> webSocketMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<String, Set<WebSocketServer>> webSocketMap = new ConcurrentHashMap<>();
/**
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment