ソースを参照

换电记录上传

jek 1 年間 前
コミット
9754b6a296

+ 84 - 0
src/main/java/com/zhili/zkstationserver/dto/ExchangeRecordInfo.java

@@ -0,0 +1,84 @@
+package com.zhili.zkstationserver.dto;
+
+import com.zhili.zkstationserver.util.BytesUtil;
+import lombok.Data;
+import org.apache.commons.lang.ArrayUtils;
+
+/**
+ * @author :jek
+ * @title 换电记录
+ * @date :2023/2/8 17:34
+ */
+@Data
+public class ExchangeRecordInfo {
+    /** 换电编号 */
+    String exchangeNo;
+    /**	流水号*/
+    String serialNo;
+    /**	车牌号*/
+    String plate;
+    /**	vin */
+    String vin;
+    /**	车型*/
+    String model;
+    /**	站点编号*/
+    String stationCode;
+    /**	司机名字*/
+    String driverName;
+    /** 司机电话  */
+    String driverPhone;
+    /**  亏电电池sn */
+    String sourceBatterySn;
+    /**  满电电池sn */
+    String targetBatterySn;
+    /**  亏电电池容量 */
+    float sourceCapacity;
+    /** 满电电池容量  */
+    float targetCapacity;
+    /**  亏电电池soc */
+    float sourceSoc;
+    /** 满电电池soc  */
+    float targetSoc;
+    /** 亏电电池soh  */
+    float sourceSoh;
+    /**  满电电池soh */
+    float targetSoh;
+    /**  换电量 */
+    float exchangePower;
+    /**  换电费 */
+    float powerFee;
+    /** 服务费  */
+    float serviceFee;
+    /**  开始时间 */
+    String startTime;
+    /**  结束时间 */
+    String endTime;
+    /**  发起换电来源 0:小程序,1:站内手动,2:云端*/
+    Integer startSource;
+
+    public ExchangeRecordInfo(String stationCode, byte[] data) {
+        this.stationCode = stationCode;
+        exchangeNo = BytesUtil.parseString(ArrayUtils.subarray(data, 0, 32));
+        serialNo = BytesUtil.parseString(ArrayUtils.subarray(data, 32, 64));
+        plate = BytesUtil.deUnicode(ArrayUtils.subarray(data, 64, 84));
+        vin = BytesUtil.parseString(ArrayUtils.subarray(data, 84, 101));
+        model = BytesUtil.deUnicode(ArrayUtils.subarray(data, 101, 117));
+        driverName = BytesUtil.deUnicode(ArrayUtils.subarray(data, 149, 181));
+        driverPhone = BytesUtil.parseString(ArrayUtils.subarray(data, 181, 192));
+        sourceBatterySn = BytesUtil.parseString(ArrayUtils.subarray(data, 192, 219));
+        targetBatterySn = BytesUtil.parseString(ArrayUtils.subarray(data, 219, 246));
+        sourceCapacity = BytesUtil.toIntWithLowerFirst(ArrayUtils.subarray(data, 246, 248)) * 0.1f;
+        targetCapacity = BytesUtil.toIntWithLowerFirst(ArrayUtils.subarray(data, 248, 250)) * 0.1f;
+        sourceSoc = Byte.toUnsignedInt(data[250]) * 0.4f;
+        targetSoc = Byte.toUnsignedInt(data[251]) * 0.4f;
+        sourceSoh = Byte.toUnsignedInt(data[252]) * 0.4f;
+        targetSoh = Byte.toUnsignedInt(data[253]) * 0.4f;
+        exchangePower = BytesUtil.toIntWithLowerFirst(ArrayUtils.subarray(data, 254, 258)) * 0.2f;
+        powerFee = BytesUtil.toIntWithLowerFirst(ArrayUtils.subarray(data, 258, 262)) * 0.2f;
+        serviceFee = BytesUtil.toIntWithLowerFirst(ArrayUtils.subarray(data, 262, 266)) * 0.2f;
+        startTime = BytesUtil.composeTimeString(ArrayUtils.subarray(data, 266, 274));
+        endTime = BytesUtil.composeTimeString(ArrayUtils.subarray(data, 274, 282));
+        startSource =  Byte.toUnsignedInt(data[282]);
+    }
+
+}

+ 2 - 0
src/main/java/com/zhili/zkstationserver/dto/StationMessage.java

@@ -22,5 +22,7 @@ public class StationMessage {
         public static final int SIGN_IN = 401;
         public static final int SIGN_IN_REPLY = 402;
         public static final int HEART_BEAT = 403;
+        public static final int EXCHANGE_RECORD = 501;
+        public static final int EXCHANGE_RECORD_REPLY = 502;
     }
 }

+ 23 - 3
src/main/java/com/zhili/zkstationserver/handler/StationMessageHandler.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.zhili.zkstationserver.configuration.ServerConfig;
 import com.zhili.zkstationserver.dto.ChargerState;
 import com.zhili.zkstationserver.dto.ExchangeEvent;
+import com.zhili.zkstationserver.dto.ExchangeRecordInfo;
 import com.zhili.zkstationserver.dto.ExchangeStartReply;
 import com.zhili.zkstationserver.dto.StationConnInfo;
 import com.zhili.zkstationserver.dto.StationMessage;
@@ -65,7 +66,7 @@ public class StationMessageHandler extends ChannelInboundHandlerAdapter {
         StationMessage stationMessage = (StationMessage) msg;
         int command = stationMessage.getCommand();
         byte[] data = stationMessage.getData();
-        log.info("command:" + command + ",data:" + ArrayUtils.toString(data));
+        //log.info("command:" + command + ",data:" + ArrayUtils.toString(data));
         String stationCode;
         StationMessage stationMessageReply;
         byte[] replyBytes;
@@ -138,9 +139,9 @@ public class StationMessageHandler extends ChannelInboundHandlerAdapter {
                 }
                 //为了削峰,将对象构建后,放到kafka中,由业务中心处理。
                 ExchangeEvent exchangeEvent = new ExchangeEvent(stationCode, data);
-                log.info("exchangeEvent:" + exchangeEvent);
+                //log.info("exchangeEvent:" + exchangeEvent);
                 topic = serverConfig.getServiceCenterName() + "_ExchangeEvent";
-                log.info("send to {}", topic);
+                //log.info("send to {}", topic);
                 kafkaTemplate.send(topic, JSON.toJSONString(exchangeEvent));
                 break;
             case CommandType.CHARGER_STATE:
@@ -178,6 +179,25 @@ public class StationMessageHandler extends ChannelInboundHandlerAdapter {
                 log.info("启动换电回复:{}",startSwapReply);
                 kafkaTemplate.send(topic, JSON.toJSONString(startSwapReply));
                 break;
+            case CommandType.EXCHANGE_RECORD:
+                stationCode = (String) Optional.ofNullable(ctx.channel().attr(AttributeKey.valueOf("station")).get()).orElse("");
+                if (StringUtils.isEmpty(stationCode)) {
+                    break;
+                }
+                //log.info("上传换电记录:{}",data);
+                ExchangeRecordInfo exchangeRecordInfo = new ExchangeRecordInfo(stationCode,data);
+                topic = serverConfig.getServiceCenterName() + "_UploadExchangeRecord";
+                log.info("换电记录上传:{}",exchangeRecordInfo);
+                kafkaTemplate.send(topic, JSON.toJSONString(exchangeRecordInfo));
+                stationMessageReply = new StationMessage();
+                stationMessageReply.setCommand(CommandType.EXCHANGE_RECORD_REPLY);
+                replyBytes = new byte[65];
+                BytesUtil.setSubBytes(replyBytes,0, BytesUtil.fromString(exchangeRecordInfo.getExchangeNo(),32,(byte)0));
+                BytesUtil.setSubBytes(replyBytes,32, BytesUtil.fromString(exchangeRecordInfo.getSerialNo(),32,(byte)0));
+                replyBytes[64] = (byte) 0;
+                stationMessageReply.setData(replyBytes);
+                ctx.writeAndFlush(stationMessageReply);
+                break;
             default:
                 break;
         }