update 电单车协议

This commit is contained in:
Guoqs
2024-09-03 10:15:10 +08:00
parent 50ce2c0e11
commit 18de552bbc

View File

@@ -176,24 +176,27 @@ public class YKCUtils {
public static Map<String, String> parsePileConnectorCode(String pileConnectorCode) { public static Map<String, String> parsePileConnectorCode(String pileConnectorCode) {
int length = pileConnectorCode.length(); int length = pileConnectorCode.length();
if (length > 10) { // 如果length不等于14, 16, 8, 10, 2, 判断为错误的长度
if (length != Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EV
&& length != Constants.PILE_SN_LENGTH_FOR_EV
&& length != Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE
&& length != Constants.PILE_SN_LENGTH_FOR_EBIKE
&& length != 2) {
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR.getValue(), "Invalid pile connector code length: " + length);
}
if (length == Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EV) {
// 汽车桩 // 汽车桩
if (length == Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EV) { return parsePileConnector(pileConnectorCode, Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EV, pileConnectorCode.length() - 2);
return parsePileConnector(pileConnectorCode, Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EV, pileConnectorCode.length() - 2); } else if (length == Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE) {
} else if (length == 14) { // 电单车
return ImmutableMap.of("pileSn", pileConnectorCode, "connectorCode", ""); return parsePileConnector(pileConnectorCode, Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE, pileConnectorCode.length() - 2);
} else { } else if (length == Constants.PILE_SN_LENGTH_FOR_EV || length == Constants.PILE_SN_LENGTH_FOR_EBIKE) {
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR.getValue(), "Invalid EV pile connector code length: " + length); // 充电桩编号
} return ImmutableMap.of("pileSn", pileConnectorCode, "connectorCode", "");
} else { } else {
// 电单车桩 // 枪口号
if (length == Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE) { return ImmutableMap.of("pileSn", "", "connectorCode", pileConnectorCode);
return parsePileConnector(pileConnectorCode, Constants.PILE_CONNECTOR_CODE_LENGTH_FOR_EBIKE, pileConnectorCode.length() - 2);
} else if (length == 8) {
return ImmutableMap.of("pileSn", pileConnectorCode, "connectorCode", "");
} else {
throw new BusinessException(ReturnCodeEnum.CODE_DATA_LENGTH_ERROR.getValue(), "Invalid e-bike pile connector code length: " + length);
}
} }
} }
@@ -219,7 +222,7 @@ public class YKCUtils {
public static void main(String[] args) { public static void main(String[] args) {
String pileConnectorCode = "8800000000000201"; String pileConnectorCode = "8800000000000201";
pileConnectorCode = "1327388103"; // 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);