CRC
This commit is contained in:
parent
e2eb7b3003
commit
38f949df23
@ -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");
|
||||
|
||||
@ -34,22 +34,27 @@ public class RateModelRequestLogic implements ServiceLogic {
|
||||
Map<String, Object> 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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user