diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java index 887e667c0..ad4a0574f 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java @@ -83,7 +83,7 @@ public class TempController extends BaseController { public RestApiResponse tempStartCharging(@RequestBody QueryOrderDTO dto) { RestApiResponse response = null; try { - eBikeSendCommandService.startCharging(dto.getPileSn()); + eBikeSendCommandService.startCharging(dto.getPileSn(), dto.getConnectorCode()); } catch (Exception e) { logger.error("电单车开始充电 error", e); response = new RestApiResponse<>(ReturnCodeEnum.CODE_FAILED); diff --git a/jsowell-common/src/main/java/com/jsowell/common/YouDianUtils.java b/jsowell-common/src/main/java/com/jsowell/common/YouDianUtils.java index 691409d04..8340eb4fc 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/YouDianUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/YouDianUtils.java @@ -1,6 +1,7 @@ package com.jsowell.common; import com.jsowell.common.util.BytesUtil; +import com.jsowell.common.util.YKCUtils; import lombok.extern.slf4j.Slf4j; import java.util.Arrays; @@ -87,4 +88,49 @@ public class YouDianUtils { int calculatedChecksum = calculateCheckField(bytes); return BytesUtil.intToBytesLittle(calculatedChecksum); } + + // public static String convertPortNumberToHex(int portNumber) { + // if (portNumber < 1 || portNumber > 16) { + // throw new IllegalArgumentException("Port number must be between 1 and 16."); + // } + // + // // 端口号从1开始,因此需要减去1 + // int hexValue = portNumber - 1; + // + // // 转换为16进制字符串,并确保长度为2位 + // String hexString = String.format("0x%02X", hexValue); + // + // return hexString; + // } + + public static byte[] convertPortNumberToBytes(int portNumber) { + if (portNumber < 1 || portNumber > 16) { + throw new IllegalArgumentException("Port number must be between 1 and 16."); + } + + // 端口号从1开始,因此需要减去1 + int hexValue = portNumber - 1; + + // 转换为字节数组 + byte[] bytes = new byte[2]; + bytes[0] = (byte) 0x00; // 前缀0x + bytes[1] = (byte) hexValue; + + return bytes; + } + + public static void main(String[] args) { + byte[] result1 = convertPortNumberToBytes(1); // 输出: [0, 0] + byte[] result2 = convertPortNumberToBytes(2); // 输出: [0, 1] + byte[] result10 = convertPortNumberToBytes(10); // 输出: [0, 9] + byte[] result11 = convertPortNumberToBytes(11); // 输出: [0, 10] + byte[] result16 = convertPortNumberToBytes(16); // 输出: [0, 15] + + // 打印结果 + System.out.println(YKCUtils.frameType2Str(result1)); + System.out.println(YKCUtils.frameType2Str(result2)); + System.out.println(YKCUtils.frameType2Str(result10)); + System.out.println(YKCUtils.frameType2Str(result11)); + System.out.println(YKCUtils.frameType2Str(result16)); + } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/EBikeSendCommandService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/EBikeSendCommandService.java index 631c5a40c..6f2a81956 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/EBikeSendCommandService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/EBikeSendCommandService.java @@ -6,5 +6,5 @@ package com.jsowell.pile.service; public interface EBikeSendCommandService { // void send(String pileSn, AbsEBikeMessage msg); - void startCharging(String pileSn); + void startCharging(String pileSn, String connectorCode); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java index f36577cc3..130aa22fc 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java @@ -3,6 +3,7 @@ package com.jsowell.pile.service.impl; import com.jsowell.common.enums.ykc.PileChannelEntity; import com.jsowell.common.util.BytesUtil; import com.jsowell.common.util.RandomUtil; +import com.jsowell.common.util.id.IdUtils; import com.jsowell.pile.domain.ebike.AbsEBikeMessage; import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82; import com.jsowell.pile.service.EBikeSendCommandService; @@ -15,20 +16,31 @@ import java.util.Objects; @Slf4j @Service public class EBikeSendCommandServiceImpl implements EBikeSendCommandService { + @Override - public void startCharging(String pileSn) { + public void startCharging(String pileSn, String connectorCode) { EBikeMessageCmd82 message = new EBikeMessageCmd82(); message.setHeader("DNY"); message.setPhysicalId(Integer.parseInt(pileSn)); message.setMessageId(RandomUtil.getRandomNumber(4)); message.setCommand("82"); + EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData(); + // 充电模式 data.setRateMode("3"); + // 余额或有效期 data.setBalanceOrValidity("0"); + // 端口号 data.setPortNumber("0"); + // 充电命令 data.setChargeCommand("1"); + // 充电时长/功率 data.setChargeDurationOrPower("0"); - data.setOrderNumber("0"); + + // 订单编号 + String orderNumber = IdUtils.generateTransactionCode(pileSn, connectorCode); + data.setOrderNumber(orderNumber); + data.setMaxChargeDuration("0"); data.setOverloadPower("0"); data.setQrCodeLight("0"); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java index 2d027c2ad..5ba9a9f6e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileStationInfoServiceImpl.java @@ -193,7 +193,7 @@ public class PileStationInfoServiceImpl implements PileStationInfoService { CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(Double.parseDouble(pileStationInfo.getStationLng()), Double.parseDouble(pileStationInfo.getStationLat())); vo.setStationLat(String.format("%.6f", coordinate.getLat())); vo.setStationLng(String.format("%.6f", coordinate.getLng())); - log.info("高德坐标:{}, 转天地图坐标:{}", pileStationInfo.getStationLng() + ", " + pileStationInfo.getStationLat(), vo.getStationLng() + ", " + vo.getStationLat()); + log.debug("高德坐标:{}, 转天地图坐标:{}", pileStationInfo.getStationLng() + ", " + pileStationInfo.getStationLat(), vo.getStationLng() + ", " + vo.getStationLat()); } vo.setCountryCode(pileStationInfo.getCountryCode());