diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java index 893ef6b1..8fef4dc9 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java @@ -8,7 +8,6 @@ import com.xhpc.common.api.dto.ChargingStationDto; import com.xhpc.common.core.domain.R; import com.xhpc.common.core.utils.HttpUtils; import com.xhpc.common.data.down.StartChargingData; -import com.xhpc.common.data.redis.CacheRateModel; import com.xhpc.pp.logic.RateModelRequestLogic; import com.xhpc.pp.server.ChargingPileServer; import com.xhpc.pp.utils.security.CRCCalculator; @@ -105,15 +104,9 @@ public class ChargingController { Long stationRateModelId = cacheStation.getRateModelId(); Long pileRateModelId = (Long) cachePile.get("rateModelId"); if (!stationRateModelId.equals(pileRateModelId)) { - CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString())); - String rateModel = RateModelRequestLogic.translate(cacheRateModel); - String skey = pkey.concat(".seqhex"); - String rateModelMsg = "685E".concat(seqHex(skey)).concat("0058").concat(pileNo) - .concat(String.format("%04X", stationRateModelId)) - .concat(rateModel); - rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModelMsg.substring(4))); + String resultStr = RateModelRequestLogic.translate(pileNo, stationRateModelId, "0058"); String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/".concat(pileNo).concat("/rateModel")), - rateModelMsg); + resultStr); JSONObject responseJson = (JSONObject) JSON.parse(response); assert responseJson != null; int code = responseJson.getInteger("code"); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java index ee956d39..61f34224 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java @@ -34,22 +34,27 @@ public class RateModelRequestLogic implements ServiceLogic { Map cachePile = REDIS.getCacheMap("pile:".concat(pileNo)); Long stationId = (Long) cachePile.get("stationId"); ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(stationId.toString())); - Long rateModelId = cacheStation.getRateModelId(); - if (rateModelId == null) { + Long stationRateModelId = cacheStation.getRateModelId(); + if (stationRateModelId == null) { ObjectMapper mapper = new ObjectMapper(); ObjectNode json = mapper.createObjectNode(); json.put("error", "场站没有设置费率"); return new ServiceResult((byte[]) null, ServiceResult.FAIL, json); } - CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(rateModelId.toString())); + String resultStr = translate(pileNo, stationRateModelId, "000A"); + return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK); + } + + public static String translate(String pileNo, Long stationRateModelId, String svc) { + + CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString())); String rateModel = translate(cacheRateModel); String skey = "pile:".concat(pileNo).concat(".seqhex"); - String seq = seqHex(skey); - String resultStr = "685E".concat(seq).concat("000A").concat(pileNo) - .concat(String.format("%04X", rateModelId)) + String resultStr = "685E".concat(seqHex(skey)).concat(svc).concat(pileNo) + .concat(String.format("%04X", stationRateModelId)) .concat(rateModel); - resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr.substring(4))); - return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK); + resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr)); + return resultStr; } public static String translate(CacheRateModel cacheRateModel) {