协议实现更新,兼容1.0、2.0

This commit is contained in:
zz 2022-03-03 12:07:37 +08:00
parent 472db29426
commit 7cd29efcc9
8 changed files with 20 additions and 10 deletions

View File

@ -59,7 +59,7 @@ public class OrderDataLogic implements ServiceLogic {
REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(gunkey, cacheGun);
Long rdtime = (Long) cacheOrder.get("rdtime"); Long rdtime = (Long) cacheOrder.get("rdtime");
Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(orderData.getPileNo())); Map<String, Object> cachePile = REDIS.getCacheMap("pile:".concat(orderData.getPileNo()));
if (cachePile.get("version").equals("0B")) { if (cachePile.get("version").equals("0C")) {
final String hex = orderData.getHex(); final String hex = orderData.getHex();
String cdhex = hex.substring(0xA2 * 2 + 4, hex.length() - 4); String cdhex = hex.substring(0xA2 * 2 + 4, hex.length() - 4);
if (cdhex.length() > 0) { if (cdhex.length() > 0) {

View File

@ -66,7 +66,7 @@ public class RateModelRequestLogic implements ServiceLogic {
String rateModel = translate(cacheRateModel); String rateModel = translate(cacheRateModel);
String skey = "pile:".concat(pileNo).concat(".seqhex"); String skey = "pile:".concat(pileNo).concat(".seqhex");
String resultStr; String resultStr;
if ("0A".equals(version)) if (!"0C".equals(version))
resultStr = "685E".concat(seqHex(skey)).concat(svc).concat(pileNo).concat(String.format("%04X", resultStr = "685E".concat(seqHex(skey)).concat(svc).concat(pileNo).concat(String.format("%04X",
stationRateModelId)).concat(rateModel); stationRateModelId)).concat(rateModel);
else else

View File

@ -52,7 +52,7 @@ public class RateModelValidateLogic implements ServiceLogic {
String hexCode = ServiceResult.HEX_00; String hexCode = ServiceResult.HEX_00;
Long rateModelId; Long rateModelId;
String version = (String) cachePile.get("version"); String version = (String) cachePile.get("version");
if ("0A".equals(version)) rateModelId = Long.valueOf(Integer.parseInt(rateModelIdStr, 16)); if ("0C".equals(version)) rateModelId = Long.valueOf(HexUtils.reverseHexInt(rateModelIdStr));
else rateModelId = Long.valueOf(rateModelIdStr); else rateModelId = Long.valueOf(rateModelIdStr);
Long csRateModelId = rateModelId; Long csRateModelId = rateModelId;
if (!charging) { if (!charging) {

View File

@ -133,7 +133,7 @@ public class RealtimeDataLogic implements ServiceLogic {
Integer cacheStartSoc = (Integer) cacheOrder.get("startSoc"); Integer cacheStartSoc = (Integer) cacheOrder.get("startSoc");
if (cacheStartSoc == null && socInt != 0) cacheOrder.put("startSoc", socInt); if (cacheStartSoc == null && socInt != 0) cacheOrder.put("startSoc", socInt);
if (socInt != 0) cacheOrder.put("endSoc", socInt); if (socInt != 0) cacheOrder.put("endSoc", socInt);
if (cachePile.get("version").equals("0B")) { if (cachePile.get("version").equals("0C")) {
final String hex = realtimeData.getHex(); final String hex = realtimeData.getHex();
String cdhex = hex.substring(0x40 * 2 + 4, hex.length() - 4); String cdhex = hex.substring(0x40 * 2 + 4, hex.length() - 4);
if (cdhex.length() > 0) { if (cdhex.length() > 0) {

View File

@ -119,7 +119,8 @@ public class ChargingPileServer {
cachePile.put("status", DISCONNECTED); cachePile.put("status", DISCONNECTED);
REDIS.setCacheMap(pkey, cachePile); REDIS.setCacheMap(pkey, cachePile);
putemDisconn(pileNo, cachePile); putemDisconn(pileNo, cachePile);
log.debug("remove handler [{}] for ({})", handler.getName(), pileNo); log.debug("remove handler [{}] for ({}), now try to close conn..", handler.getName(), pileNo);
handler.closeConnection();
pileMap.remove(handler.getName()); pileMap.remove(handler.getName());
versionMapper.remove(handler.getName()); versionMapper.remove(handler.getName());
} }

View File

@ -30,9 +30,9 @@ public class RateModelTask {
if (rateModelIdStation != null) { if (rateModelIdStation != null) {
Set<String> pks = stationDto.getPiles(); Set<String> pks = stationDto.getPiles();
if (pks != null) for (String pileNo : pks) { if (pks != null) for (String pileNo : pks) {
Long rateModelIdPile = REDIS.getCacheMapValue(pileNo, "rateModelId"); String pk = "pile:".concat(pileNo);
Long rateModelIdPile = REDIS.getCacheMapValue(pk, "rateModelId");
if (!rateModelIdStation.equals(rateModelIdPile)) { if (!rateModelIdStation.equals(rateModelIdPile)) {
String pk = "pile:".concat(pileNo);
String gkPattern = ("gun:").concat(pk).concat("*"); String gkPattern = ("gun:").concat(pk).concat("*");
Collection<String> gks = REDIS.keys(gkPattern); Collection<String> gks = REDIS.keys(gkPattern);
boolean charging = false; boolean charging = false;

View File

@ -2,6 +2,7 @@ package com.xhpc.pp.utils.security;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.xhpc.pp.utils.HexUtils; import com.xhpc.pp.utils.HexUtils;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -13,6 +14,7 @@ import static com.xhpc.common.core.utils.StringUtils.capitalize;
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
import static com.xhpc.pp.utils.security.CP56Time2a.cp56toDate; import static com.xhpc.pp.utils.security.CP56Time2a.cp56toDate;
@Slf4j
public class CacheDataUtils { public class CacheDataUtils {
public static Object reflectTranslate(Object srcobj, Class tarclz, Class srcclz, Field[] targetfields) throws IllegalAccessException, InvocationTargetException, InstantiationException { public static Object reflectTranslate(Object srcobj, Class tarclz, Class srcclz, Field[] targetfields) throws IllegalAccessException, InvocationTargetException, InstantiationException {
@ -36,7 +38,12 @@ public class CacheDataUtils {
tarval = (Integer) tarval > 0 ? tarval : 0; tarval = (Integer) tarval > 0 ? tarval : 0;
} }
} else { } else {
tarval = HexUtils.reverseHexInt(srcval); try {
tarval = HexUtils.reverseHexInt(srcval);
} catch (java.lang.NumberFormatException e) { // todo 测试代码不应该在生产环境运行到这里
log.error("fatal!! 4 bytes (bin) number: {} - {}", tarfield.getName(), srcval);
tarval = 0;
}
} }
} else if (tarFieldName.contains("ime")) { } else if (tarFieldName.contains("ime")) {
tarval = DateUtil.format(cp56toDate(srcval), NORM_DATETIME_FORMAT); tarval = DateUtil.format(cp56toDate(srcval), NORM_DATETIME_FORMAT);
@ -47,6 +54,8 @@ public class CacheDataUtils {
} }
tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval); tarclz.getMethod("set".concat(capitalize(tarFieldName)), tarfield.getType()).invoke(tarobj, tarval);
} catch (NoSuchMethodException ignored) { } catch (NoSuchMethodException ignored) {
log.warn(" src[{}], tar[{}] NoSuchMethodException {}", tarclz.getName(),
srcclz.getName(), "set".concat(capitalize(tarFieldName)));
} }
} }
} }

View File

@ -18,10 +18,10 @@ spring:
nacos: nacos:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 172.31.183.135:8848 server-addr: 127.0.0.1:8848
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 172.31.183.135:8848 server-addr: 127.0.0.1:8848
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置