模拟数据请求

This commit is contained in:
tiger_zhou 2023-06-29 13:18:08 +08:00
parent 494e8ccb2e
commit e8ba67dae7
9 changed files with 195 additions and 104 deletions

View File

@ -61,7 +61,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
<version>2.0.2</version>
</dependency>
<!-- mybatis-plus -->

View File

@ -15,12 +15,12 @@ public class OccMessageManage implements ApplicationRunner {
Map<Integer, XianOccMessagingClient> clientMap = new HashMap<>();
public void sendMsg(Integer lineId, MessageData md) {
public void sendMsg(Integer lineId, MessageData md, boolean isRealTime) {
XianOccMessagingClient client = this.clientMap.get(lineId);
if (Objects.isNull(client)) {
throw new RuntimeException("未获取到对应的occ客户端");
}
client.send(md);
client.send(md, isRealTime);
}
public void registerClient(XianOccMessagingClient client) {

View File

@ -7,6 +7,7 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -39,7 +40,7 @@ public class OccTcpClientConnection {
volatile long lastReceiveMessageTime;
public void write(MessageData messageData) {
this.channel.write(messageData);
this.channel.writeAndFlush(List.of(messageData));
}

View File

@ -22,14 +22,17 @@ public class XianOccMessagingClient {
*/
private final OccTcpClientConnection nrtConnection;
public void send(MessageData md) {
if (rtConnection.connected) {
this.rtConnection.write(md);
public void send(MessageData md, boolean isRealTime) {
OccTcpClientConnection conn = isRealTime ? rtConnection : nrtConnection;
if (conn.connected) {
conn.write(md);
} else {
throw new RuntimeException("未连接occ");
}
}
public XianOccMessagingClient(int lineId, String host) {
this.host = host;
this.lineId = lineId;

View File

@ -4,6 +4,8 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.apache.commons.lang3.StringUtils;
public class DateTimeUtil {
@ -27,6 +29,29 @@ public class DateTimeUtil {
buf.writeByte(from.getSecond());
}
public static LocalDateTime parse(String dateTimeStr, DateTimeFormatter formatter) {
if (StringUtils.isEmpty(dateTimeStr)) {
return null;
}
try {
return LocalDateTime.parse(dateTimeStr, formatter);
} catch (Exception e) {
throw new RuntimeException("解析时间错误", e);
}
}
public static byte[] convert(String dateTimeStr, DateTimeFormatter formatter) {
try {
LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, formatter);
return convert(dateTime);
} catch (Exception e) {
throw new RuntimeException("解析时间错误", e);
}
}
/**
* 例如传送2001年9月21日15时29分30秒则年秒各单元的值分别为2001921152930
*/

View File

@ -7,99 +7,113 @@ import io.netty.buffer.ByteBuf;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Objects;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.util.CollectionUtils;
/**
* 2.8.1 统计信息查询消息
*/
public class ReportAskRequest extends MessageRequest {
/**
* 线路号(2)
*/
private Short lineId;
/**
* 查询标识号(2)<br>
* 同一时间多个查询的report_id不允许重复答复消息中的report_id值跟查询消息中的相同
*/
private Short reportId;
/**
* 消息种类(2)<br>
* 1车组运行里程报告<br>
* 2司机驾驶里程报告<br>
* 3调度日志报告<br>
* 4存备车报告<br>
* 5列车整备状态报告<br>
*/
private Short msgFlag;
/**
* 消息内容(7)<br>
* 当消息种类为2或3时消息内容为调度日期格式
*/
private byte[] msgContent;
/**
* 预留(7)
*/
private byte[] reserve;
public ReportAskRequest(final short lineId,final short reportId,final MsgFlagEnum msgFlag){
super(MessageId.REPORT_ASK,2+2+2+7+7);
this.lineId=lineId;
this.reportId=reportId;
this.msgFlag=msgFlag.flag;
this.reserve=new byte[7];
Arrays.fill(this.reserve, (byte) 0);
this.msgContent=new byte[7];
Arrays.fill(this.msgContent, (byte) 0);
}
/**
* 填充消息内容(7)<br>
* 当消息种类为2或3时消息内容为调度日期格式<br>
* 例如传送2001年9月21日15时29分30秒则年秒各单元的值分别为2001921152930
*/
public ReportAskRequest fillMsgContentOfDate(final LocalDateTime msgContent){
DateTimeUtil.convert(msgContent,this.msgContent);
return this;
}
@Override
public void encode2(ByteBuf buf) {
buf.writeShort(this.lineId);
buf.writeShort(this.reportId);
buf.writeShort(this.msgFlag);
buf.writeBytes(this.msgContent);
buf.writeBytes(this.reserve);
/**
* 线路号(2)
*/
private Short lineId;
/**
* 查询标识号(2)<br> 同一时间多个查询的report_id不允许重复答复消息中的report_id值跟查询消息中的相同
*/
private Short reportId;
/**
* 消息种类(2)<br> 1车组运行里程报告<br> 2司机驾驶里程报告<br> 3调度日志报告<br> 4存备车报告<br> 5列车整备状态报告<br>
*/
private Short msgFlag;
/**
* 消息内容(7)<br> 当消息种类为2或3时消息内容为调度日期格式
*/
private byte[] msgContent;
/**
* 预留(7)
*/
private byte[] reserve;
public ReportAskRequest(final short lineId, final short reportId, final MsgFlagEnum msgFlag, LocalDateTime localDateTime) {
super(MessageId.REPORT_ASK, 2 + 2 + 2 + 7 + 7);
this.lineId = lineId;
this.reportId = reportId;
this.msgFlag = msgFlag.flag;
this.reserve = new byte[7];
Arrays.fill(this.reserve, (byte) 0);
if ((this.msgFlag == MsgFlagEnum.DRIVER_DISTANCE_REPORT.flag || this.msgFlag == MsgFlagEnum.DISPATCHER_REPORT.flag)) {
if (Objects.isNull(localDateTime)) {
throw new RuntimeException("查询 司机驾驶里程报告 或 调度日志报告 时间不能为空");
} else {
this.msgContent = DateTimeUtil.convert(localDateTime);
}
} else {
this.msgContent = new byte[7];
Arrays.fill(this.msgContent, (byte) 0);
}
}
public ReportAskRequest(final short lineId, final short reportId, final MsgFlagEnum msgFlag) {
super(MessageId.REPORT_ASK, 2 + 2 + 2 + 7 + 7);
this.lineId = lineId;
this.reportId = reportId;
this.msgFlag = msgFlag.flag;
this.reserve = new byte[7];
Arrays.fill(this.reserve, (byte) 0);
this.msgContent = new byte[7];
Arrays.fill(this.msgContent, (byte) 0);
}
/**
* 填充消息内容(7)<br> 当消息种类为2或3时消息内容为调度日期格式<br> 例如传送2001年9月21日15时29分30秒则年秒各单元的值分别为2001921152930
*/
public ReportAskRequest fillMsgContentOfDate(final LocalDateTime msgContent) {
DateTimeUtil.convert(msgContent, this.msgContent);
return this;
}
@Override
public void encode2(ByteBuf buf) {
buf.writeShort(this.lineId);
buf.writeShort(this.reportId);
buf.writeShort(this.msgFlag);
buf.writeBytes(this.msgContent);
buf.writeBytes(this.reserve);
}
/**
* 消息种类(2)<br> 1车组运行里程报告<br> 2司机驾驶里程报告<br> 3调度日志报告<br> 4存备车报告<br> 5列车整备状态报告<br>
*/
public static enum MsgFlagEnum {
/**
* 消息种类(2)<br>
* 1车组运行里程报告<br>
* 2司机驾驶里程报告<br>
* 3调度日志报告<br>
* 4存备车报告<br>
* 5列车整备状态报告<br>
* 1车组运行里程报告
*/
public static enum MsgFlagEnum{
/**
* 1车组运行里程报告
*/
GROUP_RUNNING_REPORT(1),
/**
* 2司机驾驶里程报告
*/
DRIVER_DISTANCE_REPORT(2),
/**
* 3调度日志报告
*/
DISPATCHER_REPORT(3),
/**
* 4存备车报告
*/
GROUP_BAK_REPORT(4),
/**
* 5列车整备状态报告
*/
GROUP_STATUS_REPORT(5),
;
private short flag;
private MsgFlagEnum(int flag){
this.flag = (short) flag;
}
GROUP_RUNNING_REPORT(1),
/**
* 2司机驾驶里程报告
*/
DRIVER_DISTANCE_REPORT(2),
/**
* 3调度日志报告
*/
DISPATCHER_REPORT(3),
/**
* 4存备车报告
*/
GROUP_BAK_REPORT(4),
/**
* 5列车整备状态报告
*/
GROUP_STATUS_REPORT(5),
;
private short flag;
private MsgFlagEnum(int flag) {
this.flag = (short) flag;
}
}
}

View File

@ -58,7 +58,7 @@ public class SpringSecurityConfiguration {
static {
AuthWhiteList.add(AntPathRequestMatcher.antMatcher(HttpMethod.POST, "/api/user/register"));
AuthWhiteList.add(AntPathRequestMatcher.antMatcher(HttpMethod.POST, "/api/user/login"));
AuthWhiteList.add(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/mock/**/*"));//测试使用过后删除或注释
AuthWhiteList.add(AntPathRequestMatcher.antMatcher("/mock/**/*"));//测试使用过后删除或注释
AuthWhiteList.add(AntPathRequestMatcher.antMatcher("/ws-default"));
AuthWhiteList.add(AntPathRequestMatcher.antMatcher("/swagger-ui/**"));
AuthWhiteList.add(AntPathRequestMatcher.antMatcher("/api-docs/**"));

View File

@ -1,37 +1,83 @@
package club.joylink.xiannccda.mock.message;
import club.joylink.xiannccda.ats.message.OccMessageManage;
import club.joylink.xiannccda.ats.message.line3.DateTimeUtil;
import club.joylink.xiannccda.ats.message.line3.req.AlarmAckRequest;
import club.joylink.xiannccda.ats.message.line3.req.AlarmAckRequest.MsgTypeEnum;
import club.joylink.xiannccda.ats.message.line3.req.LoadDeviceStatusRequest;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum;
import club.joylink.xiannccda.ats.message.line3.req.ReportAskRequest;
import club.joylink.xiannccda.ats.message.line3.req.ReportAskRequest.MsgFlagEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/mock")
@RequiredArgsConstructor
@Tag(name = "mock")
public class MockDeviceController {
private final NccMockDataService mockDataService;
private final OccMessageManage occMessageManage;
@Autowired
private NccMockDataService mockDataService;
@Autowired
private OccMessageManage occMessageManage;
@GetMapping("reset")
@Operation(summary = "重置设备状态")
@ApiResponse(description = "重置设备状态")
public void reset() {
this.mockDataService.reset();
}
@GetMapping("ats设备信息")
@GetMapping("load/device")
@Operation(summary = "ats设备信息")
@ApiResponse(description = "ats设备信息")
public void atsRequest(@RequestParam("lineId") Integer lineId) {
LoadDeviceStatusRequest deviceStatusRequest = new LoadDeviceStatusRequest(lineId.shortValue());
this.occMessageManage.sendMsg(lineId, deviceStatusRequest);
this.occMessageManage.sendMsg(lineId, deviceStatusRequest, true);
}
@PostMapping("load/reportAsk")
@Operation(summary = "统计信息查询")
public void reportAskRequest(@RequestParam("lineId") Integer lineId,
@RequestParam("reportId") Short reportId,
@RequestParam("msgFlag") MsgFlagEnum msgFlag, @RequestParam(value = "content", required = false) String content) {
LocalDateTime dateTime = DateTimeUtil.parse(content, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
ReportAskRequest askRequest = new ReportAskRequest(lineId.shortValue(), reportId, msgFlag, dateTime);
this.occMessageManage.sendMsg(lineId, askRequest, false);
}
@GetMapping("load/alarm")
@Operation(summary = "事件及告警信息请求")
public void alarmAckRequest(@RequestParam("lineId") Integer lineId,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
@RequestParam(value = "startDateTime", defaultValue = "2023-07-07 11:11:11") LocalDateTime startDateTime,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
@RequestParam(value = "endDateTime", defaultValue = "2023-07-07 11:11:11") LocalDateTime endDateTime,
@RequestParam("msgType") MsgTypeEnum typeEnum,
@RequestParam("reportId") Short reportId) {
AlarmAckRequest aar = new AlarmAckRequest(lineId.shortValue(), reportId, typeEnum, startDateTime, endDateTime);
this.occMessageManage.sendMsg(lineId, aar, false);
}
@GetMapping("load/history")
@Operation(summary = "历史运行图申请消息")
public void loadHistoryTgRequest(@RequestParam("lineId") Integer lineId,
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
@RequestParam(value = "localDateTime", defaultValue = "2023-07-07 11:11:11") LocalDateTime localDateTime,
@RequestParam("applyType") ApplyTypeEnum typeEnum) {
LoadHistoryTGDataRequest tgDataRequest = new LoadHistoryTGDataRequest(lineId.shortValue(), localDateTime, typeEnum);
this.occMessageManage.sendMsg(lineId, tgDataRequest, false);
}
}

View File

@ -19,7 +19,9 @@ key:
public: classpath:app.pub
private: classpath:app.key
spring-doc:
packages-to-scan: club.joylink.xiannccda.controller
packages-to-scan:
- club.joylink.xiannccda.controller
- club.joylink.xiannccda.mock.message
swagger-ui:
enabled: true
api-docs: