监管方推送失败问题解决O(∩_∩)O

This commit is contained in:
ZZ 2021-12-29 15:37:40 +08:00
parent 38402762ea
commit 41c9749de9
5 changed files with 85 additions and 13 deletions

View File

@ -0,0 +1,21 @@
package com.xhpc.evcs.domain;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Getter
@Setter
@Entity
@Table(name = "ET_PUSH_FAILED_ORDER")
public class EtPushFailedOrder {
@Id
private Long id;
private String operatorId3rdpty;
}

View File

@ -0,0 +1,13 @@
package com.xhpc.evcs.jpa;
import com.xhpc.evcs.domain.EtPushFailedOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface EtPushFailedOrderRepository extends JpaRepository<EtPushFailedOrder, Long>,
QueryByExampleExecutor<EtPushFailedOrder>, JpaSpecificationExecutor<EtPushFailedOrder> {
}

View File

@ -3,6 +3,7 @@ package com.xhpc.evcs.jpa;
import com.xhpc.order.domain.XhpcHistoryOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@ -18,4 +19,8 @@ public interface XhpcHistoryOrderRepository extends JpaRepository<XhpcHistoryOrd
List<XhpcHistoryOrder> findByConfirmResultNotAndSource(int confirmResult, int source);
@Query("select ho from XhpcHistoryOrder ho join EtPushFailedOrder fo on ho.historyOrderId = fo.id where fo" +
".operatorId3rdpty = ?1")
List<XhpcHistoryOrder> findJoinPushFailedOrders(String operatorId3irdpty);
}

View File

@ -46,6 +46,12 @@ public class CoreDispatcher {
@Transactional
public String ok(Object object, String url, AuthSecretToken authSecretTokenOut) {
return ok(object, url, authSecretTokenOut, null);
}
@Transactional
public String ok(Object object, String url, AuthSecretToken authSecretTokenOut, String stationOperatorId) {
if (authSecretTokenOut == null) {
log.error("authSecretTokenOut is null");
throw new RuntimeException();
@ -65,7 +71,11 @@ public class CoreDispatcher {
try {
if (object.getClass().getSimpleName().equals("CommonRequest")) {
CommonRequest commonRequest = (CommonRequest) object;
if (stationOperatorId != null) {
commonRequest.setOperatorId(stationOperatorId);
} else {
commonRequest.setOperatorId(authSecretTokenOut.getOperatorId());
}
Date tokenExpiry = authSecretTokenOut.getTokenExpiry();
String originalData = commonRequest.getData();
String tData;

View File

@ -1,9 +1,6 @@
package com.xhpc.evcs.notification;
import com.xhpc.evcs.domain.AuthSecretToken;
import com.xhpc.evcs.domain.EtOrderMapping;
import com.xhpc.evcs.domain.XhpcChargingStation;
import com.xhpc.evcs.domain.XhpcStatisticsTimeInterval;
import com.xhpc.evcs.domain.*;
import com.xhpc.evcs.dto.CDChargeOrder4BonusInfoRes;
import com.xhpc.evcs.dto.CDChargeOrderInfo4BonusReq;
import com.xhpc.evcs.dto.CommonRequest;
@ -12,6 +9,7 @@ import com.xhpc.evcs.jpa.*;
import com.xhpc.evcs.utils.DateUtil;
import com.xhpc.evcs.utils.JSONUtil;
import com.xhpc.order.domain.XhpcHistoryOrder;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -25,11 +23,14 @@ import java.util.List;
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;
@Component
@Slf4j
public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
@Autowired
private XhpcHistoryOrderRepository xhpcHistoryOrderRepository;
@Autowired
private EtPushFailedOrderRepository etPushFailedOrderRepository;
@Autowired
private AuthSecretTokenRepository authSecretTokenRepository;
@Autowired
private StatisticTimeIntervalRepository statisticTimeIntervalRepository;
@ -37,7 +38,7 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
private OrderMappingRepository orderMappingRepository;
@Autowired
private XhpcChargingStationRepository chargingStationRepo;
private Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfo4BonusTask.class);
private final Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfo4BonusTask.class);
@Scheduled(fixedDelay = 1000 * 60)
public void run() throws IOException {
@ -53,12 +54,23 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
List<XhpcStatisticsTimeInterval> statisticTimeIntervalList =
statisticTimeIntervalRepository.findByHistoryOrderId(xhpcHistoryOrder.getHistoryOrderId());
xhpcHistoryOrder.setXhpcStatisticsTimeIntervalList(statisticTimeIntervalList);
notify(xhpcHistoryOrder, authSecretTokenOut);
notify(xhpcHistoryOrder, authSecretTokenOut, false);
}
final List<XhpcHistoryOrder> pushFailedOrders =
xhpcHistoryOrderRepository.findJoinPushFailedOrders(authSecretTokenOut.getOperatorId3irdpty());
for (XhpcHistoryOrder xhpcHistoryOrder : pushFailedOrders) {
List<XhpcStatisticsTimeInterval> statisticTimeIntervalList =
statisticTimeIntervalRepository.findByHistoryOrderId(xhpcHistoryOrder.getHistoryOrderId());
xhpcHistoryOrder.setXhpcStatisticsTimeIntervalList(statisticTimeIntervalList);
final boolean notify = notify(xhpcHistoryOrder, authSecretTokenOut, true);
if (notify) {
etPushFailedOrderRepository.deleteById(xhpcHistoryOrder.getHistoryOrderId());
}
}
}
}
public void notify(XhpcHistoryOrder xhpcHistoryOrder, AuthSecretToken authSecretTokenOut) throws IOException {
public boolean notify(XhpcHistoryOrder xhpcHistoryOrder, AuthSecretToken authSecretTokenOut, boolean isRepush) throws IOException {
String operatorIdEvcs = xhpcHistoryOrder.getOperatorIdEvcs();
if (operatorIdEvcs == null) {
@ -67,7 +79,7 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
String stationOperatorIdEvcs = station.getOperatorIdEvcs();
if (stationOperatorIdEvcs == null) {
logger.error("station[{}] operator id evcs not set", chargingStationId);
return;
return false;
}
operatorIdEvcs = stationOperatorIdEvcs.substring(8, 17);
}
@ -78,15 +90,26 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
String data = JSONUtil.toJSONString(cdChargeOrderInfo4BonusReq);
CommonRequest<CDChargeOrderInfo4BonusReq> commonRequest = new CommonRequest<>();
commonRequest.setData(data);
String responseBody = ok(commonRequest, "/notification_charge_order_info_for_bonus", authSecretTokenOut);
String responseBody = ok(commonRequest, "/notification_charge_order_info_for_bonus", authSecretTokenOut,
operatorIdEvcs);
CDChargeOrder4BonusInfoRes cdChargeOrder4BonusInfoRes = DTOJsonHelper.parseResponseData(responseBody,
CDChargeOrder4BonusInfoRes.class, authSecretTokenOut);
if (cdChargeOrder4BonusInfoRes != null && cdChargeOrder4BonusInfoRes.getConfirmResult() == 0) {
if (!isRepush) {
authSecretTokenOut.setLastPushOrder(xhpcHistoryOrder.getHistoryOrderId());
authSecretTokenRepository.save(authSecretTokenOut);
}
if (cdChargeOrder4BonusInfoRes != null && cdChargeOrder4BonusInfoRes.getConfirmResult() == 0) {
return true;
} else {
throw new RuntimeException(String.format("push CD notification order[%s] failed: %s",
xhpcHistoryOrder.getSerialNumber(), responseBody));
if (!isRepush) {
EtPushFailedOrder etPushFailedOrder = new EtPushFailedOrder();
etPushFailedOrder.setId(xhpcHistoryOrder.getHistoryOrderId());
etPushFailedOrder.setOperatorId3rdpty(authSecretTokenOut.getOperatorId3irdpty());
etPushFailedOrderRepository.save(etPushFailedOrder);
}
logger.error(String.format("push CD notification order[%s] failed: %s", xhpcHistoryOrder.getSerialNumber(),
responseBody));
return false;
}
}