监管方推送失败问题解决O(∩_∩)O
This commit is contained in:
parent
38402762ea
commit
41c9749de9
@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@ -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> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ package com.xhpc.evcs.jpa;
|
|||||||
import com.xhpc.order.domain.XhpcHistoryOrder;
|
import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@ -18,4 +19,8 @@ public interface XhpcHistoryOrderRepository extends JpaRepository<XhpcHistoryOrd
|
|||||||
|
|
||||||
List<XhpcHistoryOrder> findByConfirmResultNotAndSource(int confirmResult, int source);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,6 +46,12 @@ public class CoreDispatcher {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public String ok(Object object, String url, AuthSecretToken authSecretTokenOut) {
|
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) {
|
if (authSecretTokenOut == null) {
|
||||||
log.error("authSecretTokenOut is null");
|
log.error("authSecretTokenOut is null");
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
@ -65,7 +71,11 @@ public class CoreDispatcher {
|
|||||||
try {
|
try {
|
||||||
if (object.getClass().getSimpleName().equals("CommonRequest")) {
|
if (object.getClass().getSimpleName().equals("CommonRequest")) {
|
||||||
CommonRequest commonRequest = (CommonRequest) object;
|
CommonRequest commonRequest = (CommonRequest) object;
|
||||||
commonRequest.setOperatorId(authSecretTokenOut.getOperatorId());
|
if (stationOperatorId != null) {
|
||||||
|
commonRequest.setOperatorId(stationOperatorId);
|
||||||
|
} else {
|
||||||
|
commonRequest.setOperatorId(authSecretTokenOut.getOperatorId());
|
||||||
|
}
|
||||||
Date tokenExpiry = authSecretTokenOut.getTokenExpiry();
|
Date tokenExpiry = authSecretTokenOut.getTokenExpiry();
|
||||||
String originalData = commonRequest.getData();
|
String originalData = commonRequest.getData();
|
||||||
String tData;
|
String tData;
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
package com.xhpc.evcs.notification;
|
package com.xhpc.evcs.notification;
|
||||||
|
|
||||||
import com.xhpc.evcs.domain.AuthSecretToken;
|
import com.xhpc.evcs.domain.*;
|
||||||
import com.xhpc.evcs.domain.EtOrderMapping;
|
|
||||||
import com.xhpc.evcs.domain.XhpcChargingStation;
|
|
||||||
import com.xhpc.evcs.domain.XhpcStatisticsTimeInterval;
|
|
||||||
import com.xhpc.evcs.dto.CDChargeOrder4BonusInfoRes;
|
import com.xhpc.evcs.dto.CDChargeOrder4BonusInfoRes;
|
||||||
import com.xhpc.evcs.dto.CDChargeOrderInfo4BonusReq;
|
import com.xhpc.evcs.dto.CDChargeOrderInfo4BonusReq;
|
||||||
import com.xhpc.evcs.dto.CommonRequest;
|
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.DateUtil;
|
||||||
import com.xhpc.evcs.utils.JSONUtil;
|
import com.xhpc.evcs.utils.JSONUtil;
|
||||||
import com.xhpc.order.domain.XhpcHistoryOrder;
|
import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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;
|
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
|
public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private XhpcHistoryOrderRepository xhpcHistoryOrderRepository;
|
private XhpcHistoryOrderRepository xhpcHistoryOrderRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private EtPushFailedOrderRepository etPushFailedOrderRepository;
|
||||||
|
@Autowired
|
||||||
private AuthSecretTokenRepository authSecretTokenRepository;
|
private AuthSecretTokenRepository authSecretTokenRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private StatisticTimeIntervalRepository statisticTimeIntervalRepository;
|
private StatisticTimeIntervalRepository statisticTimeIntervalRepository;
|
||||||
@ -37,7 +38,7 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
|
|||||||
private OrderMappingRepository orderMappingRepository;
|
private OrderMappingRepository orderMappingRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private XhpcChargingStationRepository chargingStationRepo;
|
private XhpcChargingStationRepository chargingStationRepo;
|
||||||
private Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfo4BonusTask.class);
|
private final Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfo4BonusTask.class);
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 1000 * 60)
|
@Scheduled(fixedDelay = 1000 * 60)
|
||||||
public void run() throws IOException {
|
public void run() throws IOException {
|
||||||
@ -53,12 +54,23 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
|
|||||||
List<XhpcStatisticsTimeInterval> statisticTimeIntervalList =
|
List<XhpcStatisticsTimeInterval> statisticTimeIntervalList =
|
||||||
statisticTimeIntervalRepository.findByHistoryOrderId(xhpcHistoryOrder.getHistoryOrderId());
|
statisticTimeIntervalRepository.findByHistoryOrderId(xhpcHistoryOrder.getHistoryOrderId());
|
||||||
xhpcHistoryOrder.setXhpcStatisticsTimeIntervalList(statisticTimeIntervalList);
|
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();
|
String operatorIdEvcs = xhpcHistoryOrder.getOperatorIdEvcs();
|
||||||
if (operatorIdEvcs == null) {
|
if (operatorIdEvcs == null) {
|
||||||
@ -67,7 +79,7 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
|
|||||||
String stationOperatorIdEvcs = station.getOperatorIdEvcs();
|
String stationOperatorIdEvcs = station.getOperatorIdEvcs();
|
||||||
if (stationOperatorIdEvcs == null) {
|
if (stationOperatorIdEvcs == null) {
|
||||||
logger.error("station[{}] operator id evcs not set", chargingStationId);
|
logger.error("station[{}] operator id evcs not set", chargingStationId);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
operatorIdEvcs = stationOperatorIdEvcs.substring(8, 17);
|
operatorIdEvcs = stationOperatorIdEvcs.substring(8, 17);
|
||||||
}
|
}
|
||||||
@ -78,15 +90,26 @@ public class NotificationChargeOrderInfo4BonusTask extends CoreDispatcher {
|
|||||||
String data = JSONUtil.toJSONString(cdChargeOrderInfo4BonusReq);
|
String data = JSONUtil.toJSONString(cdChargeOrderInfo4BonusReq);
|
||||||
CommonRequest<CDChargeOrderInfo4BonusReq> commonRequest = new CommonRequest<>();
|
CommonRequest<CDChargeOrderInfo4BonusReq> commonRequest = new CommonRequest<>();
|
||||||
commonRequest.setData(data);
|
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 cdChargeOrder4BonusInfoRes = DTOJsonHelper.parseResponseData(responseBody,
|
||||||
CDChargeOrder4BonusInfoRes.class, authSecretTokenOut);
|
CDChargeOrder4BonusInfoRes.class, authSecretTokenOut);
|
||||||
if (cdChargeOrder4BonusInfoRes != null && cdChargeOrder4BonusInfoRes.getConfirmResult() == 0) {
|
if (!isRepush) {
|
||||||
authSecretTokenOut.setLastPushOrder(xhpcHistoryOrder.getHistoryOrderId());
|
authSecretTokenOut.setLastPushOrder(xhpcHistoryOrder.getHistoryOrderId());
|
||||||
authSecretTokenRepository.save(authSecretTokenOut);
|
authSecretTokenRepository.save(authSecretTokenOut);
|
||||||
|
}
|
||||||
|
if (cdChargeOrder4BonusInfoRes != null && cdChargeOrder4BonusInfoRes.getConfirmResult() == 0) {
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(String.format("push CD notification order[%s] failed: %s",
|
if (!isRepush) {
|
||||||
xhpcHistoryOrder.getSerialNumber(), responseBody));
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user