diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationInitResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationInitResponse.java index d24f8e6..e8dd8dc 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationInitResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/rep/TrainIndicationInitResponse.java @@ -84,7 +84,7 @@ public class TrainIndicationInitResponse extends MessageResponse { } builder.setRollingStock(trainCell.getRollingStock()); builder.setDriverId(StringUtils.defaultString(trainCell.getDriverId(), "")); - + if (trainCell.getOtpTime() != null) { builder.setOtpTime(trainCell.getOtpTime()); } @@ -151,7 +151,7 @@ public class TrainIndicationInitResponse extends MessageResponse { /** * 目的地号(4) */ - private Integer destinationId; + private String destinationId; /** * 编组数量(1) */ @@ -209,7 +209,8 @@ public class TrainIndicationInitResponse extends MessageResponse { buf.readBytes(groupId); buf.readBytes(trainId); buf.readBytes(globalId); - this.destinationId = buf.readInt(); + this.destinationId = EntityParseUtil.convertStr(buf, 4); + this.rollingStock = buf.readByte(); buf.readBytes(driverId); this.otpTime = buf.readInt(); diff --git a/src/test/java/club/joylink/xiannccda/GenertateProtoBufUtil.java b/src/test/java/club/joylink/xiannccda/GenertateProtoBufUtil.java index 2fd2d0c..57376b5 100644 --- a/src/test/java/club/joylink/xiannccda/GenertateProtoBufUtil.java +++ b/src/test/java/club/joylink/xiannccda/GenertateProtoBufUtil.java @@ -87,7 +87,7 @@ public class GenertateProtoBufUtil { } public static void main(String[] args) throws IOException { - GenertateProtoBufUtil gu = new GenertateProtoBufUtil(System.getProperty("user.dir"), false); + GenertateProtoBufUtil gu = new GenertateProtoBufUtil(System.getProperty("user.dir"), true); gu.execCommand(); } } diff --git a/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java b/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java index 5b3fec7..a0919dc 100644 --- a/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java +++ b/src/test/java/club/joylink/xiannccda/device/TrainDataTest.java @@ -90,7 +90,7 @@ public class TrainDataTest { /** * 目的地号(4) */ - updateResponse.setDestinationId(1); +// updateResponse.setDestinationId(1); /** * 编组数量(1) */ diff --git a/src/test/java/club/joylink/xiannccda/util/CollectorData.java b/src/test/java/club/joylink/xiannccda/util/CollectorData.java new file mode 100644 index 0000000..7e10bfe --- /dev/null +++ b/src/test/java/club/joylink/xiannccda/util/CollectorData.java @@ -0,0 +1,151 @@ +package club.joylink.xiannccda.util; + +import club.joylink.xiannccda.ats.message.MessageResponse; +import club.joylink.xiannccda.ats.message.line3.device.DeviceType; +import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse; +import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse.DeviceEntity; +import club.joylink.xiannccda.ats.message.line3.rep.DeviceStatusBitmapResponse.DeviceTypeEntity; +import club.joylink.xiannccda.ats.message.line3.rep.TrainIndicationUpdateResponse; +import club.joylink.xiannccda.mock.message.NccMockData; +import club.joylink.xiannccda.mock.message.NccMockDataService; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Lists; +import com.google.common.collect.Table; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class CollectorData { + + + @Autowired + NccMockDataService nccMockDataService; + +/* @Test + public void dd() throws UnsupportedEncodingException { + + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(NccMockData::getMsgId, "TRAIN_INDICATION_UPDATE"); + List datas = this.nccMockDataService.loadALLData(queryWrapper); + List bitmapResponses = datas.stream().map(d -> (TrainIndicationUpdateResponse) d).collect(Collectors.toList()); + Set sets = new HashSet<>(); + + for (TrainIndicationUpdateResponse bitmapRespons : bitmapResponses) { + ByteBuf buf = Unpooled.buffer(); + +// buf.writeInt(842413824); + buf.writeInt(bitmapRespons.getDestinationId()); + byte[] dd = new byte[4]; + buf.readBytes(dd); + String s = new String(dd, "utf-8"); + if (StringUtils.isEmpty(s.trim())) { + System.out.println(bitmapRespons); + } + sets.add(s); + } + System.out.println(sets); + }*/ + + @Test + public void collector() { + + Table> dataTable = this.loadData(); + + JSONObject jo = this.readData(); + for (DeviceType deviceType : dataTable.rowKeySet()) { + Map> maps = dataTable.row(deviceType); + File file = new File("d:\\usr\\" + deviceType.name()); + if (file.exists()) { + file.delete(); + } + maps.forEach((k, v) -> { + + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)))) { + Map> findMaper = Device.match(v, deviceType, jo); + writer.write(String.format("集中站:%s \n", k)); + for (Boolean aBoolean : findMaper.keySet()) { + writer.write("\t\t" + aBoolean + "\n"); + writer.write("\t\t" + JSON.toJSONString(findMaper.get(aBoolean)) + "\n"); + } + writer.write("-----------------------------------\n"); + } catch (Exception e) { + e.printStackTrace(); + } + }); + } + } + + + private Table> loadData() { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(NccMockData::getMsgId, "DEVICE_STATUS_BITMAP"); + + List datas = this.nccMockDataService.loadALLData(queryWrapper); + List bitmapResponses = datas.stream().map(d -> (DeviceStatusBitmapResponse) d).collect(Collectors.toList()); + Table> dataTable = HashBasedTable.create(); + List dd = Lists.newArrayList(); + for (DeviceStatusBitmapResponse bitmapRespons : bitmapResponses) { + String rtuId = bitmapRespons.getRtuId().toString(); + for (DeviceTypeEntity deviceTypeEntity : bitmapRespons.getEntityList()) { + DeviceType dt = deviceTypeEntity.getType(); + if (!dd.contains(dt.name())) { + dd.add(dt.name()); + } + if (CollectionUtils.isNotEmpty(deviceTypeEntity.getDeviceList())) { + for (DeviceEntity deviceEntity : deviceTypeEntity.getDeviceList()) { + String deviceName = deviceEntity.getDevName(); + List deviceList = dataTable.get(dt, rtuId); + if (Objects.isNull(deviceList)) { + deviceList = Lists.newArrayList(); + } + if (!deviceList.contains(deviceName)) { + deviceList.add(deviceName); + } + dataTable.put(dt, rtuId, deviceList); + } + } + } + } + return dataTable; + } + + + private JSONObject readData() { + + try (BufferedReader reader = new BufferedReader(new FileReader("G:\\map.txt"))) { + String content = null; + StringBuilder sb = new StringBuilder(); + while ((content = reader.readLine()) != null) { + sb.append(content); + } + return JSON.parseObject(sb.toString()); + } catch (Exception e) { + + } + return null; + } + + +} diff --git a/xian-ncc-da-message b/xian-ncc-da-message index 2b1cf46..f86b357 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit 2b1cf46a4bece01bce4b3269e4fcf094f8117492 +Subproject commit f86b35768560ddd4e2a3bef70c9b8dfe42510d8f