mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-10 08:58:02 +08:00
update 电单车协议
This commit is contained in:
@@ -31,22 +31,22 @@ public class Constants {
|
|||||||
// 非法交易流水号 由充电桩启动的订单会传全是0的交易流水号
|
// 非法交易流水号 由充电桩启动的订单会传全是0的交易流水号
|
||||||
public static final String ILLEGAL_TRANSACTION_CODE = "00000000000000000000000000000000";
|
public static final String ILLEGAL_TRANSACTION_CODE = "00000000000000000000000000000000";
|
||||||
|
|
||||||
// 充电桩sn号长度
|
// 电动汽车充电桩sn号长度
|
||||||
public static final int PILE_SN_LENGTH_FOR_EV = 14;
|
public static final int PILE_SN_LENGTH_FOR_EV = 14;
|
||||||
|
|
||||||
// 充电桩枪口号长度
|
// 电动汽车充电桩枪口号长度
|
||||||
public static final int CONNECTOR_CODE_LENGTH_FOR_EV = 2;
|
public static final int CONNECTOR_CODE_LENGTH_FOR_EV = 2;
|
||||||
|
|
||||||
// 充电桩枪口编号长度
|
// 电动汽车充电桩枪口编号长度
|
||||||
public static final int PILE_CONNECTOR_CODE_LENGTH = PILE_SN_LENGTH_FOR_EV + CONNECTOR_CODE_LENGTH_FOR_EV;
|
public static final int PILE_CONNECTOR_CODE_LENGTH_FOR_EV = PILE_SN_LENGTH_FOR_EV + CONNECTOR_CODE_LENGTH_FOR_EV;
|
||||||
|
|
||||||
// 充电桩sn号长度
|
// 电单车充电桩sn号长度
|
||||||
public static final int PILE_SN_LENGTH_FOR_EBIKE = 14;
|
public static final int PILE_SN_LENGTH_FOR_EBIKE = 8;
|
||||||
|
|
||||||
// 充电桩枪口号长度
|
// 电单车充电桩枪口号长度
|
||||||
public static final int CONNECTOR_CODE_LENGTH_FOR_EBIKE = 2;
|
public static final int CONNECTOR_CODE_LENGTH_FOR_EBIKE = 2;
|
||||||
|
|
||||||
// 充电桩枪口编号长度
|
// 电单车充电桩枪口编号长度
|
||||||
public static final int PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE = PILE_SN_LENGTH_FOR_EBIKE + CONNECTOR_CODE_LENGTH_FOR_EBIKE;
|
public static final int PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE = PILE_SN_LENGTH_FOR_EBIKE + CONNECTOR_CODE_LENGTH_FOR_EBIKE;
|
||||||
|
|
||||||
// 汇付手续费费率
|
// 汇付手续费费率
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.jsowell.common.util;
|
package com.jsowell.common.util;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import com.jsowell.common.constant.Constants;
|
import com.jsowell.common.constant.Constants;
|
||||||
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
||||||
@@ -152,38 +152,49 @@ public class YKCUtils {
|
|||||||
return BytesUtil.ascii2Str(vinCodeByteArr);
|
return BytesUtil.ascii2Str(vinCodeByteArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析充电桩连接器编号
|
||||||
|
*
|
||||||
|
* @param pileConnectorCode 充电桩连接器编号
|
||||||
|
* @param totalLength 总长度
|
||||||
|
* @param connectorOffset 连接器编号的偏移量
|
||||||
|
* @return 包含桩编号和连接器编号的映射
|
||||||
|
*/
|
||||||
|
private static Map<String, String> parsePileConnector(String pileConnectorCode, int totalLength, int connectorOffset) {
|
||||||
|
String pileSn = StringUtils.substring(pileConnectorCode, 0, totalLength - 2);
|
||||||
|
String connectorCode = StringUtils.substring(pileConnectorCode, connectorOffset);
|
||||||
|
|
||||||
|
return ImmutableMap.of("pileSn", pileSn, "connectorCode", connectorCode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析充电桩编号
|
* 解析充电桩编号
|
||||||
|
*
|
||||||
|
* @param pileConnectorCode 充电桩连接器编号
|
||||||
|
* @return 包含桩编号和连接器编号的映射
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> parsePileConnectorCode(String pileConnectorCode) {
|
public static Map<String, String> parsePileConnectorCode(String pileConnectorCode) {
|
||||||
// 长度大于10是汽车桩, 否则是电单车桩
|
int length = pileConnectorCode.length();
|
||||||
String pileSn;
|
|
||||||
String connectorCode = "";
|
if (length > 10) {
|
||||||
if (pileConnectorCode.length() > 10) {
|
// 汽车桩
|
||||||
// 汽车桩, 桩编号14位, 枪口号2位
|
if (length == Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EV) {
|
||||||
if (pileConnectorCode.length() == 16) {
|
return parsePileConnector(pileConnectorCode, Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EV, pileConnectorCode.length() - 2);
|
||||||
pileSn = StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2);
|
} else if (length == 14) {
|
||||||
connectorCode = StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2);
|
return ImmutableMap.of("pileSn", pileConnectorCode, "connectorCode", "");
|
||||||
} else if (pileConnectorCode.length() == 14){
|
|
||||||
pileSn = pileConnectorCode;
|
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR);
|
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR.getValue(), "Invalid EV pile connector code length: " + length);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 电单车桩, 桩编号8位, 枪口号2位
|
// 电单车桩
|
||||||
if (pileConnectorCode.length() == 10) {
|
if (length == Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE) {
|
||||||
pileSn = StringUtils.substring(pileConnectorCode, 0, pileConnectorCode.length() - 2);
|
return parsePileConnector(pileConnectorCode, Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE, pileConnectorCode.length() - 2);
|
||||||
connectorCode = StringUtils.substring(pileConnectorCode, pileConnectorCode.length() - 2);
|
} else if (length == 8) {
|
||||||
} else if (pileConnectorCode.length() == 8){
|
return ImmutableMap.of("pileSn", pileConnectorCode, "connectorCode", "");
|
||||||
pileSn = pileConnectorCode;
|
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR);
|
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR.getValue(), "Invalid e-bike pile connector code length: " + length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, String> resultMap = Maps.newHashMap();
|
|
||||||
resultMap.put("pileSn", pileSn);
|
|
||||||
resultMap.put("connectorCode", connectorCode);
|
|
||||||
return resultMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,6 +219,7 @@ public class YKCUtils {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String pileConnectorCode = "8800000000000201";
|
String pileConnectorCode = "8800000000000201";
|
||||||
|
pileConnectorCode = "1327388103";
|
||||||
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
|
String pileSn = YKCUtils.getPileSn(pileConnectorCode);
|
||||||
System.out.println(pileSn);
|
System.out.println(pileSn);
|
||||||
String connectorCode = YKCUtils.getConnectorCode(pileConnectorCode);
|
String connectorCode = YKCUtils.getConnectorCode(pileConnectorCode);
|
||||||
|
|||||||
Reference in New Issue
Block a user