避免因数据库错误造成第三方订单丢失
This commit is contained in:
parent
2f5be831b5
commit
946caa1f63
@ -573,29 +573,30 @@ public class XhpcChargeOrderServiceImpl extends BaseService implements IXhpcChar
|
||||
xhpcChargeOrder.setStatus(status);
|
||||
xhpcChargeOrder.setCreateTime(new Date());
|
||||
xhpcChargeOrder.setTerminalId(terminalId);
|
||||
try {
|
||||
xhpcChargeOrder.setPower(power.toString());
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
xhpcChargeOrder.setPower(power == null ? "120" : power.toString());
|
||||
xhpcChargeOrder.setSource(1);
|
||||
xhpcChargeOrder.setUserId(userId);
|
||||
xhpcChargeOrder.setChargingMode(chargingMode);
|
||||
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.addXhpcChargeOrder(xhpcChargeOrder);
|
||||
//int res = xhpcChargeOrderMapper.addBy3rd(internetSerialNumber, orderNo, driverId, chargingAmt, plateNum, status,
|
||||
// date,null, terminalId, power, chargingStationId, chargingMode, 1, userId);
|
||||
R r1 = powerPileService.startCharging(startChargingData);
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<第三方充电返回>>>>>>>>>>>>>>>>>");
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getCode() + ">>>>>>>>>>>>>>>>>");
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getMsg() + ">>>>>>>>>>>>>>>>>");
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<" + r1.getData() + ">>>>>>>>>>>>>>>>>");
|
||||
logger.info("<<<<<<<<<<<<<<<<<<<<<<<<第三方充电返回>>>>>>>>>>>>>>>>>");
|
||||
Long rateModelId = Long.valueOf(r1.getData().toString());
|
||||
xhpcChargeOrder.setRateModelId(rateModelId);
|
||||
xhpcChargeOrderMapper.updateXhpcChargeOrder(xhpcChargeOrder);
|
||||
try {
|
||||
Long rateModelId = Long.valueOf(r1.getData().toString());
|
||||
xhpcChargeOrder.setRateModelId(rateModelId);
|
||||
xhpcChargeOrderMapper.updateXhpcChargeOrder(xhpcChargeOrder);
|
||||
} catch (Exception e) {
|
||||
logger.error("update order[{}] failed.", orderNo);
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("orderNo", orderNo);
|
||||
data.put("startTime", startTime);
|
||||
data.put("orderNo", orderNo);
|
||||
r.setData(data);
|
||||
if (res != 0) {
|
||||
r.setCode(200);
|
||||
|
||||
@ -285,8 +285,8 @@ public class ChargingController {
|
||||
}
|
||||
|
||||
@GetMapping("native/charging/stop/{pileNo}/{connectorId}/{version}")
|
||||
public R nativeStopCharging(@PathVariable("pileNo") String pileNo, @PathVariable("connectorId") String connectorId,
|
||||
@PathVariable("version") String version) {
|
||||
public R stopInvalidOrder(@PathVariable("pileNo") String pileNo, @PathVariable("connectorId") String connectorId,
|
||||
@PathVariable("version") String version) {
|
||||
|
||||
ClientHandler handler = ChargingPileServer.getHandler(pileNo);
|
||||
if (handler == null) {
|
||||
@ -309,8 +309,6 @@ public class ChargingController {
|
||||
return R.ok("充电桩已离线");
|
||||
} else {
|
||||
handler.sendClientBinary(msg);
|
||||
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
|
||||
REDIS.setCacheMap(gunkey, cacheGun);
|
||||
return R.ok("停止充电指令已下发");
|
||||
}
|
||||
} 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) {
|
||||
|
||||
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.getPileNo()));
|
||||
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(toHexInt(startChargingData.getBalance())));
|
||||
} else {
|
||||
|
||||
@ -147,48 +147,52 @@ public class RealtimeDataLogic implements ServiceLogic {
|
||||
cacheOrder.put("totalPower", cacheRealtimeData.getChargingDegree() / 10000.0);
|
||||
cacheOrder.put("totalMoney", cacheRealtimeData.getAmountCharged() / 10000.0);
|
||||
cacheOrder.put("realtimeDataList", realtimeDataList);
|
||||
pileOrderService.pileRimeOrder(orderNo);
|
||||
Integer vul = (Integer) cachePile.get("voltageUpperLimits");
|
||||
Integer cul = (Integer) cachePile.get("currentLimit");
|
||||
if (wc > cul || wv > vul) {
|
||||
R r = chargingController.nativeStopCharging(pileNo, gunId, default_version);
|
||||
if (r.getCode() == 200) {
|
||||
Integer vcpcnt = (Integer) cacheOrder.get("vcpcnt");
|
||||
cacheOrder.put("vcpcnt", vcpcnt == null ? 1 : vcpcnt++);
|
||||
log.error("{} alert: v[{}], c[{}]", orderNo, wv, wc);
|
||||
}
|
||||
R r1 = pileOrderService.pileRimeOrder(orderNo);
|
||||
if (r1.getMsg().contains("无效订单")) {
|
||||
chargingController.stopInvalidOrder(pileNo);
|
||||
} else {
|
||||
Integer stopSoc = (Integer) cacheOrder.get("stopSoc");
|
||||
if (stopSoc != null && socInt >= stopSoc) {
|
||||
R r = chargingController.nativeStopCharging(pileNo, gunId, default_version);
|
||||
String alerted = (String) cacheOrder.get("socalerted");
|
||||
String tel = (String) cacheOrder.get("tel");
|
||||
if (alerted == null && tel != null) {
|
||||
if (r.getCode() == 200) {
|
||||
HashMap<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("battery", stopSoc.toString());
|
||||
paramMap.put("phone", tel);
|
||||
paramMap.put("content", "【小华充电】尊敬的用户,你的车辆已充电达至设定的SOC(" + stopSoc + "%)。");
|
||||
smsService.sendNotice(paramMap);
|
||||
cacheOrder.put("socalerted", "true");
|
||||
Integer vul = (Integer) cachePile.get("voltageUpperLimits");
|
||||
Integer cul = (Integer) cachePile.get("currentLimit");
|
||||
if (wc > cul || wv > vul) {
|
||||
R r = chargingController.stopInvalidOrder(pileNo, gunId, default_version);
|
||||
if (r.getCode() == 200) {
|
||||
Integer vcpcnt = (Integer) cacheOrder.get("vcpcnt");
|
||||
cacheOrder.put("vcpcnt", vcpcnt == null ? 1 : vcpcnt++);
|
||||
log.error("{} alert: v[{}], c[{}]", orderNo, wv, wc);
|
||||
}
|
||||
} else {
|
||||
Integer stopSoc = (Integer) cacheOrder.get("stopSoc");
|
||||
if (stopSoc != null && socInt >= stopSoc) {
|
||||
R r = chargingController.stopInvalidOrder(pileNo, gunId, default_version);
|
||||
String alerted = (String) cacheOrder.get("socalerted");
|
||||
String tel = (String) cacheOrder.get("tel");
|
||||
if (alerted == null && tel != null) {
|
||||
if (r.getCode() == 200) {
|
||||
HashMap<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("battery", stopSoc.toString());
|
||||
paramMap.put("phone", tel);
|
||||
paramMap.put("content", "【小华充电】尊敬的用户,你的车辆已充电达至设定的SOC(" + stopSoc + "%)。");
|
||||
smsService.sendNotice(paramMap);
|
||||
cacheOrder.put("socalerted", "true");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (balance < 50000) {
|
||||
String alerted = (String) cacheOrder.get("lt5alerted");
|
||||
String tel = (String) cacheOrder.get("tel");
|
||||
if (alerted == null && tel != null) {
|
||||
HashMap<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("money", "5");
|
||||
paramMap.put("phone", tel);
|
||||
paramMap.put("content", "【小华充电】尊敬的用户,你的账户余额小于5元,为不影响您的正常充电,请您尽快充值交费,谢谢。");
|
||||
smsService.sendNotice(paramMap);
|
||||
cacheOrder.put("lt5alerted", "true");
|
||||
if (balance < 50000) {
|
||||
String alerted = (String) cacheOrder.get("lt5alerted");
|
||||
String tel = (String) cacheOrder.get("tel");
|
||||
if (alerted == null && tel != null) {
|
||||
HashMap<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("money", "5");
|
||||
paramMap.put("phone", tel);
|
||||
paramMap.put("content", "【小华充电】尊敬的用户,你的账户余额小于5元,为不影响您的正常充电,请您尽快充值交费,谢谢。");
|
||||
smsService.sendNotice(paramMap);
|
||||
cacheOrder.put("lt5alerted", "true");
|
||||
}
|
||||
}
|
||||
if ("true".equals(cacheOrder.get("lordiss"))) {
|
||||
cacheOrder.put("lordiss", "false");
|
||||
pileOrderService.pileStop(orderNo, 4, "订单实时数据恢复");
|
||||
}
|
||||
}
|
||||
if ("true".equals(cacheOrder.get("lordiss"))) {
|
||||
cacheOrder.put("lordiss", "false");
|
||||
pileOrderService.pileStop(orderNo, 4, "订单实时数据恢复");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user