mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
update 电单车协议
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package com.jsowell.netty.decoder;
|
||||
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class MessageDecode extends ByteToMessageDecoder {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
// 检查是否有足够的字节可以读取
|
||||
if (in.readableBytes() < 14) { // 最小长度(包头3 + 长度2 + 物理ID4 + 消息ID2 + 命令1 + 校验2)
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取所有可读字节
|
||||
byte[] bytes = new byte[in.readableBytes()];
|
||||
in.readBytes(bytes);
|
||||
|
||||
// 解析字节数组
|
||||
AbsEBikeMessage message = AbsEBikeMessage.parseMessage(bytes);
|
||||
out.add(message);
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,8 @@ public class StartAndLengthFieldFrameDecoder extends ByteToMessageDecoder {
|
||||
// 读取 data 数据
|
||||
ByteBuf frame = buffer.retainedSlice(beginReader, HEADER_LENGTH_DNY + length + 2);
|
||||
buffer.readerIndex(beginReader + HEADER_LENGTH_DNY + length + 2);
|
||||
|
||||
|
||||
out.add(frame);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd22;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -36,10 +35,10 @@ public class DeviceGetServerTimeHandler extends AbstractEBikeHandler {
|
||||
@Override
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd22 message = (EBikeMessageCmd22) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
log.info("设备 获取服务器时间:{}", JSON.toJSONString(message));
|
||||
EBikeMessageCmd22 eBikeMessageCmd22 = new EBikeMessageCmd22(dataProtocol.getBytes());
|
||||
log.info("设备 获取服务器时间:{}", JSON.toJSONString(eBikeMessageCmd22));
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
saveLastTimeAndCheckChannel(eBikeMessageCmd22.getPhysicalId() + "", ctx);
|
||||
|
||||
// 获取当前服务器10位时间戳
|
||||
byte[] timeBytes = BytesUtil.getIntBytes((int) (System.currentTimeMillis() / 1000));
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||
import com.jsowell.common.enums.ebike.PortStatusEnum;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd21;
|
||||
import com.jsowell.pile.service.PileBasicInfoService;
|
||||
@@ -47,15 +46,12 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
@Override
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd21 message = (EBikeMessageCmd21) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
EBikeMessageCmd21 eBikeMessageCmd21 = new EBikeMessageCmd21(dataProtocol.getBytes());
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
|
||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||
log.info("设备心跳包:{}", JSON.toJSONString(message));
|
||||
|
||||
updatePileStatus(message);
|
||||
|
||||
saveLastTimeAndCheckChannel(eBikeMessageCmd21.getPhysicalId() + "", ctx);
|
||||
log.info("设备心跳包:{}", JSON.toJSONString(eBikeMessageCmd21));
|
||||
// 更新充电桩状态
|
||||
updatePileStatus(eBikeMessageCmd21);
|
||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||
}
|
||||
|
||||
@@ -65,9 +61,8 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
*/
|
||||
private void updatePileStatus(EBikeMessageCmd21 message) {
|
||||
String pileSn = message.getPhysicalId() + "";
|
||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||
int portNumber = deviceHeartbeat.getPortNumber();
|
||||
List<String> portStatus = deviceHeartbeat.getPortStatus();
|
||||
int portNumber = message.getPortNumber();
|
||||
List<String> portStatus = message.getPortStatus();
|
||||
for (int i = 0; i < portNumber; i++) {
|
||||
// 组装pile_connector_info表数据
|
||||
String connectorCode = String.format("%1$02d", i + 1);
|
||||
@@ -77,5 +72,4 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
pileConnectorInfoService.updateConnectorStatus(pileConnectorCode, PortStatusEnum.eBikeStatusTransformDBStatus(eBikeStatus));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd12;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@@ -36,7 +35,7 @@ public class HostGetServerTimeHandler extends AbstractEBikeHandler {
|
||||
@Override
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd12 message = (EBikeMessageCmd12) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
EBikeMessageCmd12 message = new EBikeMessageCmd12(dataProtocol.getBytes());
|
||||
log.info("主机 获取服务器时间:{}", JSON.toJSONString(message));
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.jsowell.common.enums.ebike.PortStatusEnum;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd06;
|
||||
import com.jsowell.pile.service.PileBasicInfoService;
|
||||
@@ -47,19 +46,14 @@ public class PowerHeartbeatHandler extends AbstractEBikeHandler {
|
||||
@Override
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd06 message = (EBikeMessageCmd06) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
EBikeMessageCmd06 message = new EBikeMessageCmd06(dataProtocol.getBytes());
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
|
||||
EBikeMessageCmd06.PowerHeartbeat powerHeartbeat = message.getPowerHeartbeat();
|
||||
log.info("端口充电时功率心跳包:{}", JSON.toJSONString(message));
|
||||
|
||||
// 更新枪口状态
|
||||
updatePileStatus(message);
|
||||
|
||||
// 保存实时监控数据
|
||||
saveRealTimeMonitorData(message);
|
||||
|
||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||
}
|
||||
|
||||
@@ -68,16 +62,15 @@ public class PowerHeartbeatHandler extends AbstractEBikeHandler {
|
||||
* @param message
|
||||
*/
|
||||
private void saveRealTimeMonitorData(EBikeMessageCmd06 message) {
|
||||
EBikeMessageCmd06.PowerHeartbeat powerHeartbeat = message.getPowerHeartbeat();
|
||||
// 组装数据
|
||||
RealTimeMonitorData realTimeMonitorData = new RealTimeMonitorData();
|
||||
realTimeMonitorData.setPileSn(message.getPhysicalId() + "");
|
||||
realTimeMonitorData.setConnectorCode(powerHeartbeat.getPort());
|
||||
realTimeMonitorData.setConnectorCode(message.getPort());
|
||||
realTimeMonitorData.setPileConnectorCode(realTimeMonitorData.getPileSn() + realTimeMonitorData.getConnectorCode());
|
||||
realTimeMonitorData.setTransactionCode(powerHeartbeat.getOrderCode());
|
||||
realTimeMonitorData.setConnectorStatus(powerHeartbeat.getPortStatus());
|
||||
realTimeMonitorData.setOutputVoltage(powerHeartbeat.getVoltage());
|
||||
realTimeMonitorData.setOutputCurrent(powerHeartbeat.getCurrent());
|
||||
realTimeMonitorData.setTransactionCode(message.getOrderCode());
|
||||
realTimeMonitorData.setConnectorStatus(message.getPortStatus());
|
||||
realTimeMonitorData.setOutputVoltage(message.getVoltage());
|
||||
realTimeMonitorData.setOutputCurrent(message.getCurrent());
|
||||
// realTimeMonitorData.setOutputPower("");
|
||||
realTimeMonitorData.setDateTime(DateUtils.getDateTime());
|
||||
|
||||
@@ -90,9 +83,8 @@ public class PowerHeartbeatHandler extends AbstractEBikeHandler {
|
||||
*/
|
||||
private void updatePileStatus(EBikeMessageCmd06 message) {
|
||||
String pileSn = message.getPhysicalId() + "";
|
||||
EBikeMessageCmd06.PowerHeartbeat powerHeartbeat = message.getPowerHeartbeat();
|
||||
String connectorCode = powerHeartbeat.getPort();
|
||||
String portStatus = powerHeartbeat.getPortStatus();
|
||||
String connectorCode = message.getPort();
|
||||
String portStatus = message.getPortStatus();
|
||||
pileConnectorInfoService.updateConnectorStatus(pileSn + connectorCode, PortStatusEnum.eBikeStatusTransformDBStatus(portStatus));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd20;
|
||||
import com.jsowell.pile.service.PileBasicInfoService;
|
||||
@@ -41,10 +40,9 @@ public class RegistrationHandler extends AbstractEBikeHandler {
|
||||
@Override
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
EBikeMessageCmd20 message = new EBikeMessageCmd20(dataProtocol.getBytes());
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
|
||||
log.info("设备注册包:{}", JSON.toJSONString(message));
|
||||
pileBasicInfoService.registrationEBikePile(message);
|
||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.common.util.id.IdUtils;
|
||||
import com.jsowell.netty.factory.EBikeOperateFactory;
|
||||
import com.jsowell.pile.domain.OrderBasicInfo;
|
||||
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
|
||||
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
|
||||
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd03;
|
||||
import com.jsowell.pile.service.OrderBasicInfoService;
|
||||
@@ -58,13 +57,11 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
|
||||
@Override
|
||||
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
|
||||
// 解析字节数组
|
||||
EBikeMessageCmd03 message = (EBikeMessageCmd03) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
|
||||
EBikeMessageCmd03 message = new EBikeMessageCmd03(dataProtocol.getBytes());
|
||||
// 保存时间
|
||||
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
|
||||
EBikeMessageCmd03.SettlementInfo settlementInfo = message.getSettlementInfo();
|
||||
log.info("结算消费信息上传:{}", JSON.toJSONString(message));
|
||||
|
||||
String transactionCode = settlementInfo.getOrderNumber();
|
||||
String transactionCode = message.getOrderNumber();
|
||||
// 处理订单加锁/结算电单车订单
|
||||
String lockKey = "settle_order_" + transactionCode;
|
||||
String uuid = IdUtils.fastUUID();
|
||||
@@ -81,7 +78,6 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
|
||||
redisCache.unLock(lockKey);
|
||||
}
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||
}
|
||||
@@ -90,13 +86,12 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
|
||||
* 收到交易记录 处理订单
|
||||
*/
|
||||
private void processOrder(EBikeMessageCmd03 message) {
|
||||
EBikeMessageCmd03.SettlementInfo settlementInfo = message.getSettlementInfo();
|
||||
String transactionCode = settlementInfo.getOrderNumber();
|
||||
String transactionCode = message.getOrderNumber();
|
||||
// 根据交易流水号查询订单信息
|
||||
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
|
||||
if (orderBasicInfo != null) {
|
||||
// 平台存在订单
|
||||
int stopReason = settlementInfo.getStopReason();
|
||||
int stopReason = message.getStopReason();
|
||||
orderBasicInfo.setReason(EBikeChargingStopReasonEnum.getMsgByCode(stopReason));
|
||||
// 如果订单状态为 异常,则改为 待结算
|
||||
if (StringUtils.equals(OrderStatusEnum.ABNORMAL.getValue(), orderBasicInfo.getOrderStatus())) {
|
||||
|
||||
Reference in New Issue
Block a user