weired 00/01

This commit is contained in:
ZZ 2021-08-18 18:00:14 +08:00
parent dc73eb1ff8
commit 335971ce51
11 changed files with 22 additions and 24 deletions

View File

@ -11,7 +11,6 @@ import com.xhpc.common.data.down.StartChargingData;
import com.xhpc.common.data.redis.CacheRateModel; import com.xhpc.common.data.redis.CacheRateModel;
import com.xhpc.pp.logic.RateModelRequestLogic; import com.xhpc.pp.logic.RateModelRequestLogic;
import com.xhpc.pp.server.ChargingPileServer; import com.xhpc.pp.server.ChargingPileServer;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.utils.security.CRCCalculator; import com.xhpc.pp.utils.security.CRCCalculator;
import com.xhpc.pp.utils.security.HexUtils; import com.xhpc.pp.utils.security.HexUtils;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -105,10 +104,9 @@ public class ChargingController {
String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId()); String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId());
String skey = gunkey.concat(".seqhex"); String skey = gunkey.concat(".seqhex");
String seq = seqHex(skey); String seq = seqHex(skey);
String rateModelMsg = "680E".concat(seq).concat("000A").concat(pileNo) String rateModelMsg = "680E".concat(seq).concat("0058").concat(pileNo)
.concat(String.format("%04X", stationRateModelId)) .concat(String.format("%04X", stationRateModelId))
.concat(rateModel) .concat(rateModel);
.concat(ServiceResult.HEX_OK);
rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel)); rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel));
String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/".concat(pileNo).concat("/rateModel")), rateModelMsg); String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/".concat(pileNo).concat("/rateModel")), rateModelMsg);
JSONObject responseJson = (JSONObject) JSON.parse(response); JSONObject responseJson = (JSONObject) JSON.parse(response);
@ -286,7 +284,7 @@ public class ChargingController {
} else { } else {
// not defined or implemented yet // not defined or implemented yet
} }
String msg = HexUtils.toHex(data).concat(ServiceResult.HEX_OK); String msg = HexUtils.toHex(data);
msg = msg.concat(CRCCalculator.calcCrc(msg)); msg = msg.concat(CRCCalculator.calcCrc(msg));
log.info("start charging order[{}], send msg >>>> |{}|", startChargingData.getOrderNo(), msg); log.info("start charging order[{}], send msg >>>> |{}|", startChargingData.getOrderNo(), msg);
return HexUtils.toBytes(msg); return HexUtils.toBytes(msg);

View File

@ -68,7 +68,7 @@ public class PileController {
if (handler != null) { if (handler != null) {
try { try {
handler.sendClientBinary(HexUtils.toBytes(msg)); handler.sendClientBinary(HexUtils.toBytes(msg));
r = R.fail("费率模型已下发"); r = R.ok("费率模型已下发");
} catch (IOException e) { } catch (IOException e) {
r = R.fail("费率模型下发失败:".concat(e.getMessage())); r = R.fail("费率模型下发失败:".concat(e.getMessage()));
} }

View File

@ -37,7 +37,7 @@ public class HBLogic implements ServiceLogic {
REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(gunkey, cacheGun);
String skey = gunkey.concat(".seqhex"); String skey = gunkey.concat(".seqhex");
String seq = seqHex(skey); String seq = seqHex(skey);
String resultStr = "680D".concat(seq).concat("0004").concat(pileNo).concat(gunId).concat(ServiceResult.HEX_OK); String resultStr = "680D".concat(seq).concat("0004").concat(pileNo).concat(gunId).concat(ServiceResult.HEX_00);
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr)); resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK); return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
} }

View File

@ -50,7 +50,7 @@ public class OrderDataLogic implements ServiceLogic {
REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(gunkey, cacheGun);
String skey = gunkey.concat(".seqhex"); String skey = gunkey.concat(".seqhex");
String seq = seqHex(skey); String seq = seqHex(skey);
String resultStr = "6815".concat(seq).concat("0040").concat(orderNo).concat(ServiceResult.HEX_OK); String resultStr = "6815".concat(seq).concat("0040").concat(orderNo).concat(ServiceResult.HEX_00);
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr)); resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK, orderNo); return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK, orderNo);
} }

View File

@ -14,7 +14,7 @@ import org.springframework.stereotype.Component;
import java.util.Map; import java.util.Map;
import static com.xhpc.pp.server.ChargingPileServer.REDIS; import static com.xhpc.pp.server.ChargingPileServer.REDIS;
import static com.xhpc.pp.tx.ServiceResult.HEX_OK; import static com.xhpc.pp.tx.ServiceResult.*;
@Lazy @Lazy
@Component("RateModelConfigReplyDataLogic") @Component("RateModelConfigReplyDataLogic")
@ -29,13 +29,14 @@ public class RateModelConfigReplyDataLogic implements ServiceLogic {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
PileConfigReplyData pileRateModelConfigReplyData = objectMapper.convertValue(req, PileConfigReplyData.class); PileConfigReplyData pileRateModelConfigReplyData = objectMapper.convertValue(req, PileConfigReplyData.class);
String configResult = pileRateModelConfigReplyData.getConfigResult(); String configResult = pileRateModelConfigReplyData.getConfigResult();
if (configResult.equals(HEX_OK)) { if (HEX_01.equals(configResult)) {
// 确定设置成功的rateModelId 可能涉及协议修改 // 确定设置成功的rateModelId 可能涉及协议修改
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileRateModelConfigReplyData.getPileNo())); Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileRateModelConfigReplyData.getPileNo()));
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(cachePile.get("stationId").toString())); ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(cachePile.get("stationId").toString()));
cachePile.put("rateModelId", cacheStation.getRateModelId()); cachePile.put("rateModelId", cacheStation.getRateModelId());
return new ServiceResult(OK);
} }
return new ServiceResult(configResult); return new ServiceResult(FAIL);
} }
} }

View File

@ -47,8 +47,7 @@ public class RateModelRequestLogic implements ServiceLogic {
String seq = seqHex(skey); String seq = seqHex(skey);
String resultStr = "680E".concat(seq).concat("000A").concat(pileNo) String resultStr = "680E".concat(seq).concat("000A").concat(pileNo)
.concat(String.format("%04X", rateModelId)) .concat(String.format("%04X", rateModelId))
.concat(rateModel) .concat(rateModel);
.concat(ServiceResult.HEX_OK);
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr)); resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK); return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
} }

View File

@ -30,12 +30,12 @@ public class RateModelValidateLogic implements ServiceLogic {
String rateModelIdStr = (String) req.get("rateModelId"); String rateModelIdStr = (String) req.get("rateModelId");
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo)); Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo));
String resultCode = ServiceResult.OK; String resultCode = ServiceResult.OK;
String hexCode = ServiceResult.HEX_OK; String hexCode = ServiceResult.HEX_00;
ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(cachePile.get("stationId").toString())); ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(cachePile.get("stationId").toString()));
Long csRateModelId = cacheStation.getRateModelId(); Long csRateModelId = cacheStation.getRateModelId();
int rateModelId = Integer.parseInt(rateModelIdStr, 16); int rateModelId = Integer.parseInt(rateModelIdStr, 16);
if (csRateModelId.intValue() != rateModelId) { if (csRateModelId.intValue() != rateModelId) {
hexCode = ServiceResult.HEX_FAIL; hexCode = ServiceResult.HEX_01;
resultCode = ServiceResult.FAIL; resultCode = ServiceResult.FAIL;
} }
String skey = "pile:".concat(pileNo).concat(".seqhex"); String skey = "pile:".concat(pileNo).concat(".seqhex");

View File

@ -31,16 +31,16 @@ public class RegisterLogic implements ServiceLogic {
Map<String, Object> req = sp.getParameters(); Map<String, Object> req = sp.getParameters();
String resultCode = ServiceResult.OK; String resultCode = ServiceResult.OK;
String hexCode = ServiceResult.HEX_OK; String hexCode = ServiceResult.HEX_00;
String pileNo = (String) req.get("pileNo"); String pileNo = (String) req.get("pileNo");
Set<String> whitelist = REDIS.getCacheSet("PILE_WHITELIST"); Set<String> whitelist = REDIS.getCacheSet("PILE_WHITELIST");
if (!whitelist.contains(pileNo)) { if (!whitelist.contains(pileNo)) {
log.info("pile not in whitelist ({}) ", pileNo); log.info("pile not in whitelist ({}) ", pileNo);
hexCode = ServiceResult.HEX_FAIL; hexCode = ServiceResult.HEX_01;
resultCode = ServiceResult.FAIL; resultCode = ServiceResult.FAIL;
} else if (!EarlierBeanConf.ifreg(pileNo)) { } else if (!EarlierBeanConf.ifreg(pileNo)) {
log.info("pile already registered ({}) ", pileNo); log.info("pile already registered ({}) ", pileNo);
hexCode = ServiceResult.HEX_FAIL; hexCode = ServiceResult.HEX_01;
resultCode = ServiceResult.FAIL; resultCode = ServiceResult.FAIL;
} else { } else {
String pkey = "pile:".concat(pileNo); String pkey = "pile:".concat(pileNo);

View File

@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
import java.util.Map; import java.util.Map;
import static com.xhpc.pp.server.ChargingPileServer.REDIS; import static com.xhpc.pp.server.ChargingPileServer.REDIS;
import static com.xhpc.pp.tx.ServiceResult.HEX_OK; import static com.xhpc.pp.tx.ServiceResult.HEX_01;
@Lazy @Lazy
@Component("RemoteStartReplyDataLogic") @Component("RemoteStartReplyDataLogic")
@ -42,7 +42,7 @@ public class RemoteStartReplyDataLogic implements ServiceLogic {
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey); Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(gunkey, cacheGun);
REDIS.setCacheMap(orderkey, cacheOrder); REDIS.setCacheMap(orderkey, cacheOrder);
if (HEX_OK.equals(remoteStartReplyData.getStartResult())) { if (HEX_01.equals(remoteStartReplyData.getStartResult())) {
pileOrderService.pileStartup(orderNo, 1, "启动充电成功"); pileOrderService.pileStartup(orderNo, 1, "启动充电成功");
} else { } else {
cacheGun.put("orderkey", null); cacheGun.put("orderkey", null);

View File

@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
import java.util.Map; import java.util.Map;
import static com.xhpc.pp.server.ChargingPileServer.REDIS; import static com.xhpc.pp.server.ChargingPileServer.REDIS;
import static com.xhpc.pp.tx.ServiceResult.HEX_OK; import static com.xhpc.pp.tx.ServiceResult.HEX_01;
@Lazy @Lazy
@Component("RemoteStopReplyDataLogic") @Component("RemoteStopReplyDataLogic")
@ -41,7 +41,7 @@ public class RemoteStopReplyDataLogic implements ServiceLogic {
cacheOrder.put("stopResult", stopResult); cacheOrder.put("stopResult", stopResult);
REDIS.setCacheMap(orderkey, cacheOrder); REDIS.setCacheMap(orderkey, cacheOrder);
String orderNo = orderkey.replace("order:", ""); String orderNo = orderkey.replace("order:", "");
if (HEX_OK.equals(remoteStopReplyData.getStopResult())) { if (HEX_01.equals(remoteStopReplyData.getStopResult())) {
pileOrderService.pileStop(orderNo, 1, "停止充电成功"); pileOrderService.pileStop(orderNo, 1, "停止充电成功");
} else { } else {
pileOrderService.pileStartup(orderNo, 2, frs[Integer.parseInt(remoteStopReplyData.getFailReason())]); pileOrderService.pileStartup(orderNo, 2, frs[Integer.parseInt(remoteStopReplyData.getFailReason())]);

View File

@ -7,8 +7,8 @@ public class ServiceResult {
public static final String OK = "0"; public static final String OK = "0";
public static final String FAIL = "1"; public static final String FAIL = "1";
public static final String HEX_OK = "00"; public static final String HEX_00 = "00";
public static final String HEX_FAIL = "01"; public static final String HEX_01 = "01";
private String code; private String code;
private byte[] binary; private byte[] binary;