代码重构优化,移除不必要的方法

This commit is contained in:
ZZ 2021-08-09 16:49:44 +08:00
parent fae04fa29f
commit 119fd1b872
4 changed files with 10 additions and 15 deletions

View File

@ -28,7 +28,6 @@ import static com.xhpc.common.data.redis.SeqUtil.seqHex;
import static com.xhpc.pp.logic.RegisterLogic.REGISTERED;
import static com.xhpc.pp.server.ChargingPileServer.*;
import static com.xhpc.pp.utils.security.HexUtils.toHexInt;
import static com.xhpc.pp.utils.security.HexUtils.toHexIntX;
@RestController
public class ChargingController {
@ -74,7 +73,7 @@ public class ChargingController {
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString()));
String rateModel = RateModelRequestLogic.translate(cacheRateModel);
String rateModelMsg = "680E0000000A".concat(pileNo)
.concat(toHexIntX(Math.toIntExact(stationRateModelId)))
.concat(String.format("%04X", stationRateModelId))
.concat(rateModel)
.concat(ServiceResult.HEX_OK);
rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel));

View File

@ -43,7 +43,7 @@ public class RateModelRequestLogic implements ServiceLogic {
CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(rateModelId.toString()));
String rateModel = translate(cacheRateModel);
String resultStr = "680E0000000A".concat(pileNo)
.concat(HexUtils.toHexIntX(Math.toIntExact(rateModelId)))
.concat(String.format("%04X", rateModelId))
.concat(rateModel)
.concat(ServiceResult.HEX_OK);
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));

View File

@ -1,5 +1,6 @@
package com.xhpc.pp.logic;
import com.xhpc.common.api.dto.ChargingStationDto;
import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic;
@ -25,16 +26,18 @@ public class RateModelValidateLogic implements ServiceLogic {
Map<String, Object> req = sp.getParameters();
String pileNo = (String) req.get("pileNo");
String rateModelId = (String) req.get("rateModelId");
Map<String, Integer> cachePile = REDIS.getCacheMap(pileNo);
String rateModelIdStr = (String) req.get("rateModelId");
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(pileNo));
String resultCode = ServiceResult.OK;
String hexCode = ServiceResult.HEX_OK;
Integer rateModelIdCache = cachePile.get("rateModelId");
if (rateModelIdCache != Integer.parseInt(rateModelId, 16)) {
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_FAIL;
resultCode = ServiceResult.FAIL;
}
String resultStr = "680E00000006".concat(pileNo).concat(String.format("%04d", rateModelIdCache)).concat(hexCode);
String resultStr = "680E00000006".concat(pileNo).concat(String.format("%04X", csRateModelId)).concat(hexCode);
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
return new ServiceResult(HexUtils.toBytes(resultStr), resultCode);
}

View File

@ -16,11 +16,6 @@ public class HexUtils {
return toHex(toIntBytes(String.format("%08d", dec), 8));
}
public static String toHexIntX(Integer dec) {
return toHex(Objects.requireNonNull(toBytes(String.format("%04X", dec))));
}
public static int reverseHexInt(String hex) {
byte[] data = toBytes(reverseHex(hex));
@ -185,8 +180,6 @@ public class HexUtils {
public static void main(String[] args) {
System.out.println(toHexIntX(0xffff));
System.out.println(toHexIntX(65535));
System.out.println(Integer.parseInt("FFFF", 16));
byte[] data1 = toBytes(reverseHex("FC080000"));
System.out.println(toInteger(data1, 0, 4));