mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
update 电单车协议
This commit is contained in:
@@ -3,16 +3,21 @@ package com.jsowell.netty.handler.electricbicycles;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.bean.SerializationUtil;
|
||||
import com.jsowell.common.enums.ebike.PortStatusEnum;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
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;
|
||||
import com.jsowell.pile.service.PileConnectorInfoService;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备心跳包
|
||||
*/
|
||||
@@ -21,6 +26,12 @@ import org.springframework.stereotype.Component;
|
||||
public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
private final String type = EBikeCommandEnum.HEARTBEAT_2.getCode();
|
||||
|
||||
@Autowired
|
||||
private PileBasicInfoService pileBasicInfoService;
|
||||
|
||||
@Autowired
|
||||
private PileConnectorInfoService pileConnectorInfoService;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
EBikeOperateFactory.register(type, this);
|
||||
@@ -42,6 +53,44 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
|
||||
|
||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||
log.info("设备心跳包:{}", JSON.toJSONString(message));
|
||||
|
||||
updatePileStatus(message);
|
||||
|
||||
return getResult(dataProtocol, Constants.zeroByteArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新充电桩状态
|
||||
* @param message
|
||||
*/
|
||||
private void updatePileStatus(EBikeMessageCmd21 message) {
|
||||
String pileSn = message.getPhysicalId() + "";
|
||||
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
|
||||
int portNumber = deviceHeartbeat.getPortNumber();
|
||||
List<String> portStatus = deviceHeartbeat.getPortStatus();
|
||||
for (int i = 0; i < portNumber; i++) {
|
||||
// 组装pile_connector_info表数据
|
||||
String connectorCode = String.format("%1$02d", i + 1);
|
||||
String pileConnectorCode = pileSn + connectorCode;
|
||||
// 电单车协议状态
|
||||
String eBikeStatus = portStatus.get(i);
|
||||
pileConnectorInfoService.updateConnectorStatus(pileConnectorCode, eBikeStatusTransformDBStatus(eBikeStatus));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 电单车协议状态转换为数据库状态
|
||||
* @param eBikeStatus
|
||||
* @return
|
||||
*/
|
||||
private String eBikeStatusTransformDBStatus(String eBikeStatus) {
|
||||
String dbStatus = Constants.ZERO; // 默认0-离网
|
||||
if (StringUtils.isNotBlank(eBikeStatus)) {
|
||||
PortStatusEnum enumByValue = PortStatusEnum.getEnumByValue(Integer.parseInt(eBikeStatus));
|
||||
if (enumByValue != null) {
|
||||
dbStatus = enumByValue.getDbStatus();
|
||||
}
|
||||
}
|
||||
return dbStatus;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user