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

186 lines
8.7 KiB
Java
Raw Normal View History

2024-04-20 15:55:35 +08:00
package com.jsowell.thirdparty.common;
2024-04-26 16:08:53 +08:00
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
2024-04-22 11:10:17 +08:00
import com.jsowell.common.util.StringUtils;
2024-04-20 15:55:35 +08:00
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
import com.jsowell.thirdparty.platform.ThirdPartyPlatformService;
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;
2024-04-20 15:55:35 +08:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 主动通知Service
* 说明创建此接口目的是为了简化开发
* 在需要通知第三方平台的地方异步调用此类中对应的方法
* 通知方法中应该根据对接平台自动找到响应的平台处理逻辑
*/
@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;
/**
* 充电站信息变化推送
* notification_stationInfo
*/
2024-04-22 11:10:17 +08:00
public void notificationStationInfo(NotificationDTO dto) {
2024-04-26 16:08:53 +08:00
if (StringUtils.isBlank(dto.getStationId())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2024-04-22 11:10:17 +08:00
String stationId = dto.getStationId();
2024-04-20 15:55:35 +08:00
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-04-22 11:10:17 +08:00
if (StringUtils.isNotBlank(dto.getPlatformType()) && !StringUtils.equals(dto.getPlatformType(), secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
2024-04-20 17:18:21 +08:00
try {
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
// platformService.printServiceName();
platformService.notificationStationInfo(stationId);
} catch (Exception e) {
logger.error("充电站信息变化推送error", e);
}
2024-04-20 15:55:35 +08:00
}
}
/**
* 设备状态变化推送
* notification_stationStatus
*/
2024-04-22 11:10:17 +08:00
public void notificationStationStatus(NotificationDTO dto) {
2024-04-26 16:08:53 +08:00
if (StringUtils.isBlank(dto.getStationId()) || StringUtils.isBlank(dto.getPileConnectorCode()) || StringUtils.isBlank(dto.getStatus())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2024-04-22 11:10:17 +08:00
String stationId = dto.getStationId();
String pileConnectorCode = dto.getPileConnectorCode();
String status = dto.getStatus();
2024-04-20 15:55:35 +08:00
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-04-22 11:10:17 +08:00
if (StringUtils.isNotBlank(dto.getPlatformType()) && !StringUtils.equals(dto.getPlatformType(), secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
2024-04-20 17:18:21 +08:00
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationStationStatus(stationId, pileConnectorCode, status, secretInfoVO);
} catch (Exception e) {
logger.error("设备状态变化推送error", e);
}
2024-04-20 15:55:35 +08:00
}
}
/**
* 设备充电中状态变化推送
* notification_connector_charge_status
* notification_equip_charge_status
*/
2024-04-22 11:10:17 +08:00
public void notificationConnectorChargeStatus(NotificationDTO dto) {
2024-04-26 16:08:53 +08:00
if (StringUtils.isBlank(dto.getStationId()) || StringUtils.isBlank(dto.getOrderCode())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2024-04-22 11:10:17 +08:00
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
2024-04-20 17:18:21 +08:00
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-04-22 11:10:17 +08:00
if (StringUtils.isNotBlank(dto.getPlatformType()) && !StringUtils.equals(dto.getPlatformType(), secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
2024-04-20 17:18:21 +08:00
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationConnectorChargeStatus(orderCode, secretInfoVO);
} catch (Exception e) {
logger.error("设备充电中状态变化推送error", e);
}
}
2024-04-20 15:55:35 +08:00
}
/**
2024-04-20 17:18:21 +08:00
* 充电订单信息推送
2024-04-20 15:55:35 +08:00
* notification_orderInfo/notification_charge_order_info
*/
2024-04-22 11:10:17 +08:00
public void notificationChargeOrderInfo(NotificationDTO dto) {
2024-04-26 16:08:53 +08:00
if (StringUtils.isBlank(dto.getStationId()) || StringUtils.isBlank(dto.getOrderCode())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2024-04-22 11:10:17 +08:00
String stationId = dto.getStationId();
String orderCode = dto.getOrderCode();
2024-04-20 17:18:21 +08:00
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-04-22 11:10:17 +08:00
if (StringUtils.isNotBlank(dto.getPlatformType()) && !StringUtils.equals(dto.getPlatformType(), secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
2024-04-20 17:18:21 +08:00
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationChargeOrderInfo(orderCode, secretInfoVO);
} catch (Exception e) {
logger.error("设备充电中状态变化推送error", e);
}
}
2024-04-20 15:55:35 +08:00
}
/**
* 站点费率变化推送
* notification_stationFee
*/
2024-04-22 11:10:17 +08:00
public void notificationStationFee(NotificationDTO dto) {
2024-04-26 16:08:53 +08:00
if (StringUtils.isBlank(dto.getStationId())) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
2024-04-22 11:10:17 +08:00
String stationId = dto.getStationId();
2024-04-20 17:18:21 +08:00
// 通过stationId 查询该站点需要对接的平台配置
List<ThirdPartySecretInfoVO> secretInfoVOS = thirdpartySecretInfoService.queryStationToPlatformList(stationId);
if (CollectionUtils.isEmpty(secretInfoVOS)) {
return;
}
// 调用相应平台的处理方法
for (ThirdPartySecretInfoVO secretInfoVO : secretInfoVOS) {
2024-04-22 11:10:17 +08:00
if (StringUtils.isNotBlank(dto.getPlatformType()) && !StringUtils.equals(dto.getPlatformType(), secretInfoVO.getPlatformType())) {
// 如果dto中的platformType不为空并且不等于secretInfoVO.getPlatformType()continue
continue;
}
2024-04-20 17:18:21 +08:00
try {
// 根据平台类型获取Service
ThirdPartyPlatformService platformService = ThirdPartyPlatformFactory.getInvokeStrategy(secretInfoVO.getPlatformType());
platformService.notificationStationFee(stationId, secretInfoVO);
} catch (Exception e) {
logger.error("设备充电中状态变化推送error", e);
}
}
2024-04-20 15:55:35 +08:00
}
}