diff --git a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java index 9370d644..6513de3d 100644 --- a/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java +++ b/xhpc-modules/xhpc-common/src/main/java/com/xhpc/pp/utils/HexUtils.java @@ -16,7 +16,7 @@ public class HexUtils { return toHex(toIntBytes(String.format("%08d", dec), 8)); } - public static int reverseHexInt(String hex) { + public static Integer reverseHexInt(String hex) { byte[] data = toBytes(reverseHex(hex)); return toInteger(data, 0, data.length); @@ -64,7 +64,7 @@ public class HexUtils { return toString(ArrayUtils.subarray(data, start, end)); } - public static int toInteger(byte[] data, int start, int end) { + public static Integer toInteger(byte[] data, int start, int end) { if (data == null || data.length < end) return 0; diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java index 8cc34dd8..3ee18734 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/service/impl/XhpcChargeOrderServiceImpl.java @@ -634,14 +634,16 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar } @Override - public R cardStartup(Long userId, String serialNumber, Integer userType,String tenantId, Integer type, String grantOperator,String rateModelId) { - try{ - R user = userTypeService.getUser(null, userId, userType, null,tenantId); - if(user ==null || user.getData() ==null){ + public R cardStartup(Long userId, String serialNumber, Integer userType, String tenantId, Integer type, + String grantOperator, String rateModelId) { + + try { + R user = userTypeService.getUser(null, userId, userType, null, tenantId); + if (user == null || user.getData() == null) { return R.fail(Constants.INVALID_USER); } - Map userMessage = (Map)user.getData(); + Map userMessage = (Map) user.getData(); //桩号是否有效 String pattern = "^([0-9]{16})"; Pattern compile = Pattern.compile(pattern); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/PileStartChargingDataLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/PileStartChargingDataLogic.java index 7212e43b..48764509 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/PileStartChargingDataLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/PileStartChargingDataLogic.java @@ -14,6 +14,7 @@ import com.xhpc.pp.tx.ServiceParameter; import com.xhpc.pp.tx.ServiceResult; import com.xhpc.pp.tx.logic.ServiceLogic; import com.xhpc.pp.utils.HexUtils; +import com.xhpc.pp.utils.security.CRCCalculator; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,8 +25,6 @@ import javax.annotation.Resource; import java.util.List; import java.util.Map; -import static com.xhpc.common.data.redis.StaticBeanUtil.genOrder; - @Lazy @Component("PileStartChargingDataLogic") public class PileStartChargingDataLogic implements ServiceLogic { @@ -64,12 +63,13 @@ public class PileStartChargingDataLogic implements ServiceLogic { if (iccardInfo.getCardtype() == 0) { resultStr = "06"; } else { - // 调用订单接口 todo - orderNo = genOrder(connectorId); + // 调用订单接口 cardNo = iccardInfo.getCardno(); - R r = cardService.cardStartup(cardNo, orderNo, pileStartChargingData.getRateModelId().toString()); + R r = cardService.cardStartup(cardNo, connectorId, + HexUtils.reverseHexInt(pileStartChargingData.getRateModelId().toString()).toString()); //todo 费率处理 if (r.getCode() == 200) { result = ServiceResult.HEX_01; + orderNo = (String) ((Map) r.getData()).get("serialNumber"); } cardNo = StringUtils.leftPad(iccardInfo.getCardno(), 16, "0"); resultStr = r.getMsg(); @@ -78,7 +78,8 @@ public class PileStartChargingDataLogic implements ServiceLogic { resultStr = "01"; } } - String hex = orderNo.concat(connectorId).concat(cardNo).concat(balance).concat(resultStr).concat(result); //todo + String hex = orderNo.concat(connectorId).concat(cardNo).concat(balance).concat(result).concat(resultStr); + hex = hex.concat(CRCCalculator.calcCrc(hex)); String remark = "充电桩发起充电"; XhpcDeviceMessage deviceMessage = new XhpcDeviceMessage(); deviceMessage.setType(StationDeviceEnum.PILE.getCode());