mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 电单车协议
This commit is contained in:
@@ -631,9 +631,15 @@ public class OrderService {
|
||||
vo.setOutputCurrent(data.getOutputCurrent());
|
||||
vo.setOutputVoltage(data.getOutputVoltage());
|
||||
vo.setSOC(data.getSOC());
|
||||
BigDecimal chargingAmount = new BigDecimal(monitorData.getChargingAmount()).setScale(4, RoundingMode.HALF_UP); // 充电金额
|
||||
BigDecimal chargingAmount = BigDecimal.ZERO;
|
||||
if (monitorData.getChargingAmount() != null) {
|
||||
chargingAmount = new BigDecimal(monitorData.getChargingAmount()).setScale(4, RoundingMode.HALF_UP); // 充电金额
|
||||
}
|
||||
vo.setChargingAmount(chargingAmount.toString());
|
||||
BigDecimal chargingDegree = new BigDecimal(monitorData.getChargingDegree()).setScale(4, RoundingMode.HALF_UP); // 充电度数
|
||||
BigDecimal chargingDegree = BigDecimal.ZERO;
|
||||
if (monitorData.getChargingDegree() != null) {
|
||||
chargingDegree = new BigDecimal(monitorData.getChargingDegree()).setScale(4, RoundingMode.HALF_UP); // 充电度数
|
||||
}
|
||||
vo.setChargingDegree(chargingDegree.toString());
|
||||
vo.setSumChargingTime(monitorData.getSumChargingTime());
|
||||
vo.setTimeRemaining(monitorData.getTimeRemaining());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.jsowell.common.enums.ebike;
|
||||
|
||||
public enum EBikeChargeCommandResponse {
|
||||
public enum EBikeChargeResponseEnum {
|
||||
SUCCESS(0, "执行成功(启动或停止充电)"),
|
||||
|
||||
NO_CHARGER_PLUGGED(1, "端口未插充电器(不执行)"),
|
||||
@@ -19,7 +19,7 @@ public enum EBikeChargeCommandResponse {
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
EBikeChargeCommandResponse(int code, String description) {
|
||||
EBikeChargeResponseEnum(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
@@ -32,8 +32,8 @@ public enum EBikeChargeCommandResponse {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static EBikeChargeCommandResponse fromCode(int code) {
|
||||
for (EBikeChargeCommandResponse response : values()) {
|
||||
public static EBikeChargeResponseEnum fromCode(int code) {
|
||||
for (EBikeChargeResponseEnum response : values()) {
|
||||
if (response.getCode() == code) {
|
||||
return response;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public enum EBikeChargeCommandResponse {
|
||||
|
||||
public static String getDescriptionByCode(int code) {
|
||||
try {
|
||||
EBikeChargeCommandResponse response = fromCode(code);
|
||||
EBikeChargeResponseEnum response = fromCode(code);
|
||||
return response.getDescription();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return "未知应答码: " + code;
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.jsowell.common.enums.ebike;
|
||||
|
||||
/**
|
||||
* 电单车停止原因枚举
|
||||
*/
|
||||
public enum EBikeStopReasonEnum {
|
||||
FULLY_CHARGED(0x01, "充满自停"),
|
||||
MAX_CHARGE_TIME_REACHED(0x02, "达到最大充电时间"),
|
||||
PRESET_TIME_REACHED(0x03, "达到预设时间"),
|
||||
PRESET_POWER_REACHED(0x04, "达到预设电量"),
|
||||
USER_REMOVED(0x05, "用户拔出"),
|
||||
OVERLOAD(0x06, "负载过大"),
|
||||
SERVER_CONTROL_STOPPED(0x07, "服务器控制停止"),
|
||||
DYNAMIC_OVERLOAD(0x08, "动态过载"),
|
||||
POWER_TOO_LOW(0x09, "功率过小"),
|
||||
ENVIRONMENTAL_TEMP_HIGH(0x0A, "环境温度过高 (仅适用于AP262、AP360)"),
|
||||
PORT_TEMP_HIGH(0x0B, "端口温度过高 (仅适用于AP262)"),
|
||||
OVERCURRENT(0x0C, "过流"),
|
||||
USER_REMOVED_1(0x0D, "用户拔出-1,可能是插座弹片卡住"),
|
||||
NO_POWER_STOPPED(0x0E, "无功率停止,可能是接触不良或保险丝烧断故障"),
|
||||
RELAY_BAD_FUSE_BROKEN(0x0F, "预检-继电器坏或保险丝断"),
|
||||
WATER_INTRUSION(0x10, "水浸断电"),
|
||||
FIRE_EXTINGUISHING_SETTLEMENT_LOCAL(0x11, "灭火结算(本端口)"),
|
||||
FIRE_EXTINGUISHING_SETTLEMENT_REMOTE(0x12, "灭火结算(非本端口)"),
|
||||
USER_PASSWORD_LOCKOUT(0x13, "用户密码开柜断电"),
|
||||
DOOR_NOT_CLOSED(0x14, "未关好柜门"),
|
||||
EXTERNAL_OPERATION_STOPPED(0x15, "外部操作停止"),
|
||||
CARD_SWIPE_STOPPED(0x16, "刷卡操作停止"),
|
||||
SERVER_FORCED_STOP(0x17, "服务器强制停止(主要用于充电柜强制开柜门)"),
|
||||
FIRE_SYSTEM_TRIGGERED(0x18, "消防系统触发停止"),
|
||||
MEMORY_ERROR(0x19, "存储器错误"),
|
||||
OVERVOLTAGE(0x1A, "过压"),
|
||||
UNDERVOLTAGE(0x1B, "欠压");
|
||||
|
||||
private final int code;
|
||||
private final String description;
|
||||
|
||||
EBikeStopReasonEnum(int code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static EBikeStopReasonEnum fromCode(int code) {
|
||||
for (EBikeStopReasonEnum reason : values()) {
|
||||
if (reason.getCode() == code) {
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid code: " + code);
|
||||
}
|
||||
|
||||
public static String getDescriptionByCode(int code) {
|
||||
try {
|
||||
EBikeStopReasonEnum reason = fromCode(code);
|
||||
return reason.getDescription();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return "未知停止原因: " + Integer.toHexString(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class ChargingOperationResponse extends AbsEBikeMessage2 {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = "444e591d00198bca07f106820013273881052409191439471814850828040000ad06";
|
||||
String s = "444e591d00198bca0727268200132738810524091914394718148508280400000306";
|
||||
byte[] messageBytes = BytesUtil.hexStringToByteArray(s);
|
||||
ChargingOperationResponse response = new ChargingOperationResponse(messageBytes);
|
||||
System.out.println(response);
|
||||
|
||||
@@ -7,19 +7,21 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class EBikeMessageCmd03 extends AbsEBikeMessage2 {
|
||||
private int chargingTime; // 充电时长, 单位:"秒"
|
||||
private int maxPower; // 最大功率, 单位:"0.1W"
|
||||
private int consumedEnergy; // 耗电量, 单位:"0.01度"
|
||||
private BigDecimal maxPower; // 最大功率, 桩给的数据单位:"0.1W", 代码已经转为瓦
|
||||
private BigDecimal consumedEnergy; // 耗电量, 桩给的数据单位:"0.01度", 代码已经转为度
|
||||
private String connectorCode; // 端口号
|
||||
private int startMode; // 在线/离线启动/验证码
|
||||
private int cardNumberOrVerificationCode; // 卡号/验证码
|
||||
private int stopReason; // 停止原因
|
||||
private String orderNumber; // 订单编号
|
||||
private int secondMaxPower; // 第二最大功率
|
||||
private BigDecimal secondMaxPower; // 第二最大功率
|
||||
// private String timestamp; // 时间戳 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
|
||||
// private String placeholderDuration; // 占位时长 充电柜专用,其他设备忽略此字段 表示充满后占用设备的时长,单位为分钟
|
||||
|
||||
@@ -32,11 +34,12 @@ public class EBikeMessageCmd03 extends AbsEBikeMessage2 {
|
||||
|
||||
startIndex += length;
|
||||
length = 2;
|
||||
this.maxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
|
||||
this.maxPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length))).multiply(new BigDecimal("0.1"));
|
||||
|
||||
startIndex += length;
|
||||
length = 2;
|
||||
this.consumedEnergy = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
|
||||
this.consumedEnergy = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
|
||||
.multiply(new BigDecimal("0.01"));
|
||||
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
@@ -60,7 +63,7 @@ public class EBikeMessageCmd03 extends AbsEBikeMessage2 {
|
||||
|
||||
startIndex += length;
|
||||
length = 2;
|
||||
this.secondMaxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
|
||||
this.secondMaxPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length))).multiply(new BigDecimal("0.1"));
|
||||
|
||||
// this.timestamp = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(messageBytes, 31, 35)) + "";
|
||||
// this.placeholderDuration = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(messageBytes, 35, 37)) + "";
|
||||
|
||||
@@ -5,7 +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.ebike.EBikeChargeResponseEnum;
|
||||
import com.jsowell.common.enums.ykc.ChargingFailedReasonEnum;
|
||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
@@ -141,7 +141,7 @@ public class PileRemoteService {
|
||||
// 启动成功
|
||||
orderBasicInfoService.chargingPileStartedSuccessfully(transactionCode);
|
||||
} else {
|
||||
String failedReasonMsg = EBikeChargeCommandResponse.getDescriptionByCode(result);
|
||||
String failedReasonMsg = EBikeChargeResponseEnum.getDescriptionByCode(result);
|
||||
// 启动失败 682204000001000000000041
|
||||
orderBasicInfoService.chargingPileFailedToStart(transactionCode, failedReasonMsg);
|
||||
}
|
||||
|
||||
@@ -3103,8 +3103,8 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
*/
|
||||
@Override
|
||||
public void payOrderSuccessCallback(PayOrderSuccessCallbackDTO dto) {
|
||||
logger.info("订单:{}支付成功 支付回调", dto.getOrderCode());
|
||||
OrderBasicInfo orderInfo = this.getOrderInfoByOrderCode(dto.getOrderCode());
|
||||
logger.info("订单:{}支付成功支付回调, OrderBasicInfo:{}", dto.getOrderCode(), JSON.toJSONString(orderInfo));
|
||||
BigDecimal payAmount = dto.getPayAmount();
|
||||
|
||||
// 是否发送启动指令
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jsowell.common.enums.DelFlagEnum;
|
||||
import com.jsowell.common.enums.MemberWalletEnum;
|
||||
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
|
||||
import com.jsowell.common.enums.adapay.MerchantDelayModeEnum;
|
||||
import com.jsowell.common.enums.ebike.EBikeStopReasonEnum;
|
||||
import com.jsowell.common.enums.ykc.*;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.AdapayUtil;
|
||||
@@ -473,7 +474,35 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
|
||||
|
||||
@Override
|
||||
public void settleOrderForEBike(EBikeMessageCmd03 message, OrderBasicInfo orderBasicInfo) {
|
||||
// 判断订单状态
|
||||
if (StringUtils.equals(orderBasicInfo.getOrderStatus(), OrderStatusEnum.ORDER_COMPLETE.getValue())) {
|
||||
logger.info("结算订单:{}, 是订单完成状态", orderBasicInfo.getOrderCode());
|
||||
return;
|
||||
}
|
||||
|
||||
// 订单状态
|
||||
orderBasicInfo.setOrderStatus(OrderStatusEnum.ORDER_COMPLETE.getValue());
|
||||
// 停止原因
|
||||
orderBasicInfo.setReason(EBikeStopReasonEnum.getDescriptionByCode(message.getStopReason()));
|
||||
|
||||
// 更新订单详情
|
||||
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderBasicInfo.getOrderCode());
|
||||
if (orderDetail != null) {
|
||||
orderDetail.setTotalUsedElectricity(message.getConsumedEnergy());
|
||||
orderDetail.setFlatUsedElectricity(message.getConsumedEnergy());
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
OrderTransactionDTO dto = new OrderTransactionDTO();
|
||||
dto.setOrderBasicInfo(orderBasicInfo);
|
||||
dto.setOrderDetail(orderDetail);
|
||||
transactionService.doUpdateOrder(dto);
|
||||
|
||||
// 充电时间大于30秒不退费
|
||||
int chargingTime = message.getChargingTime();
|
||||
if (chargingTime < 30) {
|
||||
// 退款
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user