Accomplishing the notification_charge_order_info.
This commit is contained in:
parent
79d8df30df
commit
81c7d71484
@ -80,6 +80,10 @@ public class ChargeOrderInfo {
|
||||
// this.connectorID = xhpcHistoryOrder.getTerminalId()
|
||||
}
|
||||
|
||||
public ChargeOrderInfo() {
|
||||
|
||||
}
|
||||
|
||||
@JsonProperty("StartChargeSeq")
|
||||
public String getStartChargeSeq() {
|
||||
|
||||
@ -229,5 +233,4 @@ public class ChargeOrderInfo {
|
||||
"stopReason", stopReason).append("sumPeriod", sumPeriod).append("additionalProperties",
|
||||
additionalProperties).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package com.xhpc.evcs.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @Author HongYun on 2021/11/2
|
||||
*/
|
||||
@JsonPropertyOrder({
|
||||
"StartChargeSeq",
|
||||
"ConnectorID",
|
||||
"ConfirmResult"
|
||||
})
|
||||
@Setter
|
||||
@Getter
|
||||
public class ChargeOrderInfoResponse {
|
||||
|
||||
@JsonProperty("StartChargeSeq")
|
||||
private String startChargeSeq;
|
||||
|
||||
@JsonProperty("ConnectorID")
|
||||
private String connectorID;
|
||||
|
||||
@JsonProperty("ConfirmResult")
|
||||
private Integer confirmResult;
|
||||
}
|
||||
@ -77,6 +77,8 @@ public class QueryStartChargeController {
|
||||
pushOrder.put("startTime", etOrderData.get("startTime"));
|
||||
//0 means needs to be notified.
|
||||
pushOrder.put("startChargeNotificationStat", 0);
|
||||
//0 means needs to be notified.
|
||||
pushOrder.put("chargeOrderInfoNotificationStat", 0);
|
||||
REDIS.setCacheMap("pushOrder:".concat(orderNo), pushOrder);
|
||||
}
|
||||
resp.setRet(String.valueOf(res.getCode()));
|
||||
|
||||
@ -0,0 +1,152 @@
|
||||
package com.xhpc.evcs.notification;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.xhpc.evcs.domain.AuthSecretToken;
|
||||
import com.xhpc.evcs.dto.ChargeOrderInfo;
|
||||
import com.xhpc.evcs.dto.ChargeOrderInfoResponse;
|
||||
import com.xhpc.evcs.dto.CommonRequest;
|
||||
import com.xhpc.evcs.dto.DTOJsonHelper;
|
||||
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||
import com.xhpc.evcs.jpa.XhpcHistoryOrderRepository;
|
||||
import com.xhpc.evcs.utils.JSONUtil;
|
||||
import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||
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.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
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/1
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class NotificationChargeOrderInfoTask extends CoreDispatcher {
|
||||
|
||||
@Autowired
|
||||
private XhpcHistoryOrderRepository xhpcHistoryOrderRepository;
|
||||
@Autowired
|
||||
private AuthSecretTokenRepository authSecretTokenRepository;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfoTask.class);
|
||||
|
||||
@Scheduled(fixedRate = 1000 * 60)
|
||||
public void run() throws IOException {
|
||||
|
||||
//Getting the internetSerialNumbers to load the requestData.
|
||||
Collection<String> pushOrders = REDIS.keys("pushOrder:*");
|
||||
// System.out.println(pushOrderKeys);
|
||||
// List<String> pushOrders = (List<String>) REDIS.keys("pushOrder:*");
|
||||
List<String> internetSerialNumbers = new ArrayList<>();
|
||||
List<String> connectorIdMap = new ArrayList<>();
|
||||
List<String> orderNos = new ArrayList<>();
|
||||
for (String pushOrder : pushOrders) {
|
||||
Integer chargeOrderInfoNotificationStat = REDIS.getCacheMapValue(pushOrder, "chargeOrderInfoNotificationStat");
|
||||
|
||||
if (0 == chargeOrderInfoNotificationStat) {
|
||||
internetSerialNumbers.add(REDIS.getCacheMapValue(pushOrder, "internetSerialNumber"));
|
||||
connectorIdMap.add(REDIS.getCacheMapValue(pushOrder, "connectorID"));
|
||||
orderNos.add(pushOrder);
|
||||
}
|
||||
}
|
||||
|
||||
//Ensuring that the connectorId is following the handling of the data, which named interSerialNumber.
|
||||
int times = 0;
|
||||
//Loading the requestData, and also notifying.
|
||||
for (String internetSerialNumber : internetSerialNumbers) {
|
||||
String connector = connectorIdMap.get(times);
|
||||
String orderNo = orderNos.get(times);
|
||||
++times;
|
||||
String operatorId = internetSerialNumber.substring(0, 9);
|
||||
AuthSecretToken authSecretToken = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, SECRET_TOKEN_TYPE_OUT).orElse(null);
|
||||
if (null != authSecretToken) {
|
||||
XhpcHistoryOrder xhpcHistoryOrder = xhpcHistoryOrderRepository.findByInternetSerialNumber(internetSerialNumber).orElse(null);
|
||||
if (null != xhpcHistoryOrder) {
|
||||
ChargeOrderInfo chargeOrderInfo = new ChargeOrderInfo();
|
||||
if (null != xhpcHistoryOrder.getInternetSerialNumber()) {
|
||||
chargeOrderInfo.setStartChargeSeq(xhpcHistoryOrder.getInternetSerialNumber());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
//The connector is absolutely exists.
|
||||
chargeOrderInfo.setConnectorID(connector);
|
||||
|
||||
Date startTime = xhpcHistoryOrder.getStartTime();
|
||||
if (null == startTime) {
|
||||
continue;
|
||||
}
|
||||
String formatStartTime = DateUtil.format(startTime, "yyyy-MM-dd HH: mm: ss");
|
||||
chargeOrderInfo.setStartTime(formatStartTime);
|
||||
|
||||
Date endTime = xhpcHistoryOrder.getEndTime();
|
||||
if (null == endTime) continue;
|
||||
String formatEndTime = DateUtil.format(endTime, "yyyy-MM-dd HH: mm: ss");
|
||||
chargeOrderInfo.setEndTime(formatEndTime);
|
||||
|
||||
if (null != xhpcHistoryOrder.getTotalPower()) {
|
||||
chargeOrderInfo.setTotalPower(xhpcHistoryOrder.getTotalPower());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null != xhpcHistoryOrder.getActPowerPrice()) {
|
||||
chargeOrderInfo.setTotalElecMoney(xhpcHistoryOrder.getActPowerPrice().doubleValue());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null != xhpcHistoryOrder.getServicePriceTotal()) {
|
||||
chargeOrderInfo.setTotalSeviceMoney(xhpcHistoryOrder.getServicePriceTotal().doubleValue());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null != xhpcHistoryOrder.getTotalPrice()) {
|
||||
chargeOrderInfo.setTotalMoney(xhpcHistoryOrder.getTotalPrice().doubleValue());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null != xhpcHistoryOrder.getStopReasonEvcs()) {
|
||||
chargeOrderInfo.setStopReason(xhpcHistoryOrder.getStopReasonEvcs());
|
||||
}
|
||||
notify(chargeOrderInfo, authSecretToken, orderNo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void notify(ChargeOrderInfo chargeOrderInfo, AuthSecretToken authSecretTokenOut, String orderNo) throws JsonProcessingException {
|
||||
|
||||
String operatorIdEvcs = "MA6DFCTD5";
|
||||
String data = JSONUtil.toJSONString(chargeOrderInfo);
|
||||
logger.debug(data);
|
||||
CommonRequest<ChargeOrderInfo> commonRequest = new CommonRequest<>();
|
||||
commonRequest.setOperatorId(operatorIdEvcs);
|
||||
commonRequest.setData(data);
|
||||
String responseBody = ok(commonRequest, "/notification_charge_order_info", authSecretTokenOut, operatorIdEvcs);
|
||||
ChargeOrderInfoResponse chargeOrderInfoResponse = DTOJsonHelper.parseResponseData(responseBody,
|
||||
ChargeOrderInfoResponse.class, authSecretTokenOut);
|
||||
if (null != chargeOrderInfoResponse) {
|
||||
Integer succStat = chargeOrderInfoResponse.getConfirmResult();
|
||||
//O means that the response is not success.
|
||||
if (succStat == 0) {
|
||||
REDIS.setCacheMapValue(orderNo, "chargeOrderInfoNotificationStat", -1);
|
||||
} else {
|
||||
throw new RuntimeException(String.format("push CD start order status [%s] failed: %s",
|
||||
chargeOrderInfoResponse.getStartChargeSeq(), responseBody));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user