Merge remote-tracking branch 'origin/master'

This commit is contained in:
yuyang 2021-11-23 16:35:19 +08:00
commit 68d1b2e4cd
10 changed files with 40 additions and 38 deletions

View File

@ -41,7 +41,7 @@ public class ChargingController {
@Autowired @Autowired
private PowerPileService powerPileService; private PowerPileService powerPileService;
private static List<String> etable = Arrays.asList((new String[]{"离线", "故障"}).clone()); private static final List<String> etable = Arrays.asList((new String[]{"离线", "故障"}).clone());
@PostMapping("test/pile/charging/order") @PostMapping("test/pile/charging/order")
public R test(@Validated @RequestBody StartChargingData startChargingData) { public R test(@Validated @RequestBody StartChargingData startChargingData) {
@ -77,7 +77,7 @@ public class ChargingController {
r = R.fail("Native服务调用失败"); r = R.fail("Native服务调用失败");
} else { } else {
int code = responseJson.getInteger("code"); int code = responseJson.getInteger("code");
log.info(response); log.debug(response);
if (code != 200) {//todo rat if (code != 200) {//todo rat
r = R.fail(code, responseJson.getString("msg")); r = R.fail(code, responseJson.getString("msg"));
} else { } else {
@ -204,7 +204,7 @@ public class ChargingController {
r = R.fail("网络连接断开,无法刷新桩上余额"); r = R.fail("网络连接断开,无法刷新桩上余额");
} else { } else {
try { try {
log.info("native refresh balance >>> {}", refreshBalanceMsg); log.debug("native refresh balance >>> {}", refreshBalanceMsg);
handler.sendClientBinary(HexUtils.toBytes(refreshBalanceMsg)); handler.sendClientBinary(HexUtils.toBytes(refreshBalanceMsg));
r = R.ok("余额刷新指令已下发"); r = R.ok("余额刷新指令已下发");
} catch (IOException e) { } catch (IOException e) {
@ -326,7 +326,7 @@ public class ChargingController {
} }
String msg = HexUtils.toHex(data); 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.debug("start charging order[{}], send msg >>>> |{}|", startChargingData.getOrderNo(), msg);
return HexUtils.toBytes(msg); return HexUtils.toBytes(msg);
} }
@ -339,7 +339,7 @@ public class ChargingController {
} }
String msg = HexUtils.toHex(data); String msg = HexUtils.toHex(data);
msg = msg.concat(CRCCalculator.calcCrc(msg)); msg = msg.concat(CRCCalculator.calcCrc(msg));
log.info("stop charging, send msg to terminal ({}) >>>> {}", connectorId, msg); log.debug("stop charging, send msg to terminal ({}) >>>> {}", connectorId, msg);
return HexUtils.toBytes(msg); return HexUtils.toBytes(msg);
} }

View File

@ -76,7 +76,7 @@ public class PileController {
r = R.fail("充电桩连接已断开,请稍后再试"); r = R.fail("充电桩连接已断开,请稍后再试");
} else { } else {
try { try {
log.info("[{}] - server send msg >>>> ({}) |{}|", handler.getName(), pileNo, msg); log.debug("[{}] - server send msg >>>> ({}) |{}|", handler.getName(), pileNo, msg);
handler.sendClientBinary(HexUtils.toBytes(msg)); handler.sendClientBinary(HexUtils.toBytes(msg));
r = R.ok(null, "网络延迟,请重试"); r = R.ok(null, "网络延迟,请重试");
} catch (IOException e) { } catch (IOException e) {

View File

@ -16,7 +16,7 @@ import java.util.Map;
@Component("BalanceUpdateReplyDataLogic") @Component("BalanceUpdateReplyDataLogic")
public class BalanceUpdateReplyDataLogic implements ServiceLogic { public class BalanceUpdateReplyDataLogic implements ServiceLogic {
private static Logger log = LoggerFactory.getLogger(BalanceUpdateReplyDataLogic.class); private static final Logger log = LoggerFactory.getLogger(BalanceUpdateReplyDataLogic.class);
@Override @Override
public ServiceResult service(ServiceParameter sp) throws Exception { public ServiceResult service(ServiceParameter sp) throws Exception {
@ -24,7 +24,7 @@ public class BalanceUpdateReplyDataLogic implements ServiceLogic {
Map<String, Object> req = sp.getParameters(); Map<String, Object> req = sp.getParameters();
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
BalanceUpdateReplyData balanceUpdateReplyData = objectMapper.convertValue(req, BalanceUpdateReplyData.class); BalanceUpdateReplyData balanceUpdateReplyData = objectMapper.convertValue(req, BalanceUpdateReplyData.class);
log.info("balanceUpdateResult({}) [{}]", balanceUpdateReplyData.getPileNo(), balanceUpdateReplyData.getModifyResult()); log.debug("balanceUpdateResult({}) [{}]", balanceUpdateReplyData.getPileNo(), balanceUpdateReplyData.getModifyResult());
return new ServiceResult(false); return new ServiceResult(false);
} }

View File

@ -21,7 +21,7 @@ import static com.xhpc.pp.utils.security.CP56Time2a.cp56toDate;
@Component("PileTimeConfigReplyDataLogic") @Component("PileTimeConfigReplyDataLogic")
public class PileTimeConfigReplyDataLogic implements ServiceLogic { public class PileTimeConfigReplyDataLogic implements ServiceLogic {
private static Logger log = LoggerFactory.getLogger(PileTimeConfigReplyDataLogic.class); private static final Logger log = LoggerFactory.getLogger(PileTimeConfigReplyDataLogic.class);
@Override @Override
public ServiceResult service(ServiceParameter sp) throws Exception { public ServiceResult service(ServiceParameter sp) throws Exception {
@ -35,7 +35,7 @@ public class PileTimeConfigReplyDataLogic implements ServiceLogic {
Map<String, Object> cachePile = REDIS.getCacheMap(pk); Map<String, Object> cachePile = REDIS.getCacheMap(pk);
cachePile.put("configTime", configTime); cachePile.put("configTime", configTime);
REDIS.setCacheMap(pk, cachePile); REDIS.setCacheMap(pk, cachePile);
log.info("({}) set time success√: [{}]", pileNo, configTime); log.debug("({}) set time success√: [{}]", pileNo, configTime);
return new ServiceResult(false); return new ServiceResult(false);
} }

View File

@ -25,7 +25,7 @@ public class RegisterLogic implements ServiceLogic {
public static final String DISCONNECTED = "离线"; public static final String DISCONNECTED = "离线";
public static final String REGISTERED = "已注册"; public static final String REGISTERED = "已注册";
private static Logger log = LoggerFactory.getLogger(RegisterLogic.class); private static final Logger log = LoggerFactory.getLogger(RegisterLogic.class);
@Override @Override
public ServiceResult service(ServiceParameter sp) throws Exception { public ServiceResult service(ServiceParameter sp) throws Exception {
@ -36,11 +36,11 @@ public class RegisterLogic implements ServiceLogic {
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.debug("pile not in whitelist ({}) ", pileNo);
hexCode = ServiceResult.HEX_01; hexCode = ServiceResult.HEX_01;
resultCode = ServiceResult.FAIL; resultCode = ServiceResult.FAIL;
// } else if (!EarlierBeanConf.ifcanreg(pileNo)) { // not a stable reliable method // } else if (!EarlierBeanConf.ifcanreg(pileNo)) { // not a stable reliable method
// log.info("pile already registered ({}) ", pileNo); // log.debug("pile already registered ({}) ", pileNo);
// hexCode = ServiceResult.HEX_01; // hexCode = ServiceResult.HEX_01;
// resultCode = ServiceResult.FAIL; // resultCode = ServiceResult.FAIL;
} else { } else {
@ -70,7 +70,7 @@ public class RegisterLogic implements ServiceLogic {
} }
} }
} }
log.info("pile (re)registered ({}) ", pileNo); log.debug("pile (re)registered ({}) ", pileNo);
} }
String skey = "pile:".concat(pileNo).concat(".seqhex"); String skey = "pile:".concat(pileNo).concat(".seqhex");
String seq = seqHex(skey); String seq = seqHex(skey);

View File

@ -62,9 +62,9 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
for (byte[] d : dataList) { for (byte[] d : dataList) {
String dataStr = toHex(d); String dataStr = toHex(d);
String pileNo = ChargingPileServer.getPileNo(handler); String pileNo = ChargingPileServer.getPileNo(handler);
log.info("received data <<<< |{}| from pile <- ({})", dataStr, pileNo); log.debug("received data <<<< |{}| from pile <- ({})", dataStr, pileNo);
if (d.length <= 2 || !dataStr.startsWith("68")) { if (d.length <= 2 || !dataStr.startsWith("68")) {
log.info("received invalid data <<<< |{}|, len[{}]", dataStr, d.length); log.debug("received invalid data <<<< |{}|, len[{}]", dataStr, d.length);
continue; continue;
} }
int len = HexUtils.toInteger(d, 1, 2); int len = HexUtils.toInteger(d, 1, 2);
@ -114,7 +114,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo); log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo);
removeHandler(pileNo); removeHandler(pileNo);
} else { } else {
log.info("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary())); log.debug("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary()));
handler.sendClientBinary(result.getBinary()); handler.sendClientBinary(result.getBinary());
} }
if (SERVICE_HB.equals(serviceName) && OK.equals(resultCode)) { if (SERVICE_HB.equals(serviceName) && OK.equals(resultCode)) {
@ -126,7 +126,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
String timebin = getTimeBin(seqHex(skey), pileNo, date); String timebin = getTimeBin(seqHex(skey), pileNo, date);
cachePile.put("configTime", DateUtil.format(date, NORM_DATETIME_FORMAT)); cachePile.put("configTime", DateUtil.format(date, NORM_DATETIME_FORMAT));
REDIS.setCacheMap(pilekey, cachePile); REDIS.setCacheMap(pilekey, cachePile);
log.info("server send time config msg >>>> ({}) |{}|", pileNo, timebin); log.debug("server send time config msg >>>> ({}) |{}|", pileNo, timebin);
if (!handler.isOpen()) { if (!handler.isOpen()) {
log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo); log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo);
removeHandler(pileNo); removeHandler(pileNo);
@ -162,7 +162,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
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());
REDIS.setCacheMap(pilekey, cachePile); REDIS.setCacheMap(pilekey, cachePile);
log.info("rate model responds success√"); log.debug("rate model responds success√");
} }
private List<byte[]> parseDataList(byte[] data) { private List<byte[]> parseDataList(byte[] data) {
@ -173,16 +173,19 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
int start = 0; int start = 0;
while (start < data.length) { while (start < data.length) {
if (len > data.length) { if (len > data.length) {
log.error("incorrect input data|{}| len[{}]", toHex(data), data.length); String hex = toHex(data);
if (!hex.startsWith("25", 10)) {
log.error("incorrect input data|{}| len[{}]", hex, data.length);
break; break;
} }
}
dataList.add(ArrayUtils.subarray(data, start, start + len)); dataList.add(ArrayUtils.subarray(data, start, start + len));
processedLen += len; processedLen += len;
start = processedLen; start = processedLen;
len = HexUtils.toInteger(data, start + 1, start + 2) + 4; len = HexUtils.toInteger(data, start + 1, start + 2) + 4;
} }
if (dataList.size() > 1) { if (dataList.size() > 1) {
log.info("detected stick package size[{}]", dataList.size()); log.debug("detected stick package size[{}]", dataList.size());
} }
return dataList; return dataList;
} }

View File

@ -7,7 +7,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.io.IOException; import java.io.IOException;
import java.net.SocketTimeoutException;
@Repository @Repository
public class ChargingPileCommandHandler implements ClientCommandHandler { public class ChargingPileCommandHandler implements ClientCommandHandler {
@ -19,9 +18,9 @@ public class ChargingPileCommandHandler implements ClientCommandHandler {
} }
@Override @Override
public void handleCommand(ClientHandler handler, String appData) throws SocketTimeoutException, IOException { public void handleCommand(ClientHandler handler, String appData) throws IOException {
log.info("handleCommand <====" + appData); log.debug("handleCommand <====" + appData);
} }

View File

@ -25,7 +25,7 @@ public class ChargingPileEventHandler implements ClientEventHandler {
@Override @Override
public void gotConnected(ClientHandler handler) { public void gotConnected(ClientHandler handler) {
log.info("-> [{}] - {} <-", handler.getName(), handler.getSocket().getRemoteSocketAddress().toString()); log.debug("-> [{}] - {} <-", handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
} }
@Override @Override
@ -35,7 +35,7 @@ public class ChargingPileEventHandler implements ClientEventHandler {
// if (pileNo != null) { // if (pileNo != null) {
// ChargingPileServer.disconnPileNGuns(pileNo); // ChargingPileServer.disconnPileNGuns(pileNo);
// } // }
log.info("<- ({}) - [{}] - {} ->", log.debug("<- ({}) - [{}] - {} ->",
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString()); pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
} }
@ -49,7 +49,7 @@ public class ChargingPileEventHandler implements ClientEventHandler {
cachePile.put("status", DISCONNECTED); cachePile.put("status", DISCONNECTED);
REDIS.setCacheMap(pkey, cachePile); REDIS.setCacheMap(pkey, cachePile);
handler.closeConnection(); handler.closeConnection();
log.info("<- ({}) - [{}] - {} ->", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString()); log.debug("<- ({}) - [{}] - {} ->", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
} }
} }

View File

@ -33,9 +33,9 @@ public class ChargingPileServer {
public static final String default_version = "0A"; public static final String default_version = "0A";
private static final Logger log = LoggerFactory.getLogger(ChargingPileServer.class); private static final Logger log = LoggerFactory.getLogger(ChargingPileServer.class);
private static Map<String, ClientHandler> handlerMap = new HashMap<>(); private static final Map<String, ClientHandler> handlerMap = new HashMap<>();
private static Map<String, String> versionMapper = new HashMap<>(); private static final Map<String, String> versionMapper = new HashMap<>();
private static Map<String, String> pileMap = new HashMap<>(); private static final Map<String, String> pileMap = new HashMap<>();
private QuickServer server; private QuickServer server;
@Autowired @Autowired
@ -62,7 +62,7 @@ public class ChargingPileServer {
config.setTimeout(90 * 1000); config.setTimeout(90 * 1000);
server.initService(config); server.initService(config);
server.startServer(); server.startServer();
log.info("pp svc started at {}:{} ....", host, port); log.debug("pp svc started at {}:{} ....", host, port);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("pp svc start error: " + e); log.error("pp svc start error: " + e);
@ -79,7 +79,7 @@ public class ChargingPileServer {
ClientHandler handler = handlerMap.remove(pileNo); ClientHandler handler = handlerMap.remove(pileNo);
handler.closeConnection(); handler.closeConnection();
log.info("handler [{}] for ({}) close connection", handler.getName(), pileNo); log.debug("handler [{}] for ({}) close connection", handler.getName(), pileNo);
String pkey = "pile:".concat(pileNo); String pkey = "pile:".concat(pileNo);
Map<String, Object> cachePile = REDIS.getCacheMap(pkey); Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
putemDisconn(pileNo, cachePile); putemDisconn(pileNo, cachePile);
@ -113,20 +113,20 @@ public class ChargingPileServer {
ClientHandler handler = handlerMap.remove(pileNo); ClientHandler handler = handlerMap.remove(pileNo);
// handler.closeConnection(); // handler.closeConnection();
// log.info("handler [{}] for ({}) close connection", handler.getName(), pileNo); // log.debug("handler [{}] for ({}) close connection", handler.getName(), pileNo);
String pkey = "pile:".concat(pileNo); String pkey = "pile:".concat(pileNo);
Map<String, Object> cachePile = REDIS.getCacheMap(pkey); Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
cachePile.put("status", DISCONNECTED); cachePile.put("status", DISCONNECTED);
REDIS.setCacheMap(pkey, cachePile); REDIS.setCacheMap(pkey, cachePile);
putemDisconn(pileNo, cachePile); putemDisconn(pileNo, cachePile);
log.info("remove handler [{}] for ({})", handler.getName(), pileNo); log.debug("remove handler [{}] for ({})", handler.getName(), pileNo);
pileMap.remove(handler.getName()); pileMap.remove(handler.getName());
versionMapper.remove(handler.getName()); versionMapper.remove(handler.getName());
} }
public static void sendClientMsg(String pileNo, byte[] msg) { public static void sendClientMsg(String pileNo, byte[] msg) {
log.info("server send msg >>>> ({}) |{}|", pileNo, HexUtils.toHex(msg)); log.debug("server send msg >>>> ({}) |{}|", pileNo, HexUtils.toHex(msg));
if (pileNo.length() < 14) { if (pileNo.length() < 14) {
pileNo = "0000000000000000" + pileNo; pileNo = "0000000000000000" + pileNo;
pileNo = pileNo.substring(pileNo.length() - 14); pileNo = pileNo.substring(pileNo.length() - 14);

View File

@ -59,13 +59,13 @@
</appender> </appender>
<!-- 系统模块日志级别控制 --> <!-- 系统模块日志级别控制 -->
<logger name="com.xhpc" level="info"/> <logger name="com.xhpc" level="debug"/>
<!-- Spring日志级别控制 --> <!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/> <logger name="org.springframework" level="warn"/>
<!-- nacos --> <!-- nacos -->
<logger name="com.alibaba.nacos" level="warn"/> <logger name="com.alibaba.nacos" level="warn"/>
<root level="info"> <root level="debug">
<appender-ref ref="console"/> <appender-ref ref="console"/>
</root> </root>