diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java index ee9719d7..ea88cf00 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import java.util.Map; +import static cn.hutool.core.util.NumberUtil.isInteger; import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; import static com.xhpc.common.data.redis.StaticBeanUtil.seqHex; @@ -29,18 +30,33 @@ public class RateModelValidateLogic implements ServiceLogic { String pileNo = (String) req.get("pileNo"); String rateModelIdStr = (String) req.get("rateModelId"); Map cachePile = REDIS.getCacheMap("pile:".concat(pileNo)); + Integer gunNum = (Integer) cachePile.get("gunNum"); + boolean charging = false; + for (int gunN = 1; gunN <= gunNum; gunN++) { + String gunId = String.format("%02d", gunN); + String gunkey = "gun:".concat(pileNo.concat(gunId)); + Map cacheGun = REDIS.getCacheMap(gunkey); + Object status = cacheGun.get("status"); + if (isInteger(status.toString())) { + charging = true; + } + } String resultCode = ServiceResult.OK; String hexCode = ServiceResult.HEX_00; - ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(cachePile.get("stationId").toString())); - Long csRateModelId = cacheStation.getRateModelId(); - int rateModelId = Integer.parseInt(rateModelIdStr, 16); - if (csRateModelId.intValue() != rateModelId) { - hexCode = ServiceResult.HEX_01; - resultCode = ServiceResult.FAIL; + Long rateModelId = Long.valueOf(Integer.parseInt(rateModelIdStr, 16)); + Long csRateModelId = rateModelId; + if (!charging) { + ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(cachePile.get("stationId").toString())); + csRateModelId = cacheStation.getRateModelId(); + if (csRateModelId.intValue() != rateModelId) { + hexCode = ServiceResult.HEX_01; + resultCode = ServiceResult.FAIL; + } } String skey = "pile:".concat(pileNo).concat(".seqhex"); String seq = seqHex(skey); - String resultStr = "680E".concat(seq).concat("0006").concat(pileNo).concat(String.format("%04X", csRateModelId)).concat(hexCode); + String resultStr = + "680E".concat(seq).concat("0006").concat(pileNo).concat(String.format("%04X", csRateModelId)).concat(hexCode); resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr)); return new ServiceResult(HexUtils.toBytes(resultStr), resultCode); }