stop invalid order

This commit is contained in:
zz 2022-03-15 14:46:56 +08:00
parent 1f25942aab
commit b4e7bb990d
3 changed files with 32 additions and 9 deletions

View File

@ -207,7 +207,7 @@ public class ChargingController {
refreshBalanceMsg = refreshBalanceMsg.concat(CRCCalculator.calcCrc(refreshBalanceMsg)); refreshBalanceMsg = refreshBalanceMsg.concat(CRCCalculator.calcCrc(refreshBalanceMsg));
ClientHandler handler = getHandler(pileNo); ClientHandler handler = getHandler(pileNo);
R<Object> r; R<Object> r;
if (handler != null) { //todo 余额下发重试机制 if (handler != null && handler.isOpen()) { //todo 余额下发重试机制
if (!handler.isOpen()) { if (!handler.isOpen()) {
log.error("[{}]({}) connection lost", handler.getName(), pileNo); log.error("[{}]({}) connection lost", handler.getName(), pileNo);
removeHandler(pileNo); removeHandler(pileNo);
@ -235,6 +235,11 @@ public class ChargingController {
String pileNo = startChargingData.getPileNo(); String pileNo = startChargingData.getPileNo();
ClientHandler handler = ChargingPileServer.getHandler(pileNo); ClientHandler handler = ChargingPileServer.getHandler(pileNo);
if (handler == null) { if (handler == null) {
try {
handler.closeConnection();
} catch (Exception e) {
log.error("invalid conn [{}]", handler.getName());
}
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次"); return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
} else if (!handler.isOpen()) { } else if (!handler.isOpen()) {
log.error("[{}]({}) connection lost", handler.getName(), pileNo); log.error("[{}]({}) connection lost", handler.getName(), pileNo);
@ -290,7 +295,11 @@ public class ChargingController {
ClientHandler handler = ChargingPileServer.getHandler(pileNo); ClientHandler handler = ChargingPileServer.getHandler(pileNo);
if (handler == null) { if (handler == null) {
// ChargingPileServer.removeHandler(pileNo); try {
handler.closeConnection();
} catch (Exception e) {
log.error("invalid conn [{}]", handler.getName());
}
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次"); return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
} }
try { try {
@ -321,7 +330,7 @@ public class ChargingController {
String pileNo = orderNo.substring(0, 14); String pileNo = orderNo.substring(0, 14);
ClientHandler handler = ChargingPileServer.getHandler(pileNo); ClientHandler handler = ChargingPileServer.getHandler(pileNo);
if (handler != null) { if (handler != null && handler.isOpen()) {
try { try {
String connectorId = pileNo.substring(0, 16); String connectorId = pileNo.substring(0, 16);
String gunkey = "gun:".concat(connectorId); String gunkey = "gun:".concat(connectorId);
@ -333,16 +342,22 @@ public class ChargingController {
removeHandler(pileNo); removeHandler(pileNo);
} else { } else {
String orderkey = REDIS.getCacheMapValue(gunkey, "orderkey"); String orderkey = REDIS.getCacheMapValue(gunkey, "orderkey");
Integer sts = REDIS.getCacheMapValue(orderkey, "sts"); // Integer sts = REDIS.getCacheMapValue(orderkey, "sts");
if (orderkey != null && orderNo.equals(orderkey.substring(6)) && (sts == null)) { if (orderkey != null && orderNo.equals(orderkey.substring(6))) {// && (sts == null)) {
handler.sendClientBinary(msg); handler.sendClientBinary(msg);
log.error("invalid orderNo [{}], stop msg sent to pile |{}|", pileNo, HexUtils.toHex(msg)); log.error("invalid orderNo [{}], stop msg sent to pile |{}|", pileNo, HexUtils.toHex(msg));
REDIS.setCacheMapValue(orderkey, "sts", 1); // REDIS.setCacheMapValue(orderkey, "sts", 1);
} }
} }
} catch (IOException e) { } 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();
} }
} }

View File

@ -69,7 +69,7 @@ public class PileController {
ClientHandler handler = getHandler(pileNo); ClientHandler handler = getHandler(pileNo);
R r; R r;
if (handler != null) { if (handler != null && handler.isOpen()) {
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);

View File

@ -6,6 +6,7 @@ import com.xhpc.common.api.PileOrderService;
import com.xhpc.common.core.domain.R; import com.xhpc.common.core.domain.R;
import com.xhpc.common.data.redis.CacheOrderData; import com.xhpc.common.data.redis.CacheOrderData;
import com.xhpc.common.data.up.OrderData; import com.xhpc.common.data.up.OrderData;
import com.xhpc.pp.controller.ChargingController;
import com.xhpc.pp.tx.ServiceParameter; import com.xhpc.pp.tx.ServiceParameter;
import com.xhpc.pp.tx.ServiceResult; import com.xhpc.pp.tx.ServiceResult;
import com.xhpc.pp.tx.logic.ServiceLogic; import com.xhpc.pp.tx.logic.ServiceLogic;
@ -33,6 +34,8 @@ public class OrderDataLogic implements ServiceLogic {
@Autowired @Autowired
private PileOrderService pileOrderService; private PileOrderService pileOrderService;
@Autowired
private ChargingController chargingController;
@Override @Override
public ServiceResult service(ServiceParameter sp) throws Exception { public ServiceResult service(ServiceParameter sp) throws Exception {
@ -76,8 +79,13 @@ public class OrderDataLogic implements ServiceLogic {
final R r = pileOrderService.pileEndOrder(orderNo); final R r = pileOrderService.pileEndOrder(orderNo);
if (r.getCode() == 200) if (r.getCode() == 200)
return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK); return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK);
else else {
String msg = r.getMsg();
if (msg != null && msg.contains("无效订单")) {
chargingController.stopInvalidOrder(pileNo);
}
return new ServiceResult(ServiceResult.FAIL); return new ServiceResult(ServiceResult.FAIL);
}
} }
private CacheOrderData translate(OrderData orderData) throws InvocationTargetException, IllegalAccessException, InstantiationException { private CacheOrderData translate(OrderData orderData) throws InvocationTargetException, IllegalAccessException, InstantiationException {