Accomplishing the notification_cancel_order.
This commit is contained in:
parent
8fb329ea06
commit
d583fcc92a
@ -0,0 +1,19 @@
|
|||||||
|
package com.xhpc.evcs.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author HongYun on 2021/11/8
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE)
|
||||||
|
public class CancelOrderRequest {
|
||||||
|
|
||||||
|
@JsonProperty("StartChargeSeq")
|
||||||
|
private String startChargeSeq;
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.xhpc.evcs.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author HongYun on 2021/11/8
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
|
||||||
|
setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE)
|
||||||
|
public class CancelOrderResponse {
|
||||||
|
|
||||||
|
@JsonProperty("SuccStat")
|
||||||
|
private Integer succStat;
|
||||||
|
}
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
package com.xhpc.evcs.notification;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.xhpc.evcs.domain.AuthSecretToken;
|
||||||
|
import com.xhpc.evcs.dto.*;
|
||||||
|
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||||
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||||
|
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author HongYun on 2021/11/8
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class NotificationCancelOrderTask extends CoreDispatcher {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AuthSecretTokenRepository authSecretTokenRepository;
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfoTask.class);
|
||||||
|
|
||||||
|
@Scheduled(fixedRate = 1000 * 15)
|
||||||
|
public void run() throws JsonProcessingException {
|
||||||
|
|
||||||
|
//Getting the orders, which need to be notified.
|
||||||
|
Collection<String> ordersNotFilter = REDIS.keys("order:*");
|
||||||
|
List<String> ordersNeedToNotify = new ArrayList<>();
|
||||||
|
for (String order : ordersNotFilter) {
|
||||||
|
String startStatus = REDIS.getCacheMapValue(order, "startStatus");
|
||||||
|
if ("失败".equals(startStatus)) {
|
||||||
|
ordersNeedToNotify.add(order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Getting the internetSerialNumbers, which need to be notified.
|
||||||
|
List<String> internetSerialNumbers = new ArrayList<>();
|
||||||
|
Collection<String> pushOrders = REDIS.keys("pushOrder:*");
|
||||||
|
List<String> orderMaybeNeedToDelete = new ArrayList<>();
|
||||||
|
for (String order : ordersNeedToNotify) {
|
||||||
|
String tempOrder = "pushOrder:" + order.substring(6);
|
||||||
|
if (pushOrders.contains(tempOrder)) {
|
||||||
|
String internetSerialNumber = REDIS.getCacheMapValue(tempOrder, "internetSerialNumber");
|
||||||
|
if (null != internetSerialNumber) {
|
||||||
|
internetSerialNumbers.add(internetSerialNumber);
|
||||||
|
orderMaybeNeedToDelete.add(order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Making notify.
|
||||||
|
for (int i = 0; i < internetSerialNumbers.size(); i++) {
|
||||||
|
String internetSerialNumber = internetSerialNumbers.get(i);
|
||||||
|
String orderNo = orderMaybeNeedToDelete.get(i);
|
||||||
|
String operatorId = internetSerialNumber.substring(0, 9);
|
||||||
|
AuthSecretToken authSecretTokenOut = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, SECRET_TOKEN_TYPE_OUT).orElse(null);
|
||||||
|
if (null != authSecretTokenOut) {
|
||||||
|
CancelOrderRequest cancelOrderRequest = new CancelOrderRequest();
|
||||||
|
cancelOrderRequest.setStartChargeSeq(internetSerialNumber);
|
||||||
|
notify(cancelOrderRequest, authSecretTokenOut, orderNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notify(CancelOrderRequest cancelOrderRequest, AuthSecretToken authSecretTokenOut, String orderNo) throws JsonProcessingException {
|
||||||
|
|
||||||
|
String operatorIdEvcs = "MA6DFCTD5";
|
||||||
|
String data = JSONUtil.toJSONString(cancelOrderRequest);
|
||||||
|
logger.debug(data);
|
||||||
|
CommonRequest<ChargeOrderInfo> commonRequest = new CommonRequest<>();
|
||||||
|
commonRequest.setOperatorId(operatorIdEvcs);
|
||||||
|
commonRequest.setData(data);
|
||||||
|
String responseBody = ok(commonRequest, "/notification_cancel_order", authSecretTokenOut, operatorIdEvcs);
|
||||||
|
CancelOrderResponse cancelOrderResponse = DTOJsonHelper.parseResponseData(responseBody,
|
||||||
|
CancelOrderResponse.class, authSecretTokenOut);
|
||||||
|
if (null != cancelOrderResponse) {
|
||||||
|
Integer succStat = cancelOrderResponse.getSuccStat();
|
||||||
|
if (null != succStat) {
|
||||||
|
if (0 == succStat) {
|
||||||
|
REDIS.deleteObject(orderNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user