WIP:三方对接,小桔AD
This commit is contained in:
parent
1dc3b8c598
commit
465d2be266
@ -13,7 +13,7 @@ public class XhpcStationInternetBlacklist extends BaseEntity {
|
||||
private Long id;
|
||||
|
||||
@Column(name = "internet_user_id")
|
||||
private String internetUserId;
|
||||
private Long internetUserId;
|
||||
|
||||
@Column(name = "charging_station_id")
|
||||
private Long chargingStationId;
|
||||
@ -30,23 +30,27 @@ public class XhpcStationInternetBlacklist extends BaseEntity {
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getInternetUserId() {
|
||||
|
||||
public String getInternetUserId() {
|
||||
return internetUserId;
|
||||
}
|
||||
|
||||
public void setInternetUserId(String internetUserId) {
|
||||
public void setInternetUserId(Long internetUserId) {
|
||||
|
||||
this.internetUserId = internetUserId;
|
||||
}
|
||||
|
||||
public Long getChargingStationId() {
|
||||
|
||||
return chargingStationId;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.xhpc.evcs.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.xhpc.common.core.utils.DateUtils;
|
||||
import com.xhpc.evcs.domain.XhpcStatisticsTimeInterval;
|
||||
import com.xhpc.evcs.utils.DateUtil;
|
||||
import com.xhpc.order.domain.XhpcHistoryOrder;
|
||||
@ -13,6 +14,8 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Transient;
|
||||
import java.util.*;
|
||||
|
||||
import static com.xhpc.common.core.utils.DateUtils.YYYY_MM_DD_HH_MM_SS;
|
||||
|
||||
//@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonPropertyOrder({
|
||||
"StartChargeSeq",
|
||||
@ -82,7 +85,7 @@ public class ChargeOrderInfo {
|
||||
|
||||
this.connectorID = xhpcHistoryOrder.getSerialNumber().substring(0, 16);
|
||||
this.startChargeSeq = xhpcHistoryOrder.getInternetSerialNumber();
|
||||
this.endTime = DateUtil.date2StringDt(xhpcHistoryOrder.getEndTime());
|
||||
this.endTime = DateUtils.parseDateToStr(YYYY_MM_DD_HH_MM_SS, xhpcHistoryOrder.getEndTime());
|
||||
this.connectorID = xhpcHistoryOrder.getSerialNumber().substring(0, 16);
|
||||
this.endTime = DateUtil.date2String(xhpcHistoryOrder.getEndTime(), DateUtil.DATE_FORMAT_DATE_TIME);
|
||||
this.startTime = DateUtil.date2String(xhpcHistoryOrder.getStartTime(), DateUtil.DATE_FORMAT_DATE_TIME);
|
||||
|
||||
@ -61,7 +61,8 @@ public class Aes128Cbc {
|
||||
NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchPaddingException,
|
||||
InvalidKeyException {
|
||||
|
||||
System.out.println(decryptString("Fa09StzEtf3Qfmr/b91gfg==", "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"
|
||||
System.out.println(decryptString("L+FOSPaN073SDRBNMqKBAQ==",
|
||||
"ojs67l46z3f7rhok", "tet9swfkyojkhaos"
|
||||
));
|
||||
//ujNoGsWRo5MyPKYOxeofKwgPEng3xF+yhM8DDjwtwHo=
|
||||
System.out.println(encrypt("{\"StationIDs\":[\"1\"]}", "8LpncubmWiPCzY3V", "av6A8QdnRaVRMXu6"));
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
package com.xhpc.evcs.api;
|
||||
|
||||
import com.xhpc.evcs.domain.XhpcInternetUser;
|
||||
import com.xhpc.evcs.domain.XhpcStationInternetBlacklist;
|
||||
import com.xhpc.evcs.dto.CommonRequest;
|
||||
import com.xhpc.evcs.dto.CommonResponse;
|
||||
import com.xhpc.evcs.dto.EquipAuthRequest;
|
||||
import com.xhpc.evcs.dto.EquipAuthResponse;
|
||||
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
|
||||
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
|
||||
import com.xhpc.evcs.utils.JSONUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -12,6 +14,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||
@ -27,6 +31,8 @@ public class QueryEquipAuthController {
|
||||
|
||||
@Autowired
|
||||
private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo;
|
||||
@Autowired
|
||||
private XhpcInternetUserRepository xhpcInternetUserRepository;
|
||||
|
||||
@PostMapping(value = "/v1/query_equip_auth")
|
||||
public CommonResponse queryEquipAuth(@RequestBody CommonRequest<EquipAuthRequest> commonRequest) throws Exception {
|
||||
@ -41,7 +47,17 @@ public class QueryEquipAuthController {
|
||||
String pileId = connectorId.substring(0, connectorId.length() - 2);
|
||||
Map<String, Object> pileDataModel = REDIS.getCacheMap("pile:" + pileId);
|
||||
Long stationId = Long.parseLong(pileDataModel.get("stationId").toString());
|
||||
XhpcStationInternetBlacklist xhpcStationInternetBlacklist = xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(stationId, equipAuthSeq.substring(0, 10)).orElse(null);
|
||||
List<XhpcInternetUser> xhpcInternetUserList =
|
||||
xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant.now(),
|
||||
Instant.now(), equipAuthSeq.substring(0, 9));
|
||||
if (xhpcInternetUserList.isEmpty()) {
|
||||
equipAuthResponse.setSuccStat(1);
|
||||
equipAuthResponse.setFailReason(2);
|
||||
resp.setMsg("auth denied");
|
||||
} else {
|
||||
Long internetUserId = xhpcInternetUserList.get(0).getId();
|
||||
XhpcStationInternetBlacklist xhpcStationInternetBlacklist =
|
||||
xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(stationId, internetUserId).orElse(null);
|
||||
resp.setRet("0");
|
||||
if (null != xhpcStationInternetBlacklist) {
|
||||
equipAuthResponse.setSuccStat(1);
|
||||
@ -68,6 +84,7 @@ public class QueryEquipAuthController {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
resp.setData(JSONUtil.toJSONString(equipAuthResponse));
|
||||
return resp;
|
||||
}
|
||||
|
||||
@ -68,6 +68,7 @@ public class QueryEquipChargeStatusController {
|
||||
equipChargeStatus.setStartChargeSeqStat(startChargeSeqStat);
|
||||
//充电设备接口编码
|
||||
String connectorId = internalOrderNum.substring(0, 16);
|
||||
equipChargeStatus.setConnectorID(connectorId);
|
||||
//充电设备接口状态
|
||||
Map<String, Object> cacheGunData = REDIS.getCacheMap("gun:" + connectorId);
|
||||
String gunStatus = (String) cacheGunData.get("status");
|
||||
|
||||
@ -70,7 +70,7 @@ public class QueryStartChargeController {
|
||||
Map<String, Object> etOrderData = (Map<String, Object>) res.getData();
|
||||
EtOrderMapping etOrderMapping = new EtOrderMapping();
|
||||
etOrderMapping.setEvcsOrderNo(startChargeSeq);
|
||||
etOrderMapping.setXhOrderNo("123123");//String.valueOf(etOrderData.get("orderNo")));
|
||||
etOrderMapping.setXhOrderNo(String.valueOf(etOrderData.get("orderNo")));
|
||||
etOrderMappingRepo.save(etOrderMapping);
|
||||
startChargeResponse.setStartChargeSeqStat(1);
|
||||
startChargeResponse.setSuccStat(0);
|
||||
|
||||
@ -7,6 +7,7 @@ import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface XhpcInternetUserRepository extends JpaRepository<XhpcInternetUser, Long>,
|
||||
@ -16,4 +17,10 @@ public interface XhpcInternetUserRepository extends JpaRepository<XhpcInternetUs
|
||||
Instant now, Instant now2);
|
||||
|
||||
|
||||
List<XhpcInternetUser> findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant now, Instant now1);
|
||||
|
||||
List<XhpcInternetUser> findByCooperationStartTimeBeforeAndCooperationEndTimeAfterAndOperatorIdEvcsLike(Instant now,
|
||||
Instant now1,
|
||||
String operatorIdEvcs);
|
||||
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ public interface XhpcStationInternetBlacklistRepository extends JpaRepository<Xh
|
||||
QueryByExampleExecutor<XhpcStationInternetBlacklist>, JpaSpecificationExecutor<XhpcStationInternetBlacklist> {
|
||||
|
||||
|
||||
Optional<XhpcStationInternetBlacklist> findByChargingStationIdAndInternetUserId(Long stationId, String substring);
|
||||
Optional<XhpcStationInternetBlacklist> findByChargingStationIdAndInternetUserId(Long stationId, Long internetUserId);
|
||||
|
||||
List<XhpcStationInternetBlacklist> findByInternetUserId(String substring);
|
||||
|
||||
|
||||
@ -9,7 +9,6 @@ import com.xhpc.evcs.dto.DTOJsonHelper;
|
||||
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||
import com.xhpc.evcs.utils.JSONUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -30,7 +29,7 @@ public class NotificationCancelOrderTask extends CoreDispatcher {
|
||||
|
||||
//private Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfoTask.class);
|
||||
|
||||
@Scheduled(fixedRate = 1000 * 15)
|
||||
// @Scheduled(fixedRate = 1000 * 15)
|
||||
public void run() throws JsonProcessingException {
|
||||
|
||||
//Getting the orders, which need to be notified.
|
||||
|
||||
@ -18,6 +18,8 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;
|
||||
|
||||
/**
|
||||
* @Author HongYun on 2021/11/1
|
||||
*/
|
||||
@ -34,18 +36,22 @@ public class NotificationChargeOrderInfoTask extends CoreDispatcher {
|
||||
@Scheduled(fixedRate = 1000 * 15)
|
||||
public void run() throws JsonProcessingException {
|
||||
|
||||
List<AuthSecretToken> authSecretTokenList = authSecretTokenRepository.findAll();
|
||||
List<AuthSecretToken> authSecretTokenList = authSecretTokenRepository.findBySecretTokenType(SECRET_TOKEN_TYPE_OUT);
|
||||
List<XhpcHistoryOrder> xhpcHistoryOrderList =
|
||||
xhpcHistoryOrderRepository.findByConfirmResultNotAndOperatorId3rdptyEvcsIsNotNull(0);
|
||||
for (XhpcHistoryOrder horder : xhpcHistoryOrderList) {
|
||||
|
||||
for (AuthSecretToken authSecretToken : authSecretTokenList) {
|
||||
if (authSecretToken.getOperatorId3irdpty().equals(horder.getOperatorId3rdptyEvcs())) {
|
||||
String operatorId3rdptyEvcs = horder.getOperatorId3rdptyEvcs();
|
||||
if (operatorId3rdptyEvcs == null) {
|
||||
if (horder.getInternetSerialNumber() != null) operatorId3rdptyEvcs =
|
||||
horder.getInternetSerialNumber().substring(0, 9);
|
||||
}
|
||||
if (authSecretToken.getOperatorId3irdpty().equals(operatorId3rdptyEvcs)) {
|
||||
ChargeOrderInfo chargeOrderInfo = new ChargeOrderInfo(horder);
|
||||
final ChargeOrderInfoResponse pushResp = notify(chargeOrderInfo, authSecretToken);
|
||||
horder.setConfirmResult(pushResp.getConfirmResult());
|
||||
logger.info("3rd part order {} push result: {}", horder.getSerialNumber(), pushResp.getConfirmResult());
|
||||
// xhpcHistoryOrderRepository.save(horder);
|
||||
xhpcHistoryOrderRepository.save(horder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,48 +2,65 @@ package com.xhpc.evcs.notification;
|
||||
|
||||
import com.xhpc.common.api.dto.ChargingStationDto;
|
||||
import com.xhpc.evcs.domain.AuthSecretToken;
|
||||
import com.xhpc.evcs.domain.XhpcInternetUser;
|
||||
import com.xhpc.evcs.domain.XhpcStationInternetBlacklist;
|
||||
import com.xhpc.evcs.dto.*;
|
||||
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||
import com.xhpc.evcs.jpa.XhpcInternetUserRepository;
|
||||
import com.xhpc.evcs.jpa.XhpcStationInternetBlacklistRepository;
|
||||
import com.xhpc.evcs.utils.ChangePoleStatus;
|
||||
import com.xhpc.evcs.utils.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS;
|
||||
import static com.xhpc.evcs.domain.AuthSecretToken.SECRET_TOKEN_TYPE_OUT;
|
||||
import static com.xhpc.evcs.dto.ConnectorStatusInfo.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class NotificationStationStatusTask extends CoreDispatcher {
|
||||
|
||||
@Autowired
|
||||
private AuthSecretTokenRepository authSecretTokenRepository;
|
||||
@Autowired
|
||||
private XhpcInternetUserRepository xhpcInternetUserRepository;
|
||||
@Autowired
|
||||
private XhpcStationInternetBlacklistRepository xhpcStationInternetBlacklistRepo;
|
||||
|
||||
@Scheduled(fixedRate = 1000 * 15)
|
||||
@Scheduled(fixedRate = 1000 * 45)
|
||||
protected void run() throws IOException {
|
||||
|
||||
Collection<String> stationTerminalKeys = REDIS.keys("stationTerminalStatus:*");
|
||||
|
||||
List<XhpcInternetUser> xhpcInternetUserList =
|
||||
xhpcInternetUserRepository.findByCooperationStartTimeBeforeAndCooperationEndTimeAfter(Instant.now(),
|
||||
Instant.now());
|
||||
for (String stationTerminalKey : stationTerminalKeys) {
|
||||
ChargingStationDto chargingStationDto = REDIS.getCacheObject(stationTerminalKey.replace("stationTerminalStatus",
|
||||
"station")); //todo OperatorID
|
||||
"station"));
|
||||
String operatorId = chargingStationDto.getOperatorId();
|
||||
operatorId = operatorId == null ? "MA6DFCTD5" : operatorId;
|
||||
AuthSecretToken authSecretTokenOut =
|
||||
authSecretTokenRepository.findByOperatorId3irdptyAndOperatorIdAndSecretTokenType(
|
||||
"765367656", operatorId, SECRET_TOKEN_TYPE_OUT).orElse(null); //todo
|
||||
// maybe对接第三方
|
||||
if (authSecretTokenOut != null) {
|
||||
Map<String, String> terminalStatusMap = REDIS.getCacheMap(stationTerminalKey);
|
||||
Set<ConnectorStatusInfo> connectorStatusInfos = translateStatus(operatorId, terminalStatusMap);
|
||||
if (!connectorStatusInfos.isEmpty()) {
|
||||
Set<ConnectorStatusInfo> changeStatus = ChangePoleStatus.getChangeStatus(connectorStatusInfos);
|
||||
if (!connectorStatusInfos.isEmpty()) {
|
||||
for (XhpcInternetUser xhpcInternetUser : xhpcInternetUserList) {
|
||||
XhpcStationInternetBlacklist xhpcStationInternetBlacklist =
|
||||
xhpcStationInternetBlacklistRepo.findByChargingStationIdAndInternetUserId(chargingStationDto.getStationId(), xhpcInternetUser.getId()).orElse(null);
|
||||
if (xhpcStationInternetBlacklist != null) continue;
|
||||
String operatorId3rdptyEvcs = xhpcInternetUser.getOperatorIdEvcs();
|
||||
operatorId3rdptyEvcs = operatorId3rdptyEvcs.length() == 9 ? operatorId3rdptyEvcs :
|
||||
operatorId3rdptyEvcs.substring(9, 19);
|
||||
AuthSecretToken authSecretTokenOut =
|
||||
authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(xhpcInternetUser.getOperatorIdEvcs(), SECRET_TOKEN_TYPE_OUT).orElse(null);
|
||||
operatorId = !operatorId3rdptyEvcs.equals("765367656") ? "MA6DFCTD5" : operatorId;
|
||||
if (authSecretTokenOut != null) {
|
||||
for (ConnectorStatusInfo statusInfo : changeStatus) {
|
||||
notify(statusInfo, authSecretTokenOut);
|
||||
}
|
||||
@ -51,6 +68,7 @@ public class NotificationStationStatusTask extends CoreDispatcher {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Set<ConnectorStatusInfo> translateStatus(String operatorId, Map<String, String> terminalStatusMap) {
|
||||
|
||||
@ -92,7 +110,7 @@ public class NotificationStationStatusTask extends CoreDispatcher {
|
||||
connectorStatusInfo.getOperatorID());
|
||||
EvcsStatus status = DTOJsonHelper.parseResponseData(responseBody, EvcsStatus.class, authSecretTokenOut);
|
||||
if (status == null || status.getStatus() != 0) {
|
||||
throw new RuntimeException(String.format("push CD notification connector[%s] failed: %s",
|
||||
log.error(String.format("push CD notification connector[%s] failed: %s",
|
||||
connectorStatusInfo.getConnectorID(), responseBody));
|
||||
}
|
||||
return status;
|
||||
|
||||
@ -5,6 +5,7 @@ import com.xhpc.evcs.domain.AuthSecretToken;
|
||||
import com.xhpc.evcs.dto.ChargeResultRequest;
|
||||
import com.xhpc.evcs.dto.ChargeResultResponse;
|
||||
import com.xhpc.evcs.dto.CommonRequest;
|
||||
import com.xhpc.evcs.dto.DTOJsonHelper;
|
||||
import com.xhpc.evcs.jpa.AuthSecretTokenRepository;
|
||||
import com.xhpc.evcs.utils.JSONUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -86,7 +87,8 @@ public class NotificationStopChargeResultTask extends CoreDispatcher {
|
||||
chargeResultRequestCommonRequest.setData(jsonData);
|
||||
String result = ok(chargeResultRequestCommonRequest, "/notification_stop_charge_result",
|
||||
authSecretTokenOut, operatorId3rdpty);
|
||||
ChargeResultResponse chargeResultResponse = JSONUtil.readParams(result, ChargeResultResponse.class);
|
||||
ChargeResultResponse chargeResultResponse = DTOJsonHelper.parseResponseData(result,
|
||||
ChargeResultResponse.class, authSecretTokenOut);
|
||||
succStat = chargeResultResponse.getSuccStat();
|
||||
//推送成功则排除这个已推送的订单,否则则继续推送该订单 // 用于测试暂时注释
|
||||
if (succStat == 0) {
|
||||
|
||||
@ -363,6 +363,7 @@ public class XhpcPileOrderController extends BaseController {
|
||||
}else{
|
||||
Map<String, Object> pushOrder = redisService.getCacheMap("pushOrder:"+orderNo);
|
||||
xhpcHistoryOrder.setInternetSerialNumber(pushOrder.get("internetSerialNumber").toString());
|
||||
xhpcChargeOrder.setOperatorId3rdptyEvcs((String) pushOrder.get("operatorId3rdpty"));
|
||||
}
|
||||
|
||||
//结算
|
||||
|
||||
@ -262,7 +262,7 @@ public class ChargingController {
|
||||
cacheOrder.put("tel", startChargingData.getTel());
|
||||
cacheOrder.put("stopSoc", startChargingData.getSoc());
|
||||
cacheOrder.put("startTime",
|
||||
DateTimeFormatter.ofPattern("yyyyMMdd HH:mm:ss").withZone(ZoneId.systemDefault()).format(Instant.now()));
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()).format(Instant.now()));
|
||||
REDIS.setCacheMap(orderkey, cacheOrder);
|
||||
return R.ok("充电指令已下发");
|
||||
} catch (IOException e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user