避免因数据库错误造成第三方订单丢失
This commit is contained in:
parent
2f5be831b5
commit
946caa1f63
@ -573,29 +573,30 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar
|
|||||||
xhpcChargeOrder.setStatus(status);
|
xhpcChargeOrder.setStatus(status);
|
||||||
xhpcChargeOrder.setCreateTime(new Date());
|
xhpcChargeOrder.setCreateTime(new Date());
|
||||||
xhpcChargeOrder.setTerminalId(terminalId);
|
xhpcChargeOrder.setTerminalId(terminalId);
|
||||||
try {
|
xhpcChargeOrder.setPower(power == null ? "120" : power.toString());
|
||||||
xhpcChargeOrder.setPower(power.toString());
|
|
||||||
}catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
xhpcChargeOrder.setSource(1);
|
xhpcChargeOrder.setSource(1);
|
||||||
xhpcChargeOrder.setUserId(userId);
|
xhpcChargeOrder.setUserId(userId);
|
||||||
xhpcChargeOrder.setChargingMode(chargingMode);
|
xhpcChargeOrder.setChargingMode(chargingMode);
|
||||||
int res =xhpcChargeOrderMapper.addXhpcChargeOrder(xhpcChargeOrder);
|
int res = xhpcChargeOrderMapper.addXhpcChargeOrder(xhpcChargeOrder);
|
||||||
//int res = xhpcChargeOrderMapper.addBy3rd(internetSerialNumber, orderNo, driverId, chargingAmt, plateNum, status, date,null, terminalId, power, chargingStationId, chargingMode, 1, userId);
|
//int res = xhpcChargeOrderMapper.addBy3rd(internetSerialNumber, orderNo, driverId, chargingAmt, plateNum, status,
|
||||||
|
// date,null, terminalId, power, chargingStationId, chargingMode, 1, userId);
|
||||||
R r1 = powerPileService.startCharging(startChargingData);
|
R r1 = powerPileService.startCharging(startChargingData);
|
||||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<第三方充电返回>>>>>>>>>>>>>>>>>");
|
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<第三方充电返回>>>>>>>>>>>>>>>>>");
|
||||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getCode() + ">>>>>>>>>>>>>>>>>");
|
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getCode() + ">>>>>>>>>>>>>>>>>");
|
||||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getMsg() + ">>>>>>>>>>>>>>>>>");
|
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getMsg() + ">>>>>>>>>>>>>>>>>");
|
||||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getData() + ">>>>>>>>>>>>>>>>>");
|
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getData() + ">>>>>>>>>>>>>>>>>");
|
||||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<第三方充电返回>>>>>>>>>>>>>>>>>");
|
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<第三方充电返回>>>>>>>>>>>>>>>>>");
|
||||||
|
try {
|
||||||
Long rateModelId = Long.valueOf(r1.getData().toString());
|
Long rateModelId = Long.valueOf(r1.getData().toString());
|
||||||
xhpcChargeOrder.setRateModelId(rateModelId);
|
xhpcChargeOrder.setRateModelId(rateModelId);
|
||||||
xhpcChargeOrderMapper.updateXhpcChargeOrder(xhpcChargeOrder);
|
xhpcChargeOrderMapper.updateXhpcChargeOrder(xhpcChargeOrder);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("update order[{}] failed.", orderNo);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> data = new HashMap<>();
|
Map<String, Object> data = new HashMap<>();
|
||||||
data.put("orderNo", orderNo);
|
|
||||||
data.put("startTime", startTime);
|
data.put("startTime", startTime);
|
||||||
|
data.put("orderNo", orderNo);
|
||||||
r.setData(data);
|
r.setData(data);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
r.setCode(200);
|
r.setCode(200);
|
||||||
|
|||||||
@ -285,7 +285,7 @@ public class ChargingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("native/charging/stop/{pileNo}/{connectorId}/{version}")
|
@GetMapping("native/charging/stop/{pileNo}/{connectorId}/{version}")
|
||||||
public R nativeStopCharging(@PathVariable("pileNo") String pileNo, @PathVariable("connectorId") String connectorId,
|
public R stopInvalidOrder(@PathVariable("pileNo") String pileNo, @PathVariable("connectorId") String connectorId,
|
||||||
@PathVariable("version") String version) {
|
@PathVariable("version") String version) {
|
||||||
|
|
||||||
ClientHandler handler = ChargingPileServer.getHandler(pileNo);
|
ClientHandler handler = ChargingPileServer.getHandler(pileNo);
|
||||||
@ -309,8 +309,6 @@ public class ChargingController {
|
|||||||
return R.ok("充电桩已离线");
|
return R.ok("充电桩已离线");
|
||||||
} else {
|
} else {
|
||||||
handler.sendClientBinary(msg);
|
handler.sendClientBinary(msg);
|
||||||
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
|
||||||
REDIS.setCacheMap(gunkey, cacheGun);
|
|
||||||
return R.ok("停止充电指令已下发");
|
return R.ok("停止充电指令已下发");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -319,6 +317,35 @@ public class ChargingController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stopInvalidOrder(String orderNo) {
|
||||||
|
|
||||||
|
String pileNo = orderNo.substring(0, 14);
|
||||||
|
ClientHandler handler = ChargingPileServer.getHandler(pileNo);
|
||||||
|
if (handler != null) {
|
||||||
|
try {
|
||||||
|
String connectorId = pileNo.substring(0, 16);
|
||||||
|
String gunkey = "gun:".concat(connectorId);
|
||||||
|
String skey = gunkey.concat(".seqhex");
|
||||||
|
String seq = seqHex(skey);
|
||||||
|
byte[] msg = translateStop(connectorId, seq);
|
||||||
|
if (!handler.isOpen()) {
|
||||||
|
log.error("stop invalid order failed. [{}]({}) connection lost", handler.getName(), pileNo);
|
||||||
|
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)) {
|
||||||
|
handler.sendClientBinary(msg);
|
||||||
|
log.error("invalid orderNo [{}], stop msg sent to pile |{}|", pileNo, HexUtils.toHex(msg));
|
||||||
|
REDIS.setCacheMapValue(orderkey, "sts", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("send message failed. " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] translateStart(StartChargingData startChargingData, String seq) {
|
private byte[] translateStart(StartChargingData startChargingData, String seq) {
|
||||||
|
|
||||||
byte[] data = new byte[0];
|
byte[] data = new byte[0];
|
||||||
@ -328,7 +355,8 @@ public class ChargingController {
|
|||||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getOrderNo()));
|
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getOrderNo()));
|
||||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getPileNo()));
|
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getPileNo()));
|
||||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getGunId()));
|
data = ArrayUtils.addAll(data, HexUtils.toBytes(startChargingData.getGunId()));
|
||||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(String.format("%016X", Long.parseLong(startChargingData.getLogicCardNo(), 16))));
|
data = ArrayUtils.addAll(data, HexUtils.toBytes(String.format("%016X",
|
||||||
|
Long.parseLong(startChargingData.getLogicCardNo(), 16))));
|
||||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(String.format("%016X", Long.parseLong(startChargingData.getPhysicCardNo(), 16))));
|
data = ArrayUtils.addAll(data, HexUtils.toBytes(String.format("%016X", Long.parseLong(startChargingData.getPhysicCardNo(), 16))));
|
||||||
data = ArrayUtils.addAll(data, HexUtils.toBytes(toHexInt(startChargingData.getBalance())));
|
data = ArrayUtils.addAll(data, HexUtils.toBytes(toHexInt(startChargingData.getBalance())));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -147,11 +147,14 @@ public class RealtimeDataLogic implements ServiceLogic {
|
|||||||
cacheOrder.put("totalPower", cacheRealtimeData.getChargingDegree() / 10000.0);
|
cacheOrder.put("totalPower", cacheRealtimeData.getChargingDegree() / 10000.0);
|
||||||
cacheOrder.put("totalMoney", cacheRealtimeData.getAmountCharged() / 10000.0);
|
cacheOrder.put("totalMoney", cacheRealtimeData.getAmountCharged() / 10000.0);
|
||||||
cacheOrder.put("realtimeDataList", realtimeDataList);
|
cacheOrder.put("realtimeDataList", realtimeDataList);
|
||||||
pileOrderService.pileRimeOrder(orderNo);
|
R r1 = pileOrderService.pileRimeOrder(orderNo);
|
||||||
|
if (r1.getMsg().contains("无效订单")) {
|
||||||
|
chargingController.stopInvalidOrder(pileNo);
|
||||||
|
} else {
|
||||||
Integer vul = (Integer) cachePile.get("voltageUpperLimits");
|
Integer vul = (Integer) cachePile.get("voltageUpperLimits");
|
||||||
Integer cul = (Integer) cachePile.get("currentLimit");
|
Integer cul = (Integer) cachePile.get("currentLimit");
|
||||||
if (wc > cul || wv > vul) {
|
if (wc > cul || wv > vul) {
|
||||||
R r = chargingController.nativeStopCharging(pileNo, gunId, default_version);
|
R r = chargingController.stopInvalidOrder(pileNo, gunId, default_version);
|
||||||
if (r.getCode() == 200) {
|
if (r.getCode() == 200) {
|
||||||
Integer vcpcnt = (Integer) cacheOrder.get("vcpcnt");
|
Integer vcpcnt = (Integer) cacheOrder.get("vcpcnt");
|
||||||
cacheOrder.put("vcpcnt", vcpcnt == null ? 1 : vcpcnt++);
|
cacheOrder.put("vcpcnt", vcpcnt == null ? 1 : vcpcnt++);
|
||||||
@ -160,7 +163,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
|||||||
} else {
|
} else {
|
||||||
Integer stopSoc = (Integer) cacheOrder.get("stopSoc");
|
Integer stopSoc = (Integer) cacheOrder.get("stopSoc");
|
||||||
if (stopSoc != null && socInt >= stopSoc) {
|
if (stopSoc != null && socInt >= stopSoc) {
|
||||||
R r = chargingController.nativeStopCharging(pileNo, gunId, default_version);
|
R r = chargingController.stopInvalidOrder(pileNo, gunId, default_version);
|
||||||
String alerted = (String) cacheOrder.get("socalerted");
|
String alerted = (String) cacheOrder.get("socalerted");
|
||||||
String tel = (String) cacheOrder.get("tel");
|
String tel = (String) cacheOrder.get("tel");
|
||||||
if (alerted == null && tel != null) {
|
if (alerted == null && tel != null) {
|
||||||
@ -191,6 +194,7 @@ public class RealtimeDataLogic implements ServiceLogic {
|
|||||||
pileOrderService.pileStop(orderNo, 4, "订单实时数据恢复");
|
pileOrderService.pileStop(orderNo, 4, "订单实时数据恢复");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (cacheGun.get("orderkey") == null) {
|
if (cacheGun.get("orderkey") == null) {
|
||||||
cacheGun.put("orderkey", orderkey);
|
cacheGun.put("orderkey", orderkey);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user