Files
jsowell-charger-web/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/NotificationService.java

552 lines
24 KiB
Java
Raw Normal View History

2024-04-20 15:55:35 +08:00
package com.jsowell.thirdparty.common;
2024-08-15 15:31:43 +08:00
import com.google.common.collect.Lists;
2025-05-23 16:26:54 +08:00
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
2024-04-26 16:08:53 +08:00
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
2025-08-09 16:13:29 +08:00
import com.jsowell.common.service.thirdparty.ThirdPartyPlatformApi;
2024-04-22 11:10:17 +08:00
import com.jsowell.common.util.StringUtils;
2025-08-09 16:13:29 +08:00
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO;
2024-04-20 15:55:35 +08:00
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
2025-08-09 16:13:29 +08:00
import com.jsowell.thirdparty.dubbo.factory.DynamicThirdPartyPlatformFactory;
2024-05-10 15:46:01 +08:00
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
2024-04-20 15:55:35 +08:00
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.apache.commons.collections4.CollectionUtils;
2024-04-20 17:18:21 +08:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2025-08-09 16:13:29 +08:00
import org.springframework.beans.BeanUtils;
2024-04-20 15:55:35 +08:00
import org.springframework.beans.factory.annotation.Autowired;
2025-08-09 16:13:29 +08:00
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
2024-04-20 15:55:35 +08:00
import org.springframework.stereotype.Service;
2025-08-09 16:13:29 +08:00
import java.util.ArrayList;
2024-04-20 15:55:35 +08:00
import java.util.List;
2025-08-09 16:13:29 +08:00
import java.util.concurrent.CompletableFuture;
2024-04-20 15:55:35 +08:00
/**
2025-08-09 16:13:29 +08:00
* 主动通知Service - 异步改造版
2024-04-20 15:55:35 +08:00
*/
@Service
public class NotificationService {
2024-04-20 17:18:21 +08:00
private final Logger logger = LoggerFactory.getLogger(this.getClass());
2024-04-20 15:55:35 +08:00
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
2025-08-09 16:13:29 +08:00
// 引入线程池
private ThreadPoolTaskExecutor executor = SpringUtils.getBean("threadPoolTaskExecutor");
// 判断是否使用old还是new平台
private boolean isRemotePlatform(String platformType) {
for (ThirdPlatformTypeEnum item : ThirdPlatformTypeEnum.values()) {
if (StringUtils.equals(item.getTypeCode(), platformType)) {
return true; // true: 使用old平台
}
}
return false; // false: 使用new平台
}
/**
* 根据平台类型获取对应的服务实例
*/
private Object getPlatformService(String platformType) {
if (isRemotePlatform(platformType)) {
return ThirdPartyPlatformFactory.getInvokeStrategy(platformType);
} else {
return DynamicThirdPartyPlatformFactory.getPlatformService(platformType);
}
}
/**
* VO对象转换
*/
private com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO getConversion(ThirdPartySecretInfoVO secretInfoVO) {
com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO conversion =
new com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO();
BeanUtils.copyProperties(secretInfoVO, conversion);
return conversion;
}
2024-04-20 15:55:35 +08:00
/**
* 充电站信息变化推送
*/
public String notificationStationInfo(NotificationDTO dto) {
2024-05-10 17:15:47 +08:00
String stationId = dto.getStationId();
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(stationId)) {
2024-04-26 16:08:53 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
2024-04-20 15:55:35 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
2025-08-09 16:13:29 +08:00
return "该站点未绑定任何平台";
2024-04-20 15:55:35 +08:00
}
2025-08-09 16:13:29 +08:00
StringBuilder result = new StringBuilder();
2025-08-09 16:13:29 +08:00
List<CompletableFuture<Void>> futures = new ArrayList<>();
2024-04-20 15:55:35 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2025-08-09 16:13:29 +08:00
String currentPlatformType = secretInfoVO.getPlatformType();
if (StringUtils.isNotBlank(platformType) && !platformType.equals(currentPlatformType)) {
2024-04-22 11:10:17 +08:00
continue;
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(currentPlatformType);
if (service instanceof ThirdPartyPlatformService) {
String pushResult = ((ThirdPartyPlatformService) service).notificationStationInfo(stationId);
result.append("old平台[").append(secretInfoVO.getPlatformName())
.append("]推送结果:").append(pushResult).append("\n");
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> {
try {
return apiService.notificationStationInfo(stationId);
} catch (Exception e) {
return "推送失败:" + e.getMessage();
}
}, executor).thenAccept(pushResult -> {
synchronized (result) {
result.append("new平台[").append(secretInfoVO.getPlatformName())
.append("]推送结果:").append(pushResult).append("\n");
}
});
futures.add(future);
}
2024-04-20 17:18:21 +08:00
} catch (Exception e) {
2025-08-09 16:13:29 +08:00
result.append("平台[").append(secretInfoVO.getPlatformName())
.append("]处理异常:").append(e.getMessage()).append("\n");
2024-04-20 17:18:21 +08:00
}
2024-04-20 15:55:35 +08:00
}
2025-08-09 16:13:29 +08:00
// 等待所有异步任务完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
return result.toString();
2024-04-20 15:55:35 +08:00
}
/**
* 设备状态变化推送
*/
2024-04-22 11:10:17 +08:00
public void notificationStationStatus(NotificationDTO dto) {
String stationId = dto.getStationId();
String pileConnectorCode = dto.getPileConnectorCode();
String status = dto.getStatus();
2024-05-10 17:15:47 +08:00
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(pileConnectorCode) || StringUtils.isBlank(status)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
2024-04-20 15:55:35 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
2024-04-20 15:55:35 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-05-10 17:15:47 +08:00
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
2024-04-22 11:10:17 +08:00
continue;
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(secretInfoVO.getPlatformType());
com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO conversionVO = getConversion(secretInfoVO);
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationStationStatus(
stationId, pileConnectorCode, status, secretInfoVO);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationStationStatus(stationId, pileConnectorCode, status, conversionVO);
} catch (Exception e) {
logger.error("new平台[{}]设备状态推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
}
2024-04-20 17:18:21 +08:00
} catch (Exception e) {
2024-11-28 10:57:23 +08:00
logger.error("平台类型:{}, 平台名称:{}, 站点id:{}, 枪口编号:{}, 设备状态变化推送error:{}",
secretInfoVO.getPlatformType(), secretInfoVO.getPlatformName(), stationId, pileConnectorCode, e.getMessage());
2024-04-20 17:18:21 +08:00
}
2024-04-20 15:55:35 +08:00
}
}
/**
* 设备充电中状态变化推送
*/
2024-04-22 11:10:17 +08:00
public void notificationConnectorChargeStatus(NotificationDTO dto) {
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
2024-05-10 17:15:47 +08:00
String platformType = dto.getPlatformType();
2025-08-09 16:13:29 +08:00
2024-05-10 17:15:47 +08:00
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-05-10 17:15:47 +08:00
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
2024-04-22 11:10:17 +08:00
continue;
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(secretInfoVO.getPlatformType());
com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO conversionVO = getConversion(secretInfoVO);
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationConnectorChargeStatus(orderCode, secretInfoVO);
((ThirdPartyPlatformService) service).notificationEquipChargeStatus(orderCode);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationConnectorChargeStatus(orderCode, conversionVO);
} catch (Exception e) {
logger.error("new平台[{}]充电中状态推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
CompletableFuture.runAsync(() -> {
try {
apiService.notificationEquipChargeStatus(orderCode);
} catch (Exception e) {
logger.error("new平台[{}]设备充电状态推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
}
2024-04-20 17:18:21 +08:00
} catch (Exception e) {
2024-11-28 10:57:23 +08:00
logger.error("平台类型:{}, 平台名称:{}, 站点id:{}, 订单编号:{}, 设备充电中状态变化推送error:{}",
secretInfoVO.getPlatformType(), secretInfoVO.getPlatformName(), stationId, orderCode, e.getMessage());
2024-04-20 17:18:21 +08:00
}
}
2024-04-20 15:55:35 +08:00
}
/**
2024-04-20 17:18:21 +08:00
* 充电订单信息推送
2024-04-20 15:55:35 +08:00
*/
2024-04-22 11:10:17 +08:00
public void notificationChargeOrderInfo(NotificationDTO dto) {
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
2024-05-10 17:15:47 +08:00
String platformType = dto.getPlatformType();
2025-08-09 16:13:29 +08:00
2024-05-10 17:15:47 +08:00
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-05-10 17:15:47 +08:00
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
2024-04-22 11:10:17 +08:00
continue;
}
2025-08-09 16:13:29 +08:00
Object service = null;
2024-04-20 17:18:21 +08:00
try {
2025-08-09 16:13:29 +08:00
service = getPlatformService(secretInfoVO.getPlatformType());
} catch (Exception e) {
2025-06-30 14:11:06 +08:00
logger.error("获取平台服务失败", e);
2025-08-09 16:13:29 +08:00
continue;
2025-06-30 14:11:06 +08:00
}
2025-08-09 16:13:29 +08:00
com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO conversionVO = getConversion(secretInfoVO);
2025-06-30 14:11:06 +08:00
try {
2025-08-09 16:13:29 +08:00
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationChargeOrderInfo(orderCode, secretInfoVO);
((ThirdPartyPlatformService) service).notificationChargeOrderInfo(orderCode);
((ThirdPartyPlatformService) service).notificationStopChargeResult(orderCode);
((ThirdPartyPlatformService) service).notificationPayOrderInfo(orderCode);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationChargeOrderInfo(orderCode, conversionVO);
} catch (Exception e) {
logger.error("new平台[{}]充电订单信息推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
CompletableFuture.runAsync(() -> {
try {
apiService.notificationChargeOrderInfo(orderCode);
} catch (Exception e) {
logger.error("new平台[{}]订单信息推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
CompletableFuture.runAsync(() -> {
try {
apiService.notificationStopChargeResult(orderCode);
} catch (Exception e) {
logger.error("new平台[{}]停止充电结果推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
CompletableFuture.runAsync(() -> {
try {
apiService.notificationPayOrderInfo(orderCode);
} catch (Exception e) {
logger.error("new平台[{}]充电账单推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
2025-06-30 13:47:42 +08:00
}
2025-06-30 14:11:06 +08:00
} catch (Exception e) {
2025-08-09 16:13:29 +08:00
logger.error("充电订单信息推送异常", e);
2025-06-30 14:11:06 +08:00
}
2024-04-20 17:18:21 +08:00
}
2024-04-20 15:55:35 +08:00
}
2025-08-09 16:13:29 +08:00
/**
* 开始充电结果推送
*/
2025-05-21 17:12:42 +08:00
public void commonPushStartChargeResult(NotificationDTO dto) {
2025-05-21 17:47:44 +08:00
logger.info("开始调用commonPushStartChargeResult接口");
2025-05-21 17:12:42 +08:00
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
String platformType = dto.getPlatformType();
2025-08-09 16:13:29 +08:00
2025-05-21 17:12:42 +08:00
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
2025-05-21 17:12:42 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
2025-05-21 17:12:42 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
continue;
}
2025-08-09 16:13:29 +08:00
2025-05-21 17:12:42 +08:00
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(secretInfoVO.getPlatformType());
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationStartChargeResult(orderCode);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationStartChargeResult(orderCode);
} catch (Exception e) {
logger.error("new平台[{}]开始充电结果推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
}
2025-05-21 17:12:42 +08:00
} catch (Exception e) {
logger.error("充电订单信息推送error", e);
}
}
}
2024-08-15 15:31:43 +08:00
/**
* 站点功率信息推送
*/
public void notificationStationPowerInfo(NotificationDTO dto) {
String stationId = dto.getStationId();
String platformType = dto.getPlatformType();
2025-08-09 16:13:29 +08:00
2024-08-15 15:31:43 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
2024-08-15 15:31:43 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
continue;
}
2025-08-09 16:13:29 +08:00
2024-08-15 15:31:43 +08:00
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(secretInfoVO.getPlatformType());
List<String> stationIds = Lists.newArrayList(stationId);
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationPowerInfo(stationIds);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationPowerInfo(stationIds);
} catch (Exception e) {
logger.error("new平台[{}]站点功率信息推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
}
2024-08-15 15:31:43 +08:00
} catch (Exception e) {
logger.error("站点功率信息推送error", e);
}
}
}
2024-04-20 15:55:35 +08:00
/**
* 站点费率变化推送
*/
2024-04-22 11:10:17 +08:00
public void notificationStationFee(NotificationDTO dto) {
2024-05-10 17:15:47 +08:00
String stationId = dto.getStationId();
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(stationId)) {
2024-04-26 16:08:53 +08:00
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-05-10 17:15:47 +08:00
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
2024-04-22 11:10:17 +08:00
continue;
}
2025-08-09 16:13:29 +08:00
2024-04-20 17:18:21 +08:00
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(secretInfoVO.getPlatformType());
com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO conversionVO = getConversion(secretInfoVO);
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationStationFee(stationId, secretInfoVO);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationStationFee(stationId, conversionVO);
} catch (Exception e) {
logger.error("new平台[{}]站点费率推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
}
2024-04-20 17:18:21 +08:00
} catch (Exception e) {
2024-05-10 17:15:47 +08:00
logger.error("站点费率变化推送error", e);
2024-04-20 17:18:21 +08:00
}
}
2024-04-20 15:55:35 +08:00
}
/**
* 历史充电订单信息推送
*/
public void notificationChargeOrderInfoHistory(NotificationDTO dto) {
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
String platformType = dto.getPlatformType();
2025-08-09 16:13:29 +08:00
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
continue;
}
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(secretInfoVO.getPlatformType());
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationChargeOrderInfo(orderCode);
((ThirdPartyPlatformService) service).notificationChargeOrderInfoHistory(orderCode);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationChargeOrderInfo(orderCode);
} catch (Exception e) {
logger.error("new平台[{}]历史订单信息推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
CompletableFuture.runAsync(() -> {
try {
apiService.notificationChargeOrderInfoHistory(orderCode);
} catch (Exception e) {
logger.error("new平台[{}]历史充电订单推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
}
} catch (Exception e) {
2025-08-09 16:13:29 +08:00
logger.error("历史充电订单信息推送 error", e);
}
}
}
/**
* 充电设备告警信息推送
*/
public void notificationAlarmInfo(NotificationDTO dto) {
String stationId = dto.getStationId();
String pileConnectorCode = dto.getPileConnectorCode();
String status = dto.getStatus();
String platformType = dto.getPlatformType();
2025-08-09 16:13:29 +08:00
if (StringUtils.isBlank(status) || StringUtils.isBlank(pileConnectorCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2025-08-09 16:13:29 +08:00
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
2025-08-09 16:13:29 +08:00
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
continue;
}
2025-08-09 16:13:29 +08:00
try {
2025-08-09 16:13:29 +08:00
Object service = getPlatformService(secretInfoVO.getPlatformType());
PushAlarmInfoDTO pushAlarmInfoDTO = new PushAlarmInfoDTO();
pushAlarmInfoDTO.setPileConnectorCode(pileConnectorCode);
pushAlarmInfoDTO.setConnectorStatus(status);
2025-08-09 16:13:29 +08:00
com.jsowell.common.service.thirdparty.dto.PushAlarmInfoDTO dtoConvert =
new com.jsowell.common.service.thirdparty.dto.PushAlarmInfoDTO();
BeanUtils.copyProperties(pushAlarmInfoDTO, dtoConvert);
if (service instanceof ThirdPartyPlatformService) {
((ThirdPartyPlatformService) service).notificationAlarmInfo(pushAlarmInfoDTO);
} else if (service instanceof ThirdPartyPlatformApi) {
// 后续新平台异步处理
ThirdPartyPlatformApi apiService = (ThirdPartyPlatformApi) service;
CompletableFuture.runAsync(() -> {
try {
apiService.notificationAlarmInfo(dtoConvert);
} catch (Exception e) {
logger.error("new平台[{}]设备告警信息推送失败", secretInfoVO.getPlatformName(), e);
}
}, executor);
}
} catch (Exception e) {
logger.error("充电设备告警信息推送error", e);
}
}
}
2024-04-20 15:55:35 +08:00
}