Merge branch 'tmp.zz'
This commit is contained in:
commit
1d1a716e04
@ -207,7 +207,7 @@ public class ChargingController {
|
||||
refreshBalanceMsg = refreshBalanceMsg.concat(CRCCalculator.calcCrc(refreshBalanceMsg));
|
||||
ClientHandler handler = getHandler(pileNo);
|
||||
R<Object> r;
|
||||
if (handler != null) { //todo 余额下发重试机制
|
||||
if (handler != null && handler.isOpen()) { //todo 余额下发重试机制
|
||||
if (!handler.isOpen()) {
|
||||
log.error("[{}]({}) connection lost", handler.getName(), pileNo);
|
||||
removeHandler(pileNo);
|
||||
@ -235,6 +235,11 @@ public class ChargingController {
|
||||
String pileNo = startChargingData.getPileNo();
|
||||
ClientHandler handler = ChargingPileServer.getHandler(pileNo);
|
||||
if (handler == null) {
|
||||
try {
|
||||
handler.closeConnection();
|
||||
} catch (Exception e) {
|
||||
log.error("invalid conn [{}]", handler.getName());
|
||||
}
|
||||
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
|
||||
} else if (!handler.isOpen()) {
|
||||
log.error("[{}]({}) connection lost", handler.getName(), pileNo);
|
||||
@ -290,7 +295,11 @@ public class ChargingController {
|
||||
|
||||
ClientHandler handler = ChargingPileServer.getHandler(pileNo);
|
||||
if (handler == null) {
|
||||
// ChargingPileServer.removeHandler(pileNo);
|
||||
try {
|
||||
handler.closeConnection();
|
||||
} catch (Exception e) {
|
||||
log.error("invalid conn [{}]", handler.getName());
|
||||
}
|
||||
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
|
||||
}
|
||||
try {
|
||||
@ -321,9 +330,9 @@ public class ChargingController {
|
||||
|
||||
String pileNo = orderNo.substring(0, 14);
|
||||
ClientHandler handler = ChargingPileServer.getHandler(pileNo);
|
||||
if (handler != null) {
|
||||
if (handler != null && handler.isOpen()) {
|
||||
try {
|
||||
String connectorId = pileNo.substring(0, 16);
|
||||
String connectorId = orderNo.substring(0, 16);
|
||||
String gunkey = "gun:".concat(connectorId);
|
||||
String skey = gunkey.concat(".seqhex");
|
||||
String seq = seqHex(skey);
|
||||
@ -333,16 +342,22 @@ public class ChargingController {
|
||||
removeHandler(pileNo);
|
||||
} else {
|
||||
String orderkey = REDIS.getCacheMapValue(gunkey, "orderkey");
|
||||
Integer sts = REDIS.getCacheMapValue(orderkey, "sts");
|
||||
if (orderkey != null && orderNo.equals(orderkey.substring(6)) && (sts == null)) {
|
||||
// Integer sts = REDIS.getCacheMapValue(orderkey, "sts");
|
||||
if (orderkey != null && orderNo.equals(orderkey.substring(6))) {// && (sts == null)) {
|
||||
handler.sendClientBinary(msg);
|
||||
log.error("invalid orderNo [{}], stop msg sent to pile |{}|", pileNo, HexUtils.toHex(msg));
|
||||
REDIS.setCacheMapValue(orderkey, "sts", 1);
|
||||
log.error("invalid orderNo [{}], stop msg sent to pile |{}|", orderNo, HexUtils.toHex(msg));
|
||||
// REDIS.setCacheMapValue(orderkey, "sts", 1);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("send message failed. " + e.getMessage(), e);
|
||||
try {
|
||||
handler.closeConnection();
|
||||
} catch (Exception e1) {
|
||||
log.error("invalid conn [{}]", handler.getName());
|
||||
}
|
||||
}
|
||||
} else if (handler != null) {
|
||||
handler.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ public class PileController {
|
||||
|
||||
ClientHandler handler = getHandler(pileNo);
|
||||
R r;
|
||||
if (handler != null) {
|
||||
if (handler != null && handler.isOpen()) {
|
||||
if (!handler.isOpen()) {
|
||||
log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo);
|
||||
removeHandler(pileNo);
|
||||
|
||||
@ -6,6 +6,7 @@ import com.xhpc.common.api.PileOrderService;
|
||||
import com.xhpc.common.core.domain.R;
|
||||
import com.xhpc.common.data.redis.CacheOrderData;
|
||||
import com.xhpc.common.data.up.OrderData;
|
||||
import com.xhpc.pp.controller.ChargingController;
|
||||
import com.xhpc.pp.tx.ServiceParameter;
|
||||
import com.xhpc.pp.tx.ServiceResult;
|
||||
import com.xhpc.pp.tx.logic.ServiceLogic;
|
||||
@ -33,6 +34,8 @@ public class OrderDataLogic implements ServiceLogic {
|
||||
|
||||
@Autowired
|
||||
private PileOrderService pileOrderService;
|
||||
@Autowired
|
||||
private ChargingController chargingController;
|
||||
|
||||
@Override
|
||||
public ServiceResult service(ServiceParameter sp) throws Exception {
|
||||
@ -70,14 +73,11 @@ public class OrderDataLogic implements ServiceLogic {
|
||||
String resultStr =
|
||||
"6815".concat(req.get("seqhex").toString()).concat("0040").concat(orderNo).concat(ServiceResult.HEX_00);
|
||||
resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr));
|
||||
if (orderNo.equals("00000000000000000000000000000000")) {
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||
}
|
||||
final R r = pileOrderService.pileEndOrder(orderNo);
|
||||
if (r.getCode() == 200)
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||
else
|
||||
return new ServiceResult(ServiceResult.FAIL);
|
||||
if (orderNo.equals("00000000000000000000000000000000") || (r.getMsg() != null && r.getMsg().contains("无效订单"))) {
|
||||
log.error(">>INVALID order [{}] detected. MUST check the system.<<", orderNo);
|
||||
}
|
||||
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
|
||||
}
|
||||
|
||||
private CacheOrderData translate(OrderData orderData) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
||||
|
||||
@ -150,7 +150,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
||||
R r1 = pileOrderService.pileRimeOrder(orderNo);
|
||||
String msg = r1.getMsg();
|
||||
if (msg!=null && msg.contains("无效订单")) {
|
||||
chargingController.stopInvalidOrder(pileNo);
|
||||
chargingController.stopInvalidOrder(orderNo);
|
||||
} else {
|
||||
Integer vul = (Integer) cachePile.get("voltageUpperLimits");
|
||||
Integer cul = (Integer) cachePile.get("currentLimit");
|
||||
|
||||
@ -32,11 +32,11 @@ public class ChargingPileEventHandler implements ClientEventHandler {
|
||||
public void lostConnection(ClientHandler handler) {
|
||||
|
||||
String pileNo = ChargingPileServer.getPileNo(handler);
|
||||
// if (pileNo != null) {
|
||||
// ChargingPileServer.disconnPileNGuns(pileNo);
|
||||
// }
|
||||
log.debug("<- ({}) - [{}] - {} ->",
|
||||
pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString());
|
||||
if (pileNo != null) {
|
||||
ChargingPileServer.disconnPileNGuns(pileNo);
|
||||
log.debug("<- ({}) -disconn- [{}] - {} ->", pileNo, handler.getName(),
|
||||
handler.getSocket().getRemoteSocketAddress().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user