拆分第三方业务代码

This commit is contained in:
YAS\29473
2025-08-09 16:13:29 +08:00
parent 6a0b56194e
commit 655f54300c
15 changed files with 2435 additions and 139 deletions

View File

@@ -4,29 +4,29 @@ import com.google.common.collect.Lists;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.service.thirdparty.ThirdPartyPlatformApi;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.spring.SpringUtils;
import com.jsowell.pile.dto.nanrui.PushAlarmInfoDTO;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.thirdparty.dubbo.factory.DynamicThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.apache.commons.collections4.CollectionUtils;
import org.bouncycastle.crypto.CryptoException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* 主动通知Service
* 说明:创建此接口目的是为了简化开发
* 在需要通知第三方平台的地方,异步调用此类中对应的方法
* 通知方法中应该根据对接平台,自动找到响应的平台处理逻辑
* 主动通知Service - 异步改造版
*/
@Service
public class NotificationService {
@@ -35,9 +35,43 @@ public class NotificationService {
@Autowired
private ThirdpartySecretInfoService thirdpartySecretInfoService;
// 引入线程池
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;
}
/**
* 充电站信息变化推送
* notification_stationInfo
*/
public String notificationStationInfo(NotificationDTO dto) {
String stationId = dto.getStationId();
@@ -46,33 +80,58 @@ public class NotificationService {
if (StringUtils.isBlank(stationId)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return null;
return "该站点未绑定任何平台";
}
// 调用相应平台的处理方法
StringBuilder result = new StringBuilder();
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
String currentPlatformType = secretInfoVO.getPlatformType();
if (StringUtils.isNotBlank(platformType) && !platformType.equals(currentPlatformType)) {
continue;
}
try {
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
String postResult = platformService.notificationStationInfo(stationId);
result.append(postResult).append("\n");
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);
}
} catch (Exception e) {
logger.error("平台类型:{}, 平台名称:{}, 站点id:{}, 充电站信息变化推送error:{}",
secretInfoVO.getPlatformType(), secretInfoVO.getPlatformName(), stationId, e.getMessage());
result.append("平台[").append(secretInfoVO.getPlatformName())
.append("]处理异常:").append(e.getMessage()).append("\n");
}
}
// 等待所有异步任务完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
return result.toString();
}
/**
* 设备状态变化推送
* notification_stationStatus
*/
public void notificationStationStatus(NotificationDTO dto) {
String stationId = dto.getStationId();
@@ -83,21 +142,35 @@ public class NotificationService {
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(pileConnectorCode) || StringUtils.isBlank(status)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationStationStatus(stationId, pileConnectorCode, status, secretInfoVO);
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);
}
} catch (Exception e) {
logger.error("平台类型:{}, 平台名称:{}, 站点id:{}, 枪口编号:{}, 设备状态变化推送error:{}",
secretInfoVO.getPlatformType(), secretInfoVO.getPlatformName(), stationId, pileConnectorCode, e.getMessage());
@@ -107,153 +180,178 @@ public class NotificationService {
/**
* 设备充电中状态变化推送
* notification_connector_charge_status
* notification_equip_charge_status
*/
public void notificationConnectorChargeStatus(NotificationDTO dto) {
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
try {
platformService.notificationConnectorChargeStatus(orderCode, secretInfoVO);
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);
}
} catch (Exception e) {
logger.error("平台类型:{}, 平台名称:{}, 站点id:{}, 订单编号:{}, 设备充电中状态变化推送error:{}",
secretInfoVO.getPlatformType(), secretInfoVO.getPlatformName(), stationId, orderCode, e.getMessage());
}
finally {
try {
platformService.notificationEquipChargeStatus(orderCode);
}catch (Exception e){
logger.error("notification_equip_charge_status error", e);
}
}
}
}
/**
* 充电订单信息推送
* notification_orderInfo/notification_charge_order_info
*/
public void notificationChargeOrderInfo(NotificationDTO dto) {
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
// 根据平台类型获取Service
ThirdPartyPlatformService platformService =null;
Object service = null;
try {
// 根据平台类型获取Service
platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
}catch (Exception e){
service = getPlatformService(secretInfoVO.getPlatformType());
} catch (Exception e) {
logger.error("获取平台服务失败", e);
continue;
}
//充电订单信息推送
com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO conversionVO = getConversion(secretInfoVO);
try {
if(platformService != null){
platformService.notificationChargeOrderInfo(orderCode, secretInfoVO);
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);
}
} catch (Exception e) {
logger.error("充电订单信息推送error", e);
logger.error("充电订单信息推送异常", e);
}
//订单信息推送
try {
if (platformService != null) {
platformService.notificationChargeOrderInfo(orderCode);
}
}catch (Exception e){
logger.error("订单信息推送error", e);
}
//停止充电结果推送
try {
if (platformService != null) {
platformService.notificationStopChargeResult(orderCode);
}
}catch (Exception e){
logger.error("停止充电结果推送error", e);
}
//推送充换电站用能统计信息
/* try {
if (platformService != null) {
platformService.notificationOperationStatsInfo(stationId);
}
}catch (Exception e){
logger.error("推送充换电站用能统计信息error", e);
}*/
//推送充电账单信息
try {
if (platformService != null) {
platformService.notificationPayOrderInfo(orderCode);
}
}catch (Exception e){
logger.error("推送充电账单信息error", e);
}
//推送充电历史订单信息
/* try {
// 根据平台类型获取Service
if (platformService != null) {
platformService.notificationChargeOrderInfoHistory(orderCode);
}
} catch (Exception e) {
logger.error("历史充电订单信息推送error", e);
}*/
}
}
/**
* 开始充电结果推送
*/
public void commonPushStartChargeResult(NotificationDTO dto) {
logger.info("开始调用commonPushStartChargeResult接口");
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationStartChargeResult(orderCode);
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);
}
} catch (Exception e) {
logger.error("充电订单信息推送error", e);
}
@@ -262,26 +360,38 @@ public class NotificationService {
/**
* 站点功率信息推送
* notification_orderInfo/notification_charge_order_info
*/
public void notificationStationPowerInfo(NotificationDTO dto) {
String stationId = dto.getStationId();
String platformType = dto.getPlatformType();
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationPowerInfo(Lists.newArrayList(stationId));
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);
}
} catch (Exception e) {
logger.error("站点功率信息推送error", e);
}
@@ -290,7 +400,6 @@ public class NotificationService {
/**
* 站点费率变化推送
* notification_stationFee
*/
public void notificationStationFee(NotificationDTO dto) {
String stationId = dto.getStationId();
@@ -299,21 +408,34 @@ public class NotificationService {
if (StringUtils.isBlank(stationId)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationStationFee(stationId, secretInfoVO);
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);
}
} catch (Exception e) {
logger.error("站点费率变化推送error", e);
}
@@ -322,74 +444,105 @@ public class NotificationService {
/**
* 历史充电订单信息推送
* notification_orderInfo/notification_charge_order_info
*/
public void notificationChargeOrderInfoHistory(NotificationDTO dto) {
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(stationId) || StringUtils.isBlank(orderCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
try {
platformService.notificationChargeOrderInfo(orderCode);
} catch (Exception e) {
logger.error("历史充电订单信息推送 error", e);
}
try {
platformService.notificationChargeOrderInfoHistory(orderCode);
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) {
logger.error("历史充电订单信息推送error", e);
logger.error("历史充电订单信息推送 error", e);
}
}
}
/**
* 充电设备告警信息推送
* notification_alarmInfo
* @param dto
*/
public void notificationAlarmInfo(NotificationDTO dto) {
String stationId = dto.getStationId();
String pileConnectorCode = dto.getPileConnectorCode();
String status = dto.getStatus();
String platformType = dto.getPlatformType();
if (StringUtils.isBlank(status) || StringUtils.isBlank(pileConnectorCode)) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
if (StringUtils.isNotBlank(platformType) && !StringUtils.equals(platformType, secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
Object service = getPlatformService(secretInfoVO.getPlatformType());
PushAlarmInfoDTO pushAlarmInfoDTO = new PushAlarmInfoDTO();
pushAlarmInfoDTO.setPileConnectorCode(pileConnectorCode);
pushAlarmInfoDTO.setConnectorStatus(status);
platformService.notificationAlarmInfo(pushAlarmInfoDTO);
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);
}

View File

@@ -0,0 +1,109 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.dto.RealTimeMonitorData;
import com.jsowell.common.service.thirdparty.domin.OrderBasicInfo;
import com.jsowell.common.service.thirdparty.domin.OrderDetail;
import com.jsowell.common.service.thirdparty.dto.*;
import com.jsowell.common.service.thirdparty.tempservice.OrderBasicInfoApi;
import com.jsowell.common.service.thirdparty.vo.*;
import com.jsowell.pile.service.OrderBasicInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@DubboService(group = "thirdparty" , version = "1.0.0")
public class OrderBasicInfoApiImpl implements OrderBasicInfoApi {
@Autowired
private OrderBasicInfoService orderBasicInfoService;
/**
* 转换实体类
* @param orderBasicInfo
* @return
*/
public OrderBasicInfo getOrderBasicInfoVO(com.jsowell.pile.domain.OrderBasicInfo orderBasicInfo){
OrderBasicInfo orderBasicInfoVO = new OrderBasicInfo();
BeanUtils.copyProperties(orderBasicInfo, orderBasicInfoVO);
return orderBasicInfoVO;
}
@Override
public OrderBasicInfo getOrderInfoByOrderCode(String orderCode) {
com.jsowell.pile.domain.OrderBasicInfo orderInfoByOrderCode = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
return getOrderBasicInfoVO(orderInfoByOrderCode);
}
@Override
public OrderBasicInfo queryChargingByPileConnectorCode(String pileConnectorCode) {
com.jsowell.pile.domain.OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(pileConnectorCode);
return getOrderBasicInfoVO(orderBasicInfo);
}
@Override
public OrderDetail getOrderDetailByOrderCode(String orderCode) {
com.jsowell.pile.domain.OrderDetail orderDetailByOrderCode = orderBasicInfoService.getOrderDetailByOrderCode(orderCode);
if (orderDetailByOrderCode == null) {
return null;
}
OrderDetail orderDetail = new OrderDetail();
BeanUtils.copyProperties(orderDetailByOrderCode, orderDetail);
return orderDetail;
}
@Override
public List<RealTimeMonitorData> getChargingRealTimeData(String transactionCode) {
List<com.jsowell.common.core.domain.ykc.RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(transactionCode);
List<RealTimeMonitorData> result = new ArrayList<>();
chargingRealTimeData.forEach(realTimeMonitorData -> {
RealTimeMonitorData monitorData = new RealTimeMonitorData();
BeanUtils.copyProperties(realTimeMonitorData, monitorData);
result.add(monitorData);
});
return result;
}
@Override
public List<AccumulativeInfoVO> getAccumulativeInfoForLianLian(QueryStationInfoDTO dto) {
com.jsowell.pile.dto.QueryStationInfoDTO queryStationInfoDTO = new com.jsowell.pile.dto.QueryStationInfoDTO();
BeanUtils.copyProperties(dto, queryStationInfoDTO);
List<com.jsowell.pile.vo.lianlian.AccumulativeInfoVO> accumulativeInfoForLianLian = orderBasicInfoService.getAccumulativeInfoForLianLian(queryStationInfoDTO);
List<AccumulativeInfoVO> result = new ArrayList<>();
accumulativeInfoForLianLian.forEach(accumulativeInfoVO -> {
AccumulativeInfoVO info = new AccumulativeInfoVO();
BeanUtils.copyProperties(accumulativeInfoVO, info);
result.add(info);
});
return result;
}
@Override
public Map<String, Object> generateOrderForThirdParty(QueryStartChargeDTO dto) {
com.jsowell.pile.dto.QueryStartChargeDTO queryStartChargeDTO = new com.jsowell.pile.dto.QueryStartChargeDTO();
BeanUtils.copyProperties(dto, queryStartChargeDTO);
return orderBasicInfoService.generateOrderForThirdParty(queryStartChargeDTO);
}
@Override
public List<String> tempGetOrderCodes(QueryOrder2DTO dto) {
com.jsowell.pile.dto.QueryOrderDTO queryOrderDTO = new com.jsowell.pile.dto.QueryOrderDTO();
BeanUtils.copyProperties(dto, queryOrderDTO);
return orderBasicInfoService.tempGetOrderCodes(queryOrderDTO);
}
}

View File

@@ -0,0 +1,89 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.domin.PileBasicInfo;
import com.jsowell.common.service.thirdparty.tempservice.PileBasicInfoApi;
import com.jsowell.common.service.thirdparty.vo.PileConnectorDetailVO;
import com.jsowell.common.service.thirdparty.vo.PileDetailInfoVO;
import com.jsowell.common.vo.PileInfoVO;
import com.jsowell.pile.service.PileBasicInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@DubboService(group = "thirdparty" , version = "1.0.0")
public class PileBasicInfoApiImpl implements PileBasicInfoApi {
@Autowired
private PileBasicInfoService pileBasicInfoService;
@Override
public PileBasicInfo selectPileBasicInfoBySN(String pileSn) {
com.jsowell.pile.domain.PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
if (pileBasicInfo == null) {
return null;
}
PileBasicInfo result = new PileBasicInfo();
BeanUtils.copyProperties(pileBasicInfo, result);
return result;
}
@Override
public PileInfoVO selectPileInfoBySn(String pileSn) {
com.jsowell.pile.vo.base.PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn);
if (pileInfoVO == null) {
return null;
}
PileInfoVO result = new PileInfoVO();
BeanUtils.copyProperties(pileInfoVO, result);
return result;
}
@Override
public PileConnectorDetailVO queryPileConnectorDetail(String pileConnectorCode) {
com.jsowell.pile.vo.uniapp.customer.PileConnectorDetailVO pileConnectorDetailVO = pileBasicInfoService.queryPileConnectorDetail(pileConnectorCode);
if (pileConnectorDetailVO == null) {
return null;
}
PileConnectorDetailVO result = new PileConnectorDetailVO();
BeanUtils.copyProperties(pileConnectorDetailVO, result);
return result;
}
@Override
public List<PileDetailInfoVO> getPileDetailInfoList(String stationId) {
List<com.jsowell.pile.thirdparty.PileDetailInfoVO> pileDetailInfoList = pileBasicInfoService.getPileDetailInfoList(stationId);
if (pileDetailInfoList == null || pileDetailInfoList.isEmpty()) {
return Collections.emptyList();
}
List<PileDetailInfoVO> result = new ArrayList<>();
for (com.jsowell.pile.thirdparty.PileDetailInfoVO pileDetailInfoVO : pileDetailInfoList) {
PileDetailInfoVO info = new PileDetailInfoVO();
BeanUtils.copyProperties(pileDetailInfoVO, info);
result.add(info);
}
return result;
}
@Override
public List<PileBasicInfo> getPileListByStationId(String stationId) {
List<com.jsowell.pile.domain.PileBasicInfo> pileListByStationId = pileBasicInfoService.getPileListByStationId(stationId);
List<PileBasicInfo> result = new ArrayList<>();
for (com.jsowell.pile.domain.PileBasicInfo basicInfo : pileListByStationId) {
PileBasicInfo pileBasicInfo = new PileBasicInfo();
BeanUtils.copyProperties(basicInfo, pileBasicInfo);
result.add(pileBasicInfo);
}
return result;
}
}

View File

@@ -0,0 +1,47 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.tempservice.PileBillingTemplateApi;
import com.jsowell.common.service.thirdparty.vo.BillingPriceVO;
import com.jsowell.common.vo.BillingTemplateVO;
import com.jsowell.pile.service.PileBillingTemplateService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@DubboService(group = "thirdparty",version = "1.0.0")
public class PileBillingTemplateApiImpl implements PileBillingTemplateApi {
@Autowired
private PileBillingTemplateService pileBillingTemplateService;
@Override
public List<BillingPriceVO> queryBillingPrice(String stationId) {
List<com.jsowell.pile.vo.uniapp.customer.BillingPriceVO> billingPriceVOS = pileBillingTemplateService.queryBillingPrice(stationId);
if (billingPriceVOS == null || billingPriceVOS.isEmpty()){
return Collections.emptyList();
}
List<BillingPriceVO> billingPriceVOList = new ArrayList<>();
for (com.jsowell.pile.vo.uniapp.customer.BillingPriceVO billingPriceVO : billingPriceVOS){
BillingPriceVO vo = new BillingPriceVO();
BeanUtils.copyProperties(billingPriceVO,vo);
}
return billingPriceVOList;
}
@Override
public BillingTemplateVO selectBillingTemplateDetailByPileSn(String pileSn) {
com.jsowell.pile.vo.web.BillingTemplateVO billingTemplateVO = pileBillingTemplateService.selectBillingTemplateDetailByPileSn(pileSn);
if (billingTemplateVO == null){
return null;
}
BillingTemplateVO vo = new BillingTemplateVO();
BeanUtils.copyProperties(billingTemplateVO,vo);
return vo;
}
}

View File

@@ -0,0 +1,74 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.domin.PileConnectorInfo;
import com.jsowell.common.service.thirdparty.tempservice.PileConnectorInfoApi;
import com.jsowell.common.service.thirdparty.vo.ConnectorInfoVO;
import com.jsowell.common.service.thirdparty.vo.PileConnectorInfoVO;
import com.jsowell.pile.service.PileConnectorInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@DubboService(group = "thirdparty" , version = "1.0.0")
public class PileConnectorInfoApiImpl implements PileConnectorInfoApi {
@Autowired
private PileConnectorInfoService pileConnectorInfoService;
@Override
public List<PileConnectorInfo> selectPileConnectorInfoList(String pileSn) {
List<com.jsowell.pile.domain.PileConnectorInfo> pileConnectorInfos = pileConnectorInfoService.selectPileConnectorInfoList(pileSn);
if (pileConnectorInfos == null || pileConnectorInfos.isEmpty()) {
return Collections.emptyList();
}
List<PileConnectorInfo> result = new ArrayList<>();
for (com.jsowell.pile.domain.PileConnectorInfo info : pileConnectorInfos) {
PileConnectorInfo resultInfo = new PileConnectorInfo();
BeanUtils.copyProperties(info, resultInfo);
result.add(resultInfo);
}
return result;
}
@Override
public PileConnectorInfoVO getPileConnectorInfoByConnectorCode(String connectorCode) {
com.jsowell.pile.vo.web.PileConnectorInfoVO info = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(connectorCode);
if (info == null) {
return null;
}
PileConnectorInfoVO resultInfo = new PileConnectorInfoVO();
BeanUtils.copyProperties(info, resultInfo);
return resultInfo;
}
@Override
public List<ConnectorInfoVO> batchSelectConnectorList(List<String> stationIds) {
return Collections.emptyList();
}
@Override
public List<ConnectorInfoVO> getConnectorListForLianLian(Long stationId) {
List<com.jsowell.pile.vo.base.ConnectorInfoVO> connectorListForLianLian = pileConnectorInfoService.getConnectorListForLianLian(stationId);
if (connectorListForLianLian == null || connectorListForLianLian.isEmpty()) {
return Collections.emptyList();
}
List<ConnectorInfoVO> result = new ArrayList<>();
for (com.jsowell.pile.vo.base.ConnectorInfoVO info : connectorListForLianLian) {
ConnectorInfoVO resultInfo = new ConnectorInfoVO();
BeanUtils.copyProperties(info, resultInfo);
result.add(resultInfo);
}
return result;
}
}

View File

@@ -0,0 +1,27 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.tempservice.PileMerchantInfoApi;
import com.jsowell.common.service.thirdparty.vo.MerchantInfoVO;
import com.jsowell.pile.service.PileMerchantInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@DubboService(group = "thirdparty", version = "1.0.0")
public class PileMerchantInfoApiImpl implements PileMerchantInfoApi {
@Autowired
private PileMerchantInfoService pileMerchantInfoService;
@Override
public MerchantInfoVO getMerchantInfoVO(String merchantId) {
com.jsowell.pile.vo.base.MerchantInfoVO merchantInfoVO = pileMerchantInfoService.getMerchantInfoVO(merchantId);
if (merchantInfoVO == null) {
return null;
}
MerchantInfoVO vo = new MerchantInfoVO();
BeanUtils.copyProperties(merchantInfoVO, vo);
return vo;
}
}

View File

@@ -0,0 +1,30 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.tempservice.PileModelInfoApi;
import com.jsowell.common.service.thirdparty.vo.PileModelInfoVO;
import com.jsowell.pile.service.PileModelInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@DubboService(group = "thirdparty", version = "1.0.0")
public class PileModelInfoApiImpl implements PileModelInfoApi {
@Autowired
private PileModelInfoService pileModelInfoService;
@Override
public PileModelInfoVO getPileModelInfoByPileSn(String pileSn) {
com.jsowell.pile.vo.web.PileModelInfoVO pileModelInfoByPileSn = pileModelInfoService.getPileModelInfoByPileSn(pileSn);
if (pileModelInfoByPileSn == null) {
return null;
}
PileModelInfoVO pileModelInfoVO = new PileModelInfoVO();
BeanUtils.copyProperties(pileModelInfoByPileSn, pileModelInfoVO);
return pileModelInfoVO;
}
}

View File

@@ -0,0 +1,20 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.tempservice.PileRemoteApi;
import com.jsowell.pile.service.PileRemoteService;
import org.apache.dubbo.config.annotation.DubboService;
import javax.annotation.Resource;
@DubboService(group = "thirdparty", version = "1.0.0")
public class PileRemoteApiImpl implements PileRemoteApi {
@Resource
private PileRemoteService pileRemoteService;
@Override
public void remoteStopCharging(String pileSn , String connectorCode , String transactionCode) {
pileRemoteService.remoteStopCharging(pileSn, connectorCode, transactionCode);
}
}

View File

@@ -0,0 +1,54 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.domin.PileStationInfo;
import com.jsowell.common.service.thirdparty.dto.QueryStationInfoDTO;
import com.jsowell.common.service.thirdparty.tempservice.PileStationInfoApi;
import com.jsowell.common.service.thirdparty.vo.ThirdPartyStationInfoVO;
import com.jsowell.pile.service.PileStationInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@DubboService(group = "thirdparty", version = "1.0.0")
public class PileStationInfoApiImpl implements PileStationInfoApi {
@Autowired
private PileStationInfoService pileStationInfoService;
@Override
public PileStationInfo selectPileStationInfoById(Long id) {
com.jsowell.pile.domain.PileStationInfo pileStationInfo = pileStationInfoService.selectPileStationInfoById(id);
if (pileStationInfo == null) {
return null;
}
PileStationInfo result = new PileStationInfo();
BeanUtils.copyProperties(pileStationInfo, result);
return result;
}
@Override
public List<ThirdPartyStationInfoVO> selectStationInfosByThirdParty(QueryStationInfoDTO dto) {
com.jsowell.pile.dto.QueryStationInfoDTO dto1 = new com.jsowell.pile.dto.QueryStationInfoDTO();
BeanUtils.copyProperties(dto, dto1);
List<com.jsowell.pile.vo.base.ThirdPartyStationInfoVO> thirdPartyStationInfoVOS = pileStationInfoService.selectStationInfosByThirdParty(dto1);
if (thirdPartyStationInfoVOS == null) {
return Collections.emptyList();
}
List<ThirdPartyStationInfoVO> result = new ArrayList<>();
for (com.jsowell.pile.vo.base.ThirdPartyStationInfoVO stationInfo : thirdPartyStationInfoVOS) {
ThirdPartyStationInfoVO thirdPartyStationInfoVO = new ThirdPartyStationInfoVO();
BeanUtils.copyProperties(stationInfo, thirdPartyStationInfoVO);
result.add(thirdPartyStationInfoVO);
}
return result;
}
}

View File

@@ -0,0 +1,71 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.tempservice.ThirdpartySecretInfoApi;
import com.jsowell.common.service.thirdparty.vo.StationInfoVO;
import com.jsowell.common.service.thirdparty.vo.ThirdPartySecretInfoVO;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@DubboService(group = "thirdparty", version = "1.0.0")
public class ThirdpartySecretInfoApiImpl implements ThirdpartySecretInfoApi {
@Autowired
public ThirdpartySecretInfoService thirdpartySecretInfoService;
/**
* 通过组织结构代码,查询平台密钥配置信息
* @param theirOperatorId 组织结构代码
* @return
*/
@Override
public ThirdPartySecretInfoVO queryByOperatorId(String theirOperatorId) {
com.jsowell.pile.vo.ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(theirOperatorId);
if (thirdPartySecretInfoVO == null){
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO1 = new ThirdPartySecretInfoVO();
BeanUtils.copyProperties(thirdPartySecretInfoVO, thirdPartySecretInfoVO1);
return thirdPartySecretInfoVO1;
}
/**
* 通过第三方平台类型,查询平台密钥配置信息
* @param thirdPlatformType 第三方平台类型, 参见{@link com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum}
* @return
*/
@Override
public ThirdPartySecretInfoVO queryByThirdPlatformType(String thirdPlatformType) {
com.jsowell.pile.vo.ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(thirdPlatformType);
if (thirdPartySecretInfoVO == null){
return null;
}
ThirdPartySecretInfoVO thirdPartySecretInfoVO1 = new ThirdPartySecretInfoVO();
BeanUtils.copyProperties(thirdPartySecretInfoVO, thirdPartySecretInfoVO1);
return thirdPartySecretInfoVO1;
}
/**
* 根据第三方平台类型查询对接第三方平台的站点列表
* @param thirdPlatformType
* @return
*/
@Override
public List<StationInfoVO> selectStationList(String thirdPlatformType) {
List<com.jsowell.pile.vo.base.StationInfoVO> stationInfoVOS = thirdpartySecretInfoService.selectStationList(thirdPlatformType);
if (stationInfoVOS == null || stationInfoVOS.isEmpty()){
return null;
}
List<StationInfoVO> stationInfoVOList = new java.util.ArrayList<>();
for (com.jsowell.pile.vo.base.StationInfoVO stationInfoVO : stationInfoVOS){
StationInfoVO stationInfoVO1 = new StationInfoVO();
BeanUtils.copyProperties(stationInfoVO, stationInfoVO1);
stationInfoVOList.add(stationInfoVO1);
}
return stationInfoVOList;
}
}

View File

@@ -0,0 +1,22 @@
package com.jsowell.thirdparty.dubbo.api.impl;
import com.jsowell.common.service.thirdparty.domin.ykcCommond.StartChargingCommand;
import com.jsowell.common.service.thirdparty.tempservice.YKCPushCommandApi;
import com.jsowell.pile.service.YKCPushCommandService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@DubboService(group = "thirdparty" ,version = "1.0.0")
public class YKCPushCommandApiImpl implements YKCPushCommandApi {
@Autowired
private YKCPushCommandService ykcpushCommandService;
@Override
public void pushStartChargingCommand(StartChargingCommand startChargingCommand) {
com.jsowell.pile.domain.ykcCommond.StartChargingCommand command = new com.jsowell.pile.domain.ykcCommond.StartChargingCommand();
BeanUtils.copyProperties(startChargingCommand, command);
ykcpushCommandService.pushStartChargingCommand(command);
}
}

View File

@@ -0,0 +1,88 @@
package com.jsowell.thirdparty.dubbo.factory;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.service.thirdparty.ThirdPartyPlatformApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.springframework.stereotype.Component;
import java.util.concurrent.ConcurrentHashMap;
/**
* 动态服务工厂
*/
@Component
@Slf4j
public class DynamicThirdPartyPlatformFactory {
// 缓存已获取的服务代理
private static final ConcurrentHashMap<String, ThirdPartyPlatformApi> serviceCache = new ConcurrentHashMap<>();
/**
* 根据平台类型动态获取远程服务
* @param platformType 平台类型(需与远程服务的@DubboService(group)一致)
* @return 远程服务代理
*/
public static ThirdPartyPlatformApi getPlatformService(String platformType) {
if (platformType == null || platformType.isEmpty()) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
// 1. 先从缓存获取
ThirdPartyPlatformApi service = serviceCache.get(platformType);
if (service != null) {
return service;
}
// 2. 动态创建服务引用
synchronized (DynamicThirdPartyPlatformFactory.class) {
service = serviceCache.get(platformType);
if (service != null) {
return service;
}
try {
// 创建ReferenceConfig实例
// 要与jsowell-charge-thirdparty的远程服务的@DubboService配置一致
ReferenceConfig<ThirdPartyPlatformApi> referenceConfig = new ReferenceConfig<>();
referenceConfig.setInterface(ThirdPartyPlatformApi.class);
referenceConfig.setGroup(platformType);
referenceConfig.setVersion("1.0.0");
referenceConfig.setTimeout(10000); // 设置超时时间为10秒,默认为1秒
referenceConfig.setRetries(2); //失败重试次数为2
// referenceConfig.setAsync(true); //异步调用
// 根据特定的配置,在nacos中寻找jsowell-charge-thirdparty注册的服务
// 使用DubboBootstrap注册并获取服务
DubboBootstrap
.getInstance() // 获取DubboBootstrap实例
.reference( // 引用服务配置
referenceConfig,
DubboBootstrap
.getInstance()
.getApplicationModel()
.getDefaultModule());
// 获取服务代理
service = referenceConfig.get();
serviceCache.put(platformType, service);
log.info("缓存中有的缓存有: "+ serviceCache.toString());
return service;
} catch (Exception e) {
throw new BusinessException(ReturnCodeEnum.valueOf("获取平台[" + platformType + "]的服务失败: " + e.getMessage()));
}
}
}
/**
* 清理缓存
*/
public static void clearCache() {
serviceCache.clear();
}
}