update 电单车协议

This commit is contained in:
Guoqs
2024-09-19 14:58:48 +08:00
parent 0ca737e195
commit 6f46dfff4a
3 changed files with 68 additions and 1 deletions

View File

@@ -0,0 +1,52 @@
package com.jsowell.common.enums.ebike;
public enum EBikeChargeCommandResponse {
SUCCESS(0, "执行成功(启动或停止充电)"),
NO_CHARGER_PLUGGED(1, "端口未插充电器(不执行)"),
SAME_PORT_STATE(2, "端口状态和充电命令相同(不执行)"),
PORT_FAULT(3, "端口故障(执行)"),
INVALID_PORT_NUMBER(4, "无此端口号(不执行)"),
// 响应FF充电命令不执行只针对双路双路设备的二维码只有一个且端口号为FF当2个口都插了充电器服务器下发充电端口为FF时设备检测到有2个口待充电不知道充哪个就会返回此应答
MULTIPLE_PENDING_PORTS(5, "有多个待充端口"),
POWER_EXCEEDED(6, "多路设备功率超标(不执行)");
private final int code;
private final String description;
EBikeChargeCommandResponse(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static EBikeChargeCommandResponse fromCode(int code) {
for (EBikeChargeCommandResponse response : values()) {
if (response.getCode() == code) {
return response;
}
}
throw new IllegalArgumentException("Invalid code: " + code);
}
public static String getDescriptionByCode(int code) {
try {
EBikeChargeCommandResponse response = fromCode(code);
return response.getDescription();
} catch (IllegalArgumentException e) {
return "未知应答码: " + code;
}
}
}

View File

@@ -64,7 +64,7 @@ public class ChargingOperationResponse extends AbsEBikeMessage2 {
public static void main(String[] args) {
String s = "444e591d00198bca07da0c8200132738810124091416463569289954500000007907";
String s = "444e591d00198bca07f106820013273881052409191439471814850828040000ad06";
byte[] messageBytes = BytesUtil.hexStringToByteArray(s);
ChargingOperationResponse response = new ChargingOperationResponse(messageBytes);
System.out.println(response);

View File

@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.ebike.EBikeChargeCommandResponse;
import com.jsowell.common.enums.ykc.ChargingFailedReasonEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
@@ -55,6 +56,9 @@ public class PileRemoteService {
@Autowired
private EBikeSendCommandService eBikeSendCommandService;
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Value("${remoteUpdate.server}")
private String serverAddress;
@@ -131,6 +135,17 @@ public class PileRemoteService {
try {
ChargingOperationResponse startChargingResponse = eBikeSendCommandService.sendStartChargingCommand(startChargingCommand);
log.info("StartChargingResponse:{}", JSON.toJSONString(startChargingResponse));
if (startChargingResponse != null) {
int result = startChargingResponse.getResult();
if (result == 0) {
// 启动成功
orderBasicInfoService.chargingPileStartedSuccessfully(transactionCode);
} else {
String failedReasonMsg = EBikeChargeCommandResponse.getDescriptionByCode(result);
// 启动失败 682204000001000000000041
orderBasicInfoService.chargingPileFailedToStart(transactionCode, failedReasonMsg);
}
}
} catch (Exception e) {
log.error("电单车远程启动充电error", e);
}