完善订单启/停/异常/推送机制
This commit is contained in:
parent
8440605479
commit
fd9e215245
@ -28,33 +28,34 @@ public class NotificationStartChargeResultTask extends CoreDispatcher {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AuthSecretTokenRepository authSecretTokenRepository;
|
private AuthSecretTokenRepository authSecretTokenRepository;
|
||||||
|
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(NotificationStartChargeResultTask.class);
|
||||||
private Logger logger = LoggerFactory.getLogger(NotificationStartChargeResultTask.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Judging the 3rd whether it has got the start charging task.
|
* Judging the 3rd whether it has got the start charging task.
|
||||||
*/
|
*/
|
||||||
@Scheduled(fixedRate = 1000 * 20)
|
@Scheduled(fixedRate = 1000 * 3)
|
||||||
public void run() throws IOException {
|
public void run() throws IOException {
|
||||||
|
|
||||||
//Getting the charge orders which from 3rd.
|
//Getting the charge orders which from 3rd.
|
||||||
Collection<String> pushOrderKeys = REDIS.keys("pushOrder:*");
|
Collection<String> pushOrderKeys = REDIS.keys("pushOrder:*");
|
||||||
for (String pushOrderKey : pushOrderKeys) {
|
for (String pushOrderKey : pushOrderKeys) {
|
||||||
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderKey);
|
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderKey);
|
||||||
if (null != pushOrder) {
|
if ((Integer) pushOrder.get("startChargeSeqStat") > 1) {
|
||||||
Integer startChargeNotificationStat = (Integer) pushOrder.get("startChargeNotificationStat");
|
Integer startChargeNotificationStat = (Integer) pushOrder.get("startChargeNotificationStat");
|
||||||
if (null != startChargeNotificationStat && 1 != startChargeNotificationStat && startChargeNotificationStat <= 20) {
|
if (null != startChargeNotificationStat && 1 != startChargeNotificationStat && startChargeNotificationStat <= 20) {
|
||||||
String startChargeSeq = (String) pushOrder.get("internetSerialNumber");
|
String startChargeSeq = (String) pushOrder.get("internetSerialNumber");
|
||||||
String operatorId = startChargeSeq.substring(0, 9);
|
String operatorId = startChargeSeq.substring(0, 9);
|
||||||
Optional<AuthSecretToken> authSecretToken = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, SECRET_TOKEN_TYPE_OUT);
|
Optional<AuthSecretToken> authSecretToken =
|
||||||
|
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId,
|
||||||
|
SECRET_TOKEN_TYPE_OUT);
|
||||||
if (authSecretToken.isPresent()) {
|
if (authSecretToken.isPresent()) {
|
||||||
NotificationStartChargeResultRequestData notificationStartChargeResultRequestData = new NotificationStartChargeResultRequestData();
|
NotificationStartChargeResultRequestData notificationStartChargeResultRequestData =
|
||||||
|
new NotificationStartChargeResultRequestData();
|
||||||
notificationStartChargeResultRequestData.setStartTime((String) pushOrder.get("startTime"));
|
notificationStartChargeResultRequestData.setStartTime((String) pushOrder.get("startTime"));
|
||||||
notificationStartChargeResultRequestData.setStartChargeSeq(startChargeSeq);
|
notificationStartChargeResultRequestData.setStartChargeSeq(startChargeSeq);
|
||||||
notificationStartChargeResultRequestData.setConnectorId((String) pushOrder.get("connectorID"));
|
notificationStartChargeResultRequestData.setConnectorId((String) pushOrder.get("connectorID"));
|
||||||
REDIS.setCacheMapValue(pushOrderKey, "startChargeSeqStat", 2);
|
notificationStartChargeResultRequestData.setStartChargeSeqStat((Integer) pushOrder.get(
|
||||||
pushOrder.put("startChargeSeqStat", 2);
|
"startChargeSeqStat"));
|
||||||
notificationStartChargeResultRequestData.setStartChargeSeqStat((Integer) pushOrder.get("startChargeSeqStat"));
|
|
||||||
notify(notificationStartChargeResultRequestData, authSecretToken.get(), pushOrderKey.substring(10));
|
notify(notificationStartChargeResultRequestData, authSecretToken.get(), pushOrderKey.substring(10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +64,8 @@ public class NotificationStartChargeResultTask extends CoreDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Notifying others platform.
|
//Notifying others platform.
|
||||||
public void notify(NotificationStartChargeResultRequestData notificationStartChargeResultRequestData, AuthSecretToken authSecretTokenOut, String orderNo) throws IOException {
|
public void notify(NotificationStartChargeResultRequestData notificationStartChargeResultRequestData,
|
||||||
|
AuthSecretToken authSecretTokenOut, String orderNo) throws IOException {
|
||||||
|
|
||||||
String operatorIdEvcs = "MA6DFCTD5";
|
String operatorIdEvcs = "MA6DFCTD5";
|
||||||
String data = JSONUtil.toJSONString(notificationStartChargeResultRequestData);
|
String data = JSONUtil.toJSONString(notificationStartChargeResultRequestData);
|
||||||
@ -79,16 +81,19 @@ public class NotificationStartChargeResultTask extends CoreDispatcher {
|
|||||||
if (notificationStartStopChargeResultResponse.getSuccStat() == 0) {
|
if (notificationStartStopChargeResultResponse.getSuccStat() == 0) {
|
||||||
REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat", 1);
|
REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat", 1);
|
||||||
} else {
|
} else {
|
||||||
Integer startChargeNotificationStat = REDIS.getCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat");
|
Integer startChargeNotificationStat = REDIS.getCacheMapValue("pushOrder:".concat(orderNo),
|
||||||
|
"startChargeNotificationStat");
|
||||||
if (startChargeNotificationStat == 0) {
|
if (startChargeNotificationStat == 0) {
|
||||||
startChargeNotificationStat = 2;
|
startChargeNotificationStat = 2;
|
||||||
} else {
|
} else {
|
||||||
++startChargeNotificationStat;
|
++startChargeNotificationStat;
|
||||||
}
|
}
|
||||||
REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat", startChargeNotificationStat);
|
REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat",
|
||||||
|
startChargeNotificationStat);
|
||||||
throw new RuntimeException(String.format("push CD start charge order status [%s] failed: %s",
|
throw new RuntimeException(String.format("push CD start charge order status [%s] failed: %s",
|
||||||
notificationStartChargeResultRequestData.getStartChargeSeq(), responseBody));
|
notificationStartChargeResultRequestData.getStartChargeSeq(), responseBody));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,8 +50,8 @@ public class NotificationStopChargeResultTask extends CoreDispatcher {
|
|||||||
String orderNo = pushOrderKey.substring(10);
|
String orderNo = pushOrderKey.substring(10);
|
||||||
String orderkey = "order:".concat(orderNo);
|
String orderkey = "order:".concat(orderNo);
|
||||||
CacheOrderData orderData = REDIS.getCacheMapValue(orderkey, "orderData");
|
CacheOrderData orderData = REDIS.getCacheMapValue(orderkey, "orderData");
|
||||||
if (orderData != null) {
|
|
||||||
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderKey);
|
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderKey);
|
||||||
|
if (orderData != null || (Integer) pushOrder.get("startChargeSeqStat") > 3) {
|
||||||
Boolean isStopNotified = (Boolean) pushOrder.get("isStopNotified");
|
Boolean isStopNotified = (Boolean) pushOrder.get("isStopNotified");
|
||||||
if (isStopNotified == null || !isStopNotified) {
|
if (isStopNotified == null || !isStopNotified) {
|
||||||
String internetSerialNumber = (String) pushOrder.get("internetSerialNumber");
|
String internetSerialNumber = (String) pushOrder.get("internetSerialNumber");
|
||||||
@ -63,11 +63,9 @@ public class NotificationStopChargeResultTask extends CoreDispatcher {
|
|||||||
ChargeResultRequest chargeResultRequest = new ChargeResultRequest();
|
ChargeResultRequest chargeResultRequest = new ChargeResultRequest();
|
||||||
chargeResultRequest.setStartChargeSeq(internetSerialNumber);
|
chargeResultRequest.setStartChargeSeq(internetSerialNumber);
|
||||||
//使用指定包装类封装数据
|
//使用指定包装类封装数据
|
||||||
chargeResultRequest.setConnectorID(orderData.getPileNo() + orderData.getGunId());
|
chargeResultRequest.setConnectorID(orderkey.substring(0, 16));
|
||||||
int succStat = 0;
|
|
||||||
int failReason = 0;
|
|
||||||
chargeResultRequest.setStartChargeSeqStat(4);
|
chargeResultRequest.setStartChargeSeqStat(4);
|
||||||
chargeResultRequest.setSuccStat(succStat);
|
chargeResultRequest.setSuccStat(0);
|
||||||
chargeResultRequest.setFailReason(3);
|
chargeResultRequest.setFailReason(3);
|
||||||
//将其转换为json
|
//将其转换为json
|
||||||
String jsonData = JSONUtil.toJSONString(chargeResultRequest);
|
String jsonData = JSONUtil.toJSONString(chargeResultRequest);
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static cn.hutool.core.util.NumberUtil.isInteger;
|
|
||||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
import static com.xhpc.pp.server.ChargingPileServer.default_version;
|
import static com.xhpc.pp.server.ChargingPileServer.default_version;
|
||||||
import static com.xhpc.pp.utils.HexUtils.reverseHexInt;
|
import static com.xhpc.pp.utils.HexUtils.reverseHexInt;
|
||||||
@ -191,48 +190,57 @@ public class RealtimeDataLogic implements ServiceLogic {
|
|||||||
R r = null;
|
R r = null;
|
||||||
if (cacheRData == null) {
|
if (cacheRData == null) {
|
||||||
r = pileOrderService.abnormalOrder(orderNo);
|
r = pileOrderService.abnormalOrder(orderNo);
|
||||||
|
cacheOrder.put("abnormal", "1.1");//lord is null
|
||||||
|
log.error("abnormal.1 order[{}]", orderNo);
|
||||||
} else {
|
} else {
|
||||||
CacheOrderData lordAsOd = new CacheOrderData(cacheRData, (String) cacheOrder.get("orderstarttime"),
|
CacheOrderData lordAsOd = new CacheOrderData(cacheRData, (String) cacheOrder.get("orderstarttime"),
|
||||||
(Integer) cacheOrder.get("startSoc"), (Integer) cacheOrder.get("stopSoc"));
|
(Integer) cacheOrder.get("startSoc"), (Integer) cacheOrder.get("stopSoc"));
|
||||||
cacheOrder.put("orderData", lordAsOd);
|
cacheOrder.put("orderData", lordAsOd);
|
||||||
r = pileOrderService.pileEndOrder(orderNo);
|
r = pileOrderService.pileEndOrder(orderNo);
|
||||||
REDIS.setCacheMap(orderkey, cacheOrder);
|
REDIS.setCacheMap(orderkey, cacheOrder);
|
||||||
|
cacheOrder.put("abnormal", "1.2");//lord as orderData
|
||||||
|
log.error("abnormal.1.2 order[{}]", orderNo);
|
||||||
}
|
}
|
||||||
if (r == null || r.getCode() != 200) {
|
if (r == null || r.getCode() != 200) {
|
||||||
log.error("errorfreecnt r{}", JSONUtil.toJsonStr(r));
|
log.error("errorfreecnt r{}", JSONUtil.toJsonStr(r));
|
||||||
errorfreecnt = 1;
|
errorfreecnt = 1;
|
||||||
}
|
}
|
||||||
cacheOrder.put("abnormal.1", "lord as order data");
|
|
||||||
log.error("abnormal.1 order[{}]", orderNo);
|
|
||||||
}
|
}
|
||||||
cacheOrder.put("errorfreecnt", errorfreecnt);
|
cacheOrder.put("errorfreecnt", errorfreecnt);
|
||||||
}
|
}
|
||||||
REDIS.setCacheMap(orderkey, cacheOrder);
|
REDIS.setCacheMap(orderkey, cacheOrder);
|
||||||
} else {
|
} else {
|
||||||
orderkey = (String) cacheGun.get("orderkey");
|
orderkey = (String) cacheGun.get("orderkey");
|
||||||
if (orderkey != null) {
|
|
||||||
Integer idleCnt = (Integer) cacheGun.get("idleCnt");
|
Integer idleCnt = (Integer) cacheGun.get("idleCnt");
|
||||||
|
if (orderkey != null && statusInt != 3) {
|
||||||
idleCnt = idleCnt == null ? 0 : idleCnt;
|
idleCnt = idleCnt == null ? 0 : idleCnt;
|
||||||
idleCnt++;
|
idleCnt++;
|
||||||
if (idleCnt > 3) {
|
if (idleCnt >= 2) {
|
||||||
if (orderkey != null && orderkey.length() > 0) {
|
if (orderkey.length() > 0) {
|
||||||
Map<String, Object> problematicOrder = REDIS.getCacheMap(orderkey);
|
Map<String, Object> problematicOrder = REDIS.getCacheMap(orderkey);
|
||||||
Object orderData = problematicOrder.get("orderData");
|
CacheRealtimeData cacheRealtimeData = REDIS.getCacheObject(orderkey.concat(".lord"));
|
||||||
String status = (String) problematicOrder.get("status");
|
if (problematicOrder != null && cacheRealtimeData != null) {
|
||||||
if (!isInteger(status) && !status.equals("充电中") && orderData == null) {
|
Integer startSoc = (Integer) problematicOrder.get("startSoc");
|
||||||
String lorder = orderkey.replace("order:", "");
|
Integer endSoc = (Integer) problematicOrder.get("endSoc");
|
||||||
pileOrderService.abnormalOrder(lorder);
|
problematicOrder.put("orderData", new CacheOrderData(cacheRealtimeData,
|
||||||
log.error("abnormal.2 order[{}]", lorder);
|
(String) problematicOrder.get("startTime"),
|
||||||
|
startSoc == null ? 0 : startSoc, endSoc == null ? 0 : endSoc));
|
||||||
|
log.error("abnormal.2.1 order[{}]", orderNo);
|
||||||
|
cacheOrder.put("abnormal", "2.1");
|
||||||
|
} else {
|
||||||
|
log.error("abnormal.2.2 order[{}]", orderNo);
|
||||||
|
cacheOrder.put("abnormal", "2.2");//not respond
|
||||||
|
REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 4);
|
||||||
|
}
|
||||||
|
orderNo = orderkey.replace("order:", "");
|
||||||
|
pileOrderService.abnormalOrder(orderNo);
|
||||||
cacheGun.put("orderkey", null);
|
cacheGun.put("orderkey", null);
|
||||||
idleCnt = 0;
|
idleCnt = 0;
|
||||||
}
|
cacheGun.put("idleCnt", idleCnt);
|
||||||
// } else {
|
|
||||||
// Collection<String> cacheOrderKyes = REDIS.keys("order:".concat(terminalId).concat("*"));
|
|
||||||
// for (String cacheOrderKye : cacheOrderKyes) { //todo ???
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
idleCnt = 0;
|
||||||
cacheGun.put("idleCnt", idleCnt);
|
cacheGun.put("idleCnt", idleCnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,8 +25,8 @@ import static com.xhpc.pp.tx.ServiceResult.HEX_01;
|
|||||||
@Component("RemoteStartReplyDataLogic")
|
@Component("RemoteStartReplyDataLogic")
|
||||||
public class RemoteStartReplyDataLogic implements ServiceLogic {
|
public class RemoteStartReplyDataLogic implements ServiceLogic {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(RemoteStartReplyDataLogic.class);
|
private static final Logger log = LoggerFactory.getLogger(RemoteStartReplyDataLogic.class);
|
||||||
private static Map<String, String> frs;
|
private static final Map<String, String> frs;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
frs = new HashMap<>();
|
frs = new HashMap<>();
|
||||||
@ -65,8 +65,9 @@ public class RemoteStartReplyDataLogic implements ServiceLogic {
|
|||||||
REDIS.setCacheMap(gunkey, cacheGun);
|
REDIS.setCacheMap(gunkey, cacheGun);
|
||||||
REDIS.setCacheMap(orderkey, cacheOrder);
|
REDIS.setCacheMap(orderkey, cacheOrder);
|
||||||
pileOrderService.pileStartup(orderNo, 1, "启动充电成功");
|
pileOrderService.pileStartup(orderNo, 1, "启动充电成功");
|
||||||
|
REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 2);
|
||||||
} else {
|
} else {
|
||||||
|
REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 4);
|
||||||
final String remark = frs.get(remoteStartReplyData.getFailReason());
|
final String remark = frs.get(remoteStartReplyData.getFailReason());
|
||||||
pileOrderService.pileStartup(orderNo, 2, remark == null ? "未知错误" : remark);
|
pileOrderService.pileStartup(orderNo, 2, remark == null ? "未知错误" : remark);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user