stop invalid order
This commit is contained in:
parent
1f25942aab
commit
b4e7bb990d
@ -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,7 +330,7 @@ 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 gunkey = "gun:".concat(connectorId);
|
||||
@ -333,17 +342,23 @@ 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);
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] translateStart(StartChargingData startChargingData, String seq) {
|
||||
|
||||
@ -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 {
|
||||
@ -76,9 +79,14 @@ public class OrderDataLogic implements ServiceLogic {
|
||||
final R r = pileOrderService.pileEndOrder(orderNo);
|
||||
if (r.getCode() == 200)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private CacheOrderData translate(OrderData orderData) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user