模拟数据接口调整
This commit is contained in:
parent
071e8b3231
commit
2219ea9aa1
@ -2,6 +2,7 @@ package club.joylink.xiannccda.ats.message;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -14,6 +15,14 @@ public class OccMessageManage implements ApplicationRunner {
|
|||||||
|
|
||||||
Map<Integer, XianOccMessagingClient> clientMap = new HashMap<>();
|
Map<Integer, XianOccMessagingClient> clientMap = new HashMap<>();
|
||||||
|
|
||||||
|
public void sendMsg(Integer lineId, MessageData md) {
|
||||||
|
XianOccMessagingClient client = this.clientMap.get(lineId);
|
||||||
|
if (Objects.isNull(client)) {
|
||||||
|
throw new RuntimeException("未获取到对应的occ客户端");
|
||||||
|
}
|
||||||
|
client.send(md);
|
||||||
|
}
|
||||||
|
|
||||||
public void registerClient(XianOccMessagingClient client) {
|
public void registerClient(XianOccMessagingClient client) {
|
||||||
clientMap.put(client.lineId, client);
|
clientMap.put(client.lineId, client);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,11 @@ public class OccTcpClientConnection {
|
|||||||
*/
|
*/
|
||||||
volatile long lastReceiveMessageTime;
|
volatile long lastReceiveMessageTime;
|
||||||
|
|
||||||
|
public void write(MessageData messageData) {
|
||||||
|
this.channel.write(messageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public OccTcpClientConnection(XianOccMessagingClient client, String host, int port) {
|
public OccTcpClientConnection(XianOccMessagingClient client, String host, int port) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
@ -8,8 +8,7 @@ public class XianOccMessagingClient {
|
|||||||
final int realTimePortBase = 2600;
|
final int realTimePortBase = 2600;
|
||||||
final int nonRealTimePortBase = 2700;
|
final int nonRealTimePortBase = 2700;
|
||||||
/**
|
/**
|
||||||
* 线路号 实时信息的侦听端口号为2600+line_id,非实时信息的侦听端口号为2700+line_id。
|
* 线路号 实时信息的侦听端口号为2600+line_id,非实时信息的侦听端口号为2700+line_id。 (如对于地铁1号线来说,实时信息的侦听端口号为2601,非实时信息的侦听端口号为2701)
|
||||||
* (如对于地铁1号线来说,实时信息的侦听端口号为2601,非实时信息的侦听端口号为2701)
|
|
||||||
*/
|
*/
|
||||||
final int lineId;
|
final int lineId;
|
||||||
final String host;
|
final String host;
|
||||||
@ -23,6 +22,13 @@ public class XianOccMessagingClient {
|
|||||||
*/
|
*/
|
||||||
private final OccTcpClientConnection nrtConnection;
|
private final OccTcpClientConnection nrtConnection;
|
||||||
|
|
||||||
|
public void send(MessageData md) {
|
||||||
|
if (rtConnection.connected) {
|
||||||
|
this.rtConnection.write(md);
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("未连接occ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public XianOccMessagingClient(int lineId, String host) {
|
public XianOccMessagingClient(int lineId, String host) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
@ -34,6 +40,7 @@ public class XianOccMessagingClient {
|
|||||||
this.nrtConnection = new OccTcpClientConnection(this, host, nonRealTimePort);
|
this.nrtConnection = new OccTcpClientConnection(this, host, nonRealTimePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 连接OCC服务
|
* 连接OCC服务
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,7 @@ public abstract class DeviceStatusDataRepository {
|
|||||||
|
|
||||||
|
|
||||||
public static void addTrain(String lineCode, List<Builder> builders) {
|
public static void addTrain(String lineCode, List<Builder> builders) {
|
||||||
TrainInfoData data = trainDataMap.computeIfAbsent(lineCode, TrainInfoData::new);
|
TrainInfoData data = getAllTrainInfo(lineCode);
|
||||||
for (Builder builder : builders) {
|
for (Builder builder : builders) {
|
||||||
data.addTrain(builder);
|
data.addTrain(builder);
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ public abstract class DeviceStatusDataRepository {
|
|||||||
* @param builders 设备信息
|
* @param builders 设备信息
|
||||||
*/
|
*/
|
||||||
public static void addDeviceStatusDataList(String lineCode, List<Builder> builders) {
|
public static void addDeviceStatusDataList(String lineCode, List<Builder> builders) {
|
||||||
DeviceStatusData data = lineStatusDataMap.computeIfAbsent(lineCode, DeviceStatusData::new);
|
DeviceStatusData data = getDeviceStatusData(lineCode);
|
||||||
DeviceStatusDataOperate.addDevices(builders, data);
|
DeviceStatusDataOperate.addDevices(builders, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package club.joylink.xiannccda.mock.message;
|
package club.joylink.xiannccda.mock.message;
|
||||||
|
|
||||||
|
import club.joylink.xiannccda.ats.message.OccMessageManage;
|
||||||
|
import club.joylink.xiannccda.ats.message.line3.req.LoadDeviceStatusRequest;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@ -14,10 +17,21 @@ public class MockDeviceController {
|
|||||||
|
|
||||||
private final NccMockDataService mockDataService;
|
private final NccMockDataService mockDataService;
|
||||||
|
|
||||||
|
private final OccMessageManage occMessageManage;
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("reset")
|
@GetMapping("reset")
|
||||||
@Operation(summary = "重置设备状态")
|
@Operation(summary = "重置设备状态")
|
||||||
@ApiResponse(description = "重置设备状态")
|
@ApiResponse(description = "重置设备状态")
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.mockDataService.reset();
|
this.mockDataService.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("ats设备信息")
|
||||||
|
@Operation(summary = "ats设备信息")
|
||||||
|
@ApiResponse(description = "ats设备信息")
|
||||||
|
public void atsRequest(@RequestParam("lineId") Integer lineId) {
|
||||||
|
LoadDeviceStatusRequest deviceStatusRequest = new LoadDeviceStatusRequest(lineId.shortValue());
|
||||||
|
this.occMessageManage.sendMsg(lineId, deviceStatusRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class MockLoadData implements ApplicationRunner {
|
|||||||
|
|
||||||
static final ScheduledExecutorService CIRCLE_QUERY_THREAD = Executors.newSingleThreadScheduledExecutor();
|
static final ScheduledExecutorService CIRCLE_QUERY_THREAD = Executors.newSingleThreadScheduledExecutor();
|
||||||
private final NccMockDataService nccMockDataService;
|
private final NccMockDataService nccMockDataService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
this.nccMockDataService.reset(1);
|
this.nccMockDataService.reset(1);
|
||||||
@ -42,7 +42,8 @@ public class MockLoadData implements ApplicationRunner {
|
|||||||
private void loadAllDevice() {
|
private void loadAllDevice() {
|
||||||
Wrapper<NccMockData> wrapper = Wrappers.<NccMockData>lambdaQuery()
|
Wrapper<NccMockData> wrapper = Wrappers.<NccMockData>lambdaQuery()
|
||||||
.eq(NccMockData::getActionType, ActionTypeEnum.ALL.name())
|
.eq(NccMockData::getActionType, ActionTypeEnum.ALL.name())
|
||||||
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name());
|
.eq(NccMockData::getMsgType, MsgTypeEnum.REAL_TIME.name())
|
||||||
|
.eq(NccMockData::getMsgId, MessageId.DEVICE_STATUS_BITMAP.name());
|
||||||
List<MessageData> dataList = this.nccMockDataService.loadALLData(wrapper);
|
List<MessageData> dataList = this.nccMockDataService.loadALLData(wrapper);
|
||||||
try {
|
try {
|
||||||
for (MessageData messageData : dataList) {
|
for (MessageData messageData : dataList) {
|
||||||
|
Loading…
Reference in New Issue
Block a user