完善订单启/停/异常/推送机制

This commit is contained in:
ZZ 2021-11-24 13:01:06 +08:00
parent 8440605479
commit fd9e215245
4 changed files with 54 additions and 42 deletions

View File

@ -28,33 +28,34 @@ public class NotificationStartChargeResultTask extends CoreDispatcher {
@Autowired
private AuthSecretTokenRepository authSecretTokenRepository;
private Logger logger = LoggerFactory.getLogger(NotificationStartChargeResultTask.class);
private final Logger logger = LoggerFactory.getLogger(NotificationStartChargeResultTask.class);
/**
* Judging the 3rd whether it has got the start charging task.
*/
@Scheduled(fixedRate = 1000 * 20)
@Scheduled(fixedRate = 1000 * 3)
public void run() throws IOException {
//Getting the charge orders which from 3rd.
Collection<String> pushOrderKeys = REDIS.keys("pushOrder:*");
for (String pushOrderKey : pushOrderKeys) {
Map<String, Object> pushOrder = REDIS.getCacheMap(pushOrderKey);
if (null != pushOrder) {
if ((Integer) pushOrder.get("startChargeSeqStat") > 1) {
Integer startChargeNotificationStat = (Integer) pushOrder.get("startChargeNotificationStat");
if (null != startChargeNotificationStat && 1 != startChargeNotificationStat && startChargeNotificationStat <= 20) {
String startChargeSeq = (String) pushOrder.get("internetSerialNumber");
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()) {
NotificationStartChargeResultRequestData notificationStartChargeResultRequestData = new NotificationStartChargeResultRequestData();
NotificationStartChargeResultRequestData notificationStartChargeResultRequestData =
new NotificationStartChargeResultRequestData();
notificationStartChargeResultRequestData.setStartTime((String) pushOrder.get("startTime"));
notificationStartChargeResultRequestData.setStartChargeSeq(startChargeSeq);
notificationStartChargeResultRequestData.setConnectorId((String) pushOrder.get("connectorID"));
REDIS.setCacheMapValue(pushOrderKey, "startChargeSeqStat", 2);
pushOrder.put("startChargeSeqStat", 2);
notificationStartChargeResultRequestData.setStartChargeSeqStat((Integer) pushOrder.get("startChargeSeqStat"));
notificationStartChargeResultRequestData.setStartChargeSeqStat((Integer) pushOrder.get(
"startChargeSeqStat"));
notify(notificationStartChargeResultRequestData, authSecretToken.get(), pushOrderKey.substring(10));
}
}
@ -63,7 +64,8 @@ public class NotificationStartChargeResultTask extends CoreDispatcher {
}
//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 data = JSONUtil.toJSONString(notificationStartChargeResultRequestData);
@ -73,22 +75,25 @@ public class NotificationStartChargeResultTask extends CoreDispatcher {
String responseBody = ok(commonRequest, "/notification_start_charge_result", authSecretTokenOut);
NotificationStartStopChargeResultResponse notificationStartStopChargeResultResponse =
DTOJsonHelper.parseResponseData(responseBody,
NotificationStartStopChargeResultResponse.class, authSecretTokenOut);
NotificationStartStopChargeResultResponse.class, authSecretTokenOut);
if (null != notificationStartStopChargeResultResponse) {
//Ensuring that only when startChargeNotificationStat equals 1 won't be notified.
if (notificationStartStopChargeResultResponse.getSuccStat() == 0) {
REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat", 1);
} else {
Integer startChargeNotificationStat = REDIS.getCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat");
Integer startChargeNotificationStat = REDIS.getCacheMapValue("pushOrder:".concat(orderNo),
"startChargeNotificationStat");
if (startChargeNotificationStat == 0) {
startChargeNotificationStat = 2;
} else {
++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",
notificationStartChargeResultRequestData.getStartChargeSeq(), responseBody));
}
}
}
}

View File

@ -50,8 +50,8 @@ public class NotificationStopChargeResultTask extends CoreDispatcher {
String orderNo = pushOrderKey.substring(10);
String orderkey = "order:".concat(orderNo);
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");
if (isStopNotified == null || !isStopNotified) {
String internetSerialNumber = (String) pushOrder.get("internetSerialNumber");
@ -63,11 +63,9 @@ public class NotificationStopChargeResultTask extends CoreDispatcher {
ChargeResultRequest chargeResultRequest = new ChargeResultRequest();
chargeResultRequest.setStartChargeSeq(internetSerialNumber);
//使用指定包装类封装数据
chargeResultRequest.setConnectorID(orderData.getPileNo() + orderData.getGunId());
int succStat = 0;
int failReason = 0;
chargeResultRequest.setConnectorID(orderkey.substring(0, 16));
chargeResultRequest.setStartChargeSeqStat(4);
chargeResultRequest.setSuccStat(succStat);
chargeResultRequest.setSuccStat(0);
chargeResultRequest.setFailReason(3);
//将其转换为json
String jsonData = JSONUtil.toJSONString(chargeResultRequest);

View File

@ -29,7 +29,6 @@ import java.util.HashMap;
import java.util.List;
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.pp.server.ChargingPileServer.default_version;
import static com.xhpc.pp.utils.HexUtils.reverseHexInt;
@ -191,48 +190,57 @@ public class RealtimeDataLogic implements ServiceLogic {
R r = null;
if (cacheRData == null) {
r = pileOrderService.abnormalOrder(orderNo);
cacheOrder.put("abnormal", "1.1");//lord is null
log.error("abnormal.1 order[{}]", orderNo);
} else {
CacheOrderData lordAsOd = new CacheOrderData(cacheRData, (String) cacheOrder.get("orderstarttime"),
(Integer) cacheOrder.get("startSoc"), (Integer) cacheOrder.get("stopSoc"));
cacheOrder.put("orderData", lordAsOd);
r = pileOrderService.pileEndOrder(orderNo);
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) {
log.error("errorfreecnt r{}", JSONUtil.toJsonStr(r));
errorfreecnt = 1;
}
cacheOrder.put("abnormal.1", "lord as order data");
log.error("abnormal.1 order[{}]", orderNo);
}
cacheOrder.put("errorfreecnt", errorfreecnt);
}
REDIS.setCacheMap(orderkey, cacheOrder);
} else {
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++;
if (idleCnt > 3) {
if (orderkey != null && orderkey.length() > 0) {
if (idleCnt >= 2) {
if (orderkey.length() > 0) {
Map<String, Object> problematicOrder = REDIS.getCacheMap(orderkey);
Object orderData = problematicOrder.get("orderData");
String status = (String) problematicOrder.get("status");
if (!isInteger(status) && !status.equals("充电中") && orderData == null) {
String lorder = orderkey.replace("order:", "");
pileOrderService.abnormalOrder(lorder);
log.error("abnormal.2 order[{}]", lorder);
cacheGun.put("orderkey", null);
idleCnt = 0;
CacheRealtimeData cacheRealtimeData = REDIS.getCacheObject(orderkey.concat(".lord"));
if (problematicOrder != null && cacheRealtimeData != null) {
Integer startSoc = (Integer) problematicOrder.get("startSoc");
Integer endSoc = (Integer) problematicOrder.get("endSoc");
problematicOrder.put("orderData", new CacheOrderData(cacheRealtimeData,
(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);
}
// } else {
// Collection<String> cacheOrderKyes = REDIS.keys("order:".concat(terminalId).concat("*"));
// for (String cacheOrderKye : cacheOrderKyes) { //todo ???
//
// }
orderNo = orderkey.replace("order:", "");
pileOrderService.abnormalOrder(orderNo);
cacheGun.put("orderkey", null);
idleCnt = 0;
cacheGun.put("idleCnt", idleCnt);
}
}
} else {
idleCnt = 0;
cacheGun.put("idleCnt", idleCnt);
}
}

View File

@ -25,8 +25,8 @@ import static com.xhpc.pp.tx.ServiceResult.HEX_01;
@Component("RemoteStartReplyDataLogic")
public class RemoteStartReplyDataLogic implements ServiceLogic {
private static Logger log = LoggerFactory.getLogger(RemoteStartReplyDataLogic.class);
private static Map<String, String> frs;
private static final Logger log = LoggerFactory.getLogger(RemoteStartReplyDataLogic.class);
private static final Map<String, String> frs;
static {
frs = new HashMap<>();
@ -65,8 +65,9 @@ public class RemoteStartReplyDataLogic implements ServiceLogic {
REDIS.setCacheMap(gunkey, cacheGun);
REDIS.setCacheMap(orderkey, cacheOrder);
pileOrderService.pileStartup(orderNo, 1, "启动充电成功");
REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 2);
} else {
REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 4);
final String remark = frs.get(remoteStartReplyData.getFailReason());
pileOrderService.pileStartup(orderNo, 2, remark == null ? "未知错误" : remark);
}