将 0x3b 0x13中推送第三方平台Service统一方法

This commit is contained in:
Lemon
2024-01-25 11:37:38 +08:00
parent 9086dbfc16
commit 78f2196854
5 changed files with 466 additions and 389 deletions

View File

@@ -8,12 +8,16 @@ import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.thirdparty.common.CommonService;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 远程启动充电命令回复 0x33, 0x34
*
@@ -28,6 +32,9 @@ public class RemoteStartChargingRequestHandler extends AbstractHandler{
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private CommonService commonService;
@Override
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
@@ -92,6 +99,29 @@ public class RemoteStartChargingRequestHandler extends AbstractHandler{
}
// orderBasicInfoService.updateOrderBasicInfo(orderInfo);
log.info("远程启动充电命令回复-交易流水号:{}, 桩编码:{}, 枪号:{}, 启动结果:{}, 失败原因:{}", transactionCode, pileSn, connectorCode, startResult, failedReasonMsg);
// 异步推送第三方平台
CompletableFuture.runAsync(() -> {
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
try {
// 启动结果回复
commonService.commonPushStartChargeResult(orderInfo);
} catch (Exception e) {
e.printStackTrace();
}
// 启动失败, 推送第三方订单信息
if (StringUtils.equals(startResult, Constants.DOUBLE_ZERO)) {
try {
Thread.sleep(500);
commonService.commonPushOrderInfo(orderInfo);
} catch (Exception e) {
log.error("统一推送第三方平台订单信息error, ", e);
}
}
});
return null;
}
}

View File

@@ -7,13 +7,8 @@ import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.parkplatform.ParkingEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.StartModeEnum;
import com.jsowell.common.enums.ykc.YKCChargingStopReasonEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.Cp56Time2a.Cp56Time2aUtil;
import com.jsowell.common.util.DateUtils;
@@ -22,35 +17,19 @@ import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.ThirdPartyStationRelation;
import com.jsowell.pile.domain.ThirdpartyParkingConfig;
import com.jsowell.pile.dto.lutongyunting.BindCouponDTO;
import com.jsowell.pile.dto.ruanjie.UseCouponDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.service.programlogic.AbstractProgramLogic;
import com.jsowell.pile.service.programlogic.ProgramLogicFactory;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
import com.jsowell.pile.vo.web.PileStationVO;
import com.jsowell.thirdparty.hainan.service.HaiNanChargeService;
import com.jsowell.thirdparty.huawei.HuaWeiService;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
import com.jsowell.thirdparty.lutongyunting.service.LTYTService;
import com.jsowell.thirdparty.nanrui.service.NRService;
import com.jsowell.thirdparty.ruanjie.service.RJService;
import com.jsowell.thirdparty.xindiantu.service.XDTService;
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
import com.jsowell.thirdparty.common.CommonService;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
/**
* 交易记录确认
@@ -86,40 +65,8 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
private PileMerchantInfoService pileMerchantInfoService;
@Autowired
private LianLianService lianLianService;
private CommonService commonService;
@Autowired
private ZDLService zdlService;
@Autowired
private NRService nrService;
@Autowired
private YCBCService ycbcService;
@Autowired
private XDTService xdtService;
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private LTYTService ltytService;
@Autowired
private RJService rjService;
@Autowired
private HuaWeiService huaWeiService;
@Autowired
private HaiNanChargeService haiNanChargeService;
@Autowired
private ThirdPartyParkingConfigService thirdPartyParkingConfigService;
public static void main(String[] args) {
BigDecimal totalElectricity = new BigDecimal("23.73");
@@ -678,140 +625,45 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
log.error("结算订单发生异常", e);
}
// 给车辆绑定优惠券
try {
// BigDecimal totalElectricity = new BigDecimal(data.getTotalElectricity());
// if (totalElectricity.compareTo(BigDecimal.TEN) > 0) {
// // 充电度数大于10度
// }
String bindResult = bindCoupon(orderBasicInfo);
log.info("绑定优惠券 订单信息:{}, result:{}", orderBasicInfo, bindResult);
} catch (BusinessException e) {
log.error("绑定优惠券 error, code:{}, msg:{}", e.getCode(), e.getMessage());
} catch (Exception e) {
log.error("绑定优惠券 error,", e);
}
// 联联平台 推送订单信息 notification_orderInfo
try {
// 查询该站点是否推送第三方平台
// ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
// relation.setStationId(Long.parseLong(orderBasicInfo.getStationId()));
List<ThirdPartyStationRelationVO> relationInfoList = thirdPartyStationRelationService.getRelationInfoList(orderBasicInfo.getStationId());
// ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
if (CollectionUtils.isEmpty(relationInfoList)) {
return;
// 异步绑定第三方平台优惠券
CompletableFuture.runAsync(() -> {
try {
String bindResult = commonService.bindCoupon(orderBasicInfo);
log.info("绑定优惠券 订单信息:{}, result:{}", orderBasicInfo, bindResult);
} catch (Exception e) {
log.error("绑定优惠券 error,", e);
}
for (ThirdPartyStationRelationVO relationVO : relationInfoList) {
String thirdPartyType = relationVO.getThirdPartyType();
if (StringUtils.equals(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 联联平台
// 推送停止充电结果
lianLianService.pushStopChargeResult(orderBasicInfo.getOrderCode());
// 推送订单信息
lianLianService.pushOrderInfo(orderBasicInfo.getOrderCode());
// 推送充电订单信息
lianLianService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.ZHONG_DIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 中电联
zdlService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getCode(), thirdPartyType)) {
// 江苏平台
// 推送订单信息
nrService.pushOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.XIN_DIAN_TU.getCode(), thirdPartyType)) {
// 新电途平台
// 推送停止充电结果
xdtService.notificationStopChargeResult(orderBasicInfo.getOrderCode());
// 推送订单信息
xdtService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.HUA_WEI.getCode(), thirdPartyType)) {
// 华为
// 推送停止充电结果
huaWeiService.notificationStopChargeResult(orderBasicInfo.getOrderCode());
// 推送订单信息
huaWeiService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.HAI_NAN.getCode(), thirdPartyType)) {
// 海南平台
haiNanChargeService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
});
if (StringUtils.equals(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getCode(), thirdPartyType)) {
if (StringUtils.equals(orderBasicInfo.getStartMode(), StartModeEnum.THIRD_PARTY_PLATFORM.getValue())) {
// 甬城泊车
// 推送停止充电结果
ycbcService.pushStopChargeResult(orderBasicInfo.getOrderCode());
// 推送订单信息
// log.info("甬城泊车平台 推送充电订单信息 param:{}", orderBasicInfo.getOrderCode());
String result = ycbcService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
// log.info("甬城泊车平台 推送充电订单信息 result:{}", result);
}
}
// // 给车辆绑定优惠券
// try {
// // BigDecimal totalElectricity = new BigDecimal(data.getTotalElectricity());
// // if (totalElectricity.compareTo(BigDecimal.TEN) > 0) {
// // // 充电度数大于10度
// // }
// String bindResult = bindCoupon(orderBasicInfo);
// log.info("绑定优惠券 订单信息:{}, result:{}", orderBasicInfo, bindResult);
// } catch (BusinessException e) {
// log.error("绑定优惠券 error, code:{}, msg:{}", e.getCode(), e.getMessage());
// } catch (Exception e) {
// log.error("绑定优惠券 error,", e);
// }
// 异步推送第三方平台订单信息
CompletableFuture.runAsync(() -> {
try {
commonService.commonPushOrderInfo(orderBasicInfo);
} catch (Exception e) {
log.error("推送第三方平台订单信息error, ", e);
e.printStackTrace();
}
// 调用相关接口
} catch (Exception e) {
log.error("第三方平台 推送订单信息发生异常", e);
}
});
} else {
// 平台没有查到订单
orderBasicInfoService.saveAbnormalOrder(data);
log.warn("充电桩传来的交易记录,根据交易流水号:{}查询不到订单,判定为可疑账单", transactionCode);
}
}
/**
* 绑定优惠券
*
* @param orderBasicInfo
* @return
* @throws UnsupportedEncodingException
*/
private String bindCoupon(OrderBasicInfo orderBasicInfo) throws UnsupportedEncodingException {
if (orderBasicInfo == null) {
return null;
}
// 如果该站点的停车场优惠券信息配置不为空,则需绑定一张优惠券
String stationId = orderBasicInfo.getStationId();
PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId);
if (StringUtils.isBlank(stationInfo.getParkingId())) {
return orderBasicInfo.getOrderCode() + " 该订单无需绑定优惠券";
}
if (StringUtils.equals(ParkingEnum.LU_TONG_YUN_TING_PLATFORM.getCode(), stationInfo.getParkingId())) {
// 路通云停
// 查询密钥等配置
ThirdpartyParkingConfig parkingInfo = thirdPartyParkingConfigService.selectByPrimaryKey(Integer.parseInt(stationInfo.getParkingId()));
if (parkingInfo == null) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_PARKING_INFO_IS_NULL);
}
BindCouponDTO dto = BindCouponDTO.builder()
.appId(parkingInfo.getAppId())
.merchantId(parkingInfo.getParkingMerchantId())
.couponId(parkingInfo.getCouponId())
.secretKey(parkingInfo.getSecretKey())
.plateNumber(orderBasicInfo.getPlateNumber())
.plateColor(5) // 5-绿牌车
.build();
// 绑定优惠券
return ltytService.bindCoupon(dto);
} else if (StringUtils.equals(ParkingEnum.RUAN_JIE_PLATFORM.getCode(), stationInfo.getParkingId())) {
// 软杰
UseCouponDTO dto = UseCouponDTO.builder()
.fCouponCode(orderBasicInfo.getOrderCode()) // 优惠券编号(使用订单编号)
.fCouponType("2") // 优惠类型 2-时长
.fCouponValue("120") // 优惠券面额 单位:分钟
.fPlateCode(orderBasicInfo.getPlateNumber()) // 车牌号
.build();
return rjService.useCoupon(dto);
}
return null;
}
}

View File

@@ -1,44 +1,28 @@
package com.jsowell.netty.handler;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.enums.ykc.StartModeEnum;
import com.jsowell.common.enums.ykc.YKCPileFaultReasonEnum;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.ThirdPartyStationRelation;
import com.jsowell.pile.service.PileBasicInfoService;
import com.jsowell.pile.service.PileConnectorInfoService;
import com.jsowell.pile.service.ThirdPartyStationRelationService;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
import com.jsowell.thirdparty.hainan.service.HaiNanChargeService;
import com.jsowell.thirdparty.huawei.HuaWeiService;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
import com.jsowell.thirdparty.nanrui.service.NRService;
import com.jsowell.thirdparty.xindiantu.service.XDTService;
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
import com.jsowell.thirdparty.common.CommonService;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
/**
@@ -66,34 +50,11 @@ public class UploadRealTimeMonitorHandler extends AbstractHandler {
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private PileConnectorInfoService pileConnectorInfoService;
@Autowired
private LianLianService lianLianService;
@Autowired
private YCBCService ycbcService;
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
private CommonService commonService;
@Autowired
private RedisCache redisCache;
@Autowired
private ZDLService zdlService;
@Autowired
private NRService nrService;
@Autowired
private HaiNanChargeService haiNanChargeService;
@Autowired
private XDTService xdtService;
@Autowired
private HuaWeiService huaWeiService;
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
@@ -321,166 +282,20 @@ public class UploadRealTimeMonitorHandler extends AbstractHandler {
}
}
// 推送第三方平台
pushToThirdPartyPlatforms(pileSn, connectorCode, connectorStatus, realTimeMonitorData, transactionCode);
// 异步推送第三方平台实时数据
// pushToThirdPartyPlatforms(pileSn, connectorCode, connectorStatus, realTimeMonitorData, transactionCode);
CompletableFuture.runAsync(() -> {
try {
commonService.pushRealTimeInfo(pileSn, connectorCode, connectorStatus, realTimeMonitorData, transactionCode);
} catch (Exception e) {
log.error("统一推送第三方平台实时数据 error, ", e);
e.printStackTrace();
}
});
return null;
}
/**
* 推送第三方平台
* @param pileSn 桩编号
* @param connectorCode 枪口号
* @param connectorStatus 枪口状态
* @param realTimeMonitorData 实时数据
* @param transactionCode 交易流水号
*/
private void pushToThirdPartyPlatforms(String pileSn, String connectorCode, String connectorStatus,
RealTimeMonitorData realTimeMonitorData, String transactionCode) {
try {
// 推送第三方平台,先通过桩编号查出站点信息 pushToThirdPartyPlatforms
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
// Map<String, String> pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn));
// String pileStatus = pileStatusMap.get(pileSn);
// if (StringUtils.equals(connectorStatus, pileStatus)) {
// return null;
// }
// 状态不一样,传给第三方平台
// ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
// if (StringUtils.isBlank(String.valueOf(pileBasicInfo.getStationId()))) {
// return;
// }
// relation.setStationId(pileBasicInfo.getStationId());
// 查询该站点是否推送第三方平台
List<ThirdPartyStationRelationVO> list = thirdPartyStationRelationService.getRelationInfoList(String.valueOf(pileBasicInfo.getStationId()));
// ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
if (CollectionUtils.isEmpty(list)) {
return;
}
String pileConnectorCode = pileSn + connectorCode;
// 将枪口状态转换成对接平台的状态
String changedStatus = changeConnectorStatus(connectorStatus, realTimeMonitorData.getPutGunType());
for (ThirdPartyStationRelationVO vo : list) {
String thirdPartyType = vo.getThirdPartyType();
if (StringUtils.equals(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 联联
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
// log.info("推送联联平台实时数据 params: orderBasicInfo:{}", JSON.toJSONString(orderInfo));
// 设备状态变化推送 notification_stationStatus
lianLianService.pushConnectorStatus(pileConnectorCode, changedStatus);
if (StringUtils.equals(connectorStatus, "03")) {
// 充电中
lianLianService.pushPileChargeStatusChange(orderInfo.getOrderCode());
}
// 推送充电状态
lianLianService.pushChargeStatus(orderInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.ZHONG_DIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 中电联
// log.info("推送中电联平台实时数据 pileConnectorCode:{}, connectorStatus:{}", pileConnectorCode, connectorStatus);
zdlService.notificationStationStatus(pileConnectorCode, changedStatus);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getCode(), thirdPartyType)) {
// 先判断缓存中是否有数据
String redisKey = CacheConstants.JIANGSU_PUSH_PILE_STATUS + pileConnectorCode;
Object cacheObject = redisCache.getCacheObject(redisKey);
// 江苏省平台(充电状态至少一分钟推送一次)
if (StringUtils.equals(connectorStatus, "03")) {
// 充电状态
// 如果缓存有数据,证明上次推送未超过一分钟,不予推送,若缓存中无数据,说明需要推送
if (cacheObject == null) {
// log.info("推送江苏省平台 充电状态 params:{}", realTimeMonitorData);
String result = nrService.pushPileStatus(realTimeMonitorData);
redisCache.setCacheObject(redisKey, realTimeMonitorData, 1, TimeUnit.MINUTES);
// log.info("推送江苏省平台 充电状态 result:{}", result);
}
} else {
// 如果不是充电状态,直接推送就可以
// log.info("推送江苏省平台 非充电状态 params:{}", realTimeMonitorData);
String result = nrService.pushPileStatus(realTimeMonitorData);
// log.info("推送江苏省平台 非充电状态 result:{}", result);
}
// log.info("推送江苏省平台实时数据 result:{}", result);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.XIN_DIAN_TU.getCode(), thirdPartyType)) {
// 新电途平台
log.info("新电途平台设备状态变化推送 pileConnectorCode:{}, changedStatus:{}", pileConnectorCode, changedStatus);
String result1 = xdtService.notificationStationStatus(pileConnectorCode, changedStatus);
log.info("新电途平台设备状态变化推送 result:{}", result1);
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
log.info("推送新电途平台 充电状态 params:{}", orderInfo.getOrderCode());
String result = xdtService.notificationEquipChargeStatus(orderInfo.getOrderCode());
log.info("推送新电途平台 充电状态 result:{}", result);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.HUA_WEI.getCode(), thirdPartyType)) {
// 华为平台
huaWeiService.notificationStationStatus(pileConnectorCode, changedStatus);
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
huaWeiService.notificationEquipChargeStatus(orderInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.HAI_NAN.getCode(), thirdPartyType)) {
// 海南平台
haiNanChargeService.notificationStationStatus(pileConnectorCode, changedStatus);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getCode(), thirdPartyType)) {
// 甬城泊车
// log.info("推送甬城泊车平台设备状态变化推送 pileConnectorCode:{}, changedStatus:{}", pileConnectorCode, changedStatus);
// 设备状态变化推送 notification_stationStatus
String result1 = ycbcService.notificationStationStatus(pileConnectorCode, changedStatus);
// log.info("推送甬城泊车平台设备状态变化推送 result:{}", result1);
// 推送充电状态
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
if (StringUtils.equals(orderInfo.getStartMode(), StartModeEnum.THIRD_PARTY_PLATFORM.getValue())) {
// log.info("推送甬城泊车充电订单状态 param:{}", orderInfo);
String result2 = ycbcService.pushChargeStatus(orderInfo.getOrderCode());
// log.info("推送甬城泊车充电订单状态 result:{}", result2);
}
}
}
} catch (Exception e) {
log.error("推送第三方平台 实时数据 异常", e);
}
}
/**
* 转换枪口状态
* @param connectorStatus 有电充平台枪口状态
* @param putGunType 是否插枪
* @return 第三方平台枪口状态
*/
private String changeConnectorStatus(String connectorStatus, String putGunType) {
if (StringUtils.equals(connectorStatus, "02")) {
// 空闲
return Constants.ONE;
} else if (StringUtils.equals(connectorStatus, "02") && StringUtils.equals(putGunType, "01")) {
// 占用(未充电)
return Constants.TWO;
} else if (StringUtils.equals(connectorStatus, "01")) {
// 故障
return "255";
}else {
// 0-离网和 3-充电中不需要转换,直接返回
return connectorStatus;
}
}
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("0100");
String lowOrder = sb.substring(0, 2);

View File

@@ -1,23 +1,48 @@
package com.jsowell.thirdparty.common;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.parkplatform.ParkingEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.StartModeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.PileBasicInfo;
import com.jsowell.pile.domain.ThirdPartyStationRelation;
import com.jsowell.pile.domain.ThirdpartyParkingConfig;
import com.jsowell.pile.dto.PushStationInfoDTO;
import com.jsowell.pile.service.ThirdPartyStationRelationService;
import com.jsowell.pile.dto.lutongyunting.BindCouponDTO;
import com.jsowell.pile.dto.ruanjie.UseCouponDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO;
import com.jsowell.pile.vo.web.PileStationVO;
import com.jsowell.thirdparty.hainan.service.HaiNanChargeService;
import com.jsowell.thirdparty.huawei.HuaWeiService;
import com.jsowell.thirdparty.lianlian.service.LianLianService;
import com.jsowell.thirdparty.lianlian.util.HttpRequestUtil;
import com.jsowell.thirdparty.lutongyunting.service.LTYTService;
import com.jsowell.thirdparty.nanrui.service.NRService;
import com.jsowell.thirdparty.ruanjie.service.RJService;
import com.jsowell.thirdparty.xindiantu.service.XDTService;
import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO;
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -27,11 +52,24 @@ import java.util.stream.Collectors;
* @Date 2024/1/18 15:11:32
*/
@Service
@Slf4j
public class CommonService {
@Autowired
private PileBasicInfoService pileBasicInfoService;
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private ThirdPartyStationRelationService thirdPartyStationRelationService;
@Autowired
private ThirdPartyParkingConfigService thirdPartyParkingConfigService;
@Autowired
private LianLianService lianLianService;
@@ -47,9 +85,21 @@ public class CommonService {
@Autowired
private XDTService xdtService;
@Autowired
private LTYTService ltytService;
@Autowired
private RJService rjService;
@Autowired
private HuaWeiService huaWeiService;
@Autowired
private HaiNanChargeService haiNanChargeService;
@Autowired
private RedisCache redisCache;
/**
* 将站点--第三方平台类型对应关系存入关系表
* @param dto
@@ -112,4 +162,334 @@ public class CommonService {
}
return finalResult.toString();
}
/**
* 统一推送第三方平台实时数据
* @param pileSn 桩编号
* @param connectorCode 枪口号
* @param connectorStatus 枪口状态
* @param realTimeMonitorData 实时数据
* @param transactionCode 交易流水号
*/
public void pushRealTimeInfo(String pileSn, String connectorCode, String connectorStatus,
RealTimeMonitorData realTimeMonitorData, String transactionCode) throws UnsupportedEncodingException {
// 推送第三方平台,先通过桩编号查出站点信息 pushToThirdPartyPlatforms
PileBasicInfo pileBasicInfo = pileBasicInfoService.selectPileBasicInfoBySN(pileSn);
// Map<String, String> pileStatusMap = pileConnectorInfoService.getPileStatus(Lists.newArrayList(pileSn));
// String pileStatus = pileStatusMap.get(pileSn);
// if (StringUtils.equals(connectorStatus, pileStatus)) {
// return null;
// }
// 状态不一样,传给第三方平台
// ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
// if (StringUtils.isBlank(String.valueOf(pileBasicInfo.getStationId()))) {
// return;
// }
// relation.setStationId(pileBasicInfo.getStationId());
// 查询该站点是否推送第三方平台
List<ThirdPartyStationRelationVO> list = thirdPartyStationRelationService.getRelationInfoList(String.valueOf(pileBasicInfo.getStationId()));
// ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
if (CollectionUtils.isEmpty(list)) {
return;
}
String pileConnectorCode = pileSn + connectorCode;
// 将枪口状态转换成对接平台的状态
String changedStatus = changeConnectorStatus(connectorStatus, realTimeMonitorData.getPutGunType());
for (ThirdPartyStationRelationVO vo : list) {
String thirdPartyType = vo.getThirdPartyType();
if (StringUtils.equals(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 联联
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
// log.info("推送联联平台实时数据 params: orderBasicInfo:{}", JSON.toJSONString(orderInfo));
// 设备状态变化推送 notification_stationStatus
lianLianService.pushConnectorStatus(pileConnectorCode, changedStatus);
if (StringUtils.equals(connectorStatus, "03")) {
// 充电中
lianLianService.pushPileChargeStatusChange(orderInfo.getOrderCode());
}
// 推送充电状态
lianLianService.pushChargeStatus(orderInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.ZHONG_DIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 中电联
// log.info("推送中电联平台实时数据 pileConnectorCode:{}, connectorStatus:{}", pileConnectorCode, connectorStatus);
zdlService.notificationStationStatus(pileConnectorCode, changedStatus);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getCode(), thirdPartyType)) {
// 先判断缓存中是否有数据
String redisKey = CacheConstants.JIANGSU_PUSH_PILE_STATUS + pileConnectorCode;
Object cacheObject = redisCache.getCacheObject(redisKey);
// 江苏省平台(充电状态至少一分钟推送一次)
if (StringUtils.equals(connectorStatus, "03")) {
// 充电状态
// 如果缓存有数据,证明上次推送未超过一分钟,不予推送,若缓存中无数据,说明需要推送
if (cacheObject == null) {
// log.info("推送江苏省平台 充电状态 params:{}", realTimeMonitorData);
String result = nrService.pushPileStatus(realTimeMonitorData);
redisCache.setCacheObject(redisKey, realTimeMonitorData, 1, TimeUnit.MINUTES);
// log.info("推送江苏省平台 充电状态 result:{}", result);
}
} else {
// 如果不是充电状态,直接推送就可以
// log.info("推送江苏省平台 非充电状态 params:{}", realTimeMonitorData);
String result = nrService.pushPileStatus(realTimeMonitorData);
// log.info("推送江苏省平台 非充电状态 result:{}", result);
}
// log.info("推送江苏省平台实时数据 result:{}", result);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.XIN_DIAN_TU.getCode(), thirdPartyType)) {
// 新电途平台
log.info("新电途平台设备状态变化推送 pileConnectorCode:{}, changedStatus:{}", pileConnectorCode, changedStatus);
String result1 = xdtService.notificationStationStatus(pileConnectorCode, changedStatus);
log.info("新电途平台设备状态变化推送 result:{}", result1);
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
log.info("推送新电途平台 充电状态 params:{}", orderInfo.getOrderCode());
String result = xdtService.notificationEquipChargeStatus(orderInfo.getOrderCode());
log.info("推送新电途平台 充电状态 result:{}", result);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.HUA_WEI.getCode(), thirdPartyType)) {
// 华为平台
huaWeiService.notificationStationStatus(pileConnectorCode, changedStatus);
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
huaWeiService.notificationEquipChargeStatus(orderInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.HAI_NAN.getCode(), thirdPartyType)) {
// 海南平台
haiNanChargeService.notificationStationStatus(pileConnectorCode, changedStatus);
}
if (StringUtils.equals(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getCode(), thirdPartyType)) {
// 甬城泊车
// log.info("推送甬城泊车平台设备状态变化推送 pileConnectorCode:{}, changedStatus:{}", pileConnectorCode, changedStatus);
// 设备状态变化推送 notification_stationStatus
String result1 = ycbcService.notificationStationStatus(pileConnectorCode, changedStatus);
// log.info("推送甬城泊车平台设备状态变化推送 result:{}", result1);
// 推送充电状态
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderInfo == null) {
return;
}
if (StringUtils.equals(orderInfo.getStartMode(), StartModeEnum.THIRD_PARTY_PLATFORM.getValue())) {
// log.info("推送甬城泊车充电订单状态 param:{}", orderInfo);
String result2 = ycbcService.pushChargeStatus(orderInfo.getOrderCode());
// log.info("推送甬城泊车充电订单状态 result:{}", result2);
}
}
}
}
/**
* 统一方法推送订单信息
* @param orderBasicInfo 订单信息
*/
public void commonPushOrderInfo(OrderBasicInfo orderBasicInfo) {
// 查询该站点是否推送第三方平台
// ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
// relation.setStationId(Long.parseLong(orderBasicInfo.getStationId()));
List<ThirdPartyStationRelationVO> relationInfoList = thirdPartyStationRelationService.getRelationInfoList(orderBasicInfo.getStationId());
// ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
if (CollectionUtils.isEmpty(relationInfoList)) {
return;
}
for (ThirdPartyStationRelationVO relationVO : relationInfoList) {
String thirdPartyType = relationVO.getThirdPartyType();
if (StringUtils.equals(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 联联平台
// 推送停止充电结果
lianLianService.pushStopChargeResult(orderBasicInfo.getOrderCode());
// 推送订单信息
lianLianService.pushOrderInfo(orderBasicInfo.getOrderCode());
// 推送充电订单信息
lianLianService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.ZHONG_DIAN_LIAN_PLATFORM.getCode(), thirdPartyType)) {
// 中电联
zdlService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.JIANG_SU_PLATFORM.getCode(), thirdPartyType)) {
// 江苏平台
// 推送订单信息
nrService.pushOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.XIN_DIAN_TU.getCode(), thirdPartyType)) {
// 新电途平台
// 推送停止充电结果
xdtService.notificationStopChargeResult(orderBasicInfo.getOrderCode());
// 推送订单信息
xdtService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
// if (StringUtils.equals(ThirdPlatformTypeEnum.HUA_WEI.getCode(), thirdPartyType)) {
// // 华为
// // 推送停止充电结果
// result = huaWeiService.notificationStopChargeResult(orderBasicInfo.getOrderCode());
// // 推送订单信息
// result = huaWeiService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
// }
if (StringUtils.equals(ThirdPlatformTypeEnum.HAI_NAN.getCode(), thirdPartyType)) {
// 海南平台
haiNanChargeService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
}
if (StringUtils.equals(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getCode(), thirdPartyType)) {
if (StringUtils.equals(orderBasicInfo.getStartMode(), StartModeEnum.THIRD_PARTY_PLATFORM.getValue())) {
// 甬城泊车
// 推送停止充电结果
ycbcService.pushStopChargeResult(orderBasicInfo.getOrderCode());
// 推送订单信息
// log.info("甬城泊车平台 推送充电订单信息 param:{}", orderBasicInfo.getOrderCode());
ycbcService.pushChargeOrderInfo(orderBasicInfo.getOrderCode());
// log.info("甬城泊车平台 推送充电订单信息 result:{}", result);
}
}
}
}
/**
* 统一推送启动充电结果
* @param orderBasicInfo
* @return
*/
public String commonPushStartChargeResult(OrderBasicInfo orderBasicInfo) {
// 通过站点id查询相关配置信息
ThirdPartyStationRelation relation = new ThirdPartyStationRelation();
relation.setStationId(Long.parseLong(orderBasicInfo.getStationId()));
ThirdPartyStationRelationVO relationInfo = thirdPartyStationRelationService.selectRelationInfo(relation);
// ThirdPartySettingInfo settingInfo = thirdPartySettingInfoService.getInfoByStationId(Long.parseLong(orderBasicInfo.getStationId()));
if (relationInfo == null) {
return null;
}
String operatorId = relationInfo.getOperatorId();
String operatorSecret = relationInfo.getOperatorSecret();
String signSecret = relationInfo.getSignSecret();
String dataSecret = relationInfo.getDataSecret();
String dataSecretIv = relationInfo.getDataSecretIv();
String urlAddress = relationInfo.getUrlAddress();
String thirdPartyType = relationInfo.getThirdPartyType();
// 推送启动充电结果(调用接口 notification_start_charge_result)
String url = urlAddress + "notification_start_charge_result";
// String orderStatus = orderInfo.getOrderStatus();
// // 订单状态统一
// if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) {
// // 充电中
// orderStatus = "2";
// } else if (StringUtils.equals(OrderStatusEnum.NOT_START.getValue(), orderStatus)) {
// // 未启动
// orderStatus = "1";
// } else {
// // 其他状态都为 未知
// orderStatus = "5";
// }
// 拼装参数
JSONObject json = new JSONObject();
json.put("StartChargeSeq", orderBasicInfo.getOrderCode());
json.put("ConnectorID", orderBasicInfo.getPileConnectorCode());
json.put("StartChargeSeqStat", 2); // 一定要给 2-充电中
json.put("StartTime", DateUtils.getDateTime());
String jsonString = JSONObject.toJSONString(json);
String token = "";
String result = "";
if (StringUtils.equals(ThirdPlatformTypeEnum.YONG_CHENG_BO_CHE.getCode(), thirdPartyType)) {
YCBCGetTokenDTO dto = new YCBCGetTokenDTO();
dto.setOperatorId(operatorId);
dto.setDataSecret(dataSecret);
dto.setSignSecret(signSecret);
dto.setUrlAddress(urlAddress);
dto.setDataSecretIv(dataSecretIv);
dto.setOperatorSecret(operatorSecret);
token = ycbcService.YCBCGetToken(dto);
result = HttpRequestUtil.YCBCSendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
}else {
token = lianLianService.getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
}
return result;
}
/**
* 绑定优惠券
*
* @param orderBasicInfo
* @return
* @throws UnsupportedEncodingException
*/
public String bindCoupon(OrderBasicInfo orderBasicInfo) throws UnsupportedEncodingException {
if (orderBasicInfo == null) {
return null;
}
// 如果该站点的停车场优惠券信息配置不为空,则需绑定一张优惠券
String stationId = orderBasicInfo.getStationId();
PileStationVO stationInfo = pileStationInfoService.getStationInfo(stationId);
if (StringUtils.isBlank(stationInfo.getParkingId())) {
return orderBasicInfo.getOrderCode() + " 该订单无需绑定优惠券";
}
if (StringUtils.equals(ParkingEnum.LU_TONG_YUN_TING_PLATFORM.getCode(), stationInfo.getParkingId())) {
// 路通云停
// 查询密钥等配置
ThirdpartyParkingConfig parkingInfo = thirdPartyParkingConfigService.selectByPrimaryKey(Integer.parseInt(stationInfo.getParkingId()));
if (parkingInfo == null) {
throw new BusinessException(ReturnCodeEnum.CODE_QUERY_PARKING_INFO_IS_NULL);
}
BindCouponDTO dto = BindCouponDTO.builder()
.appId(parkingInfo.getAppId())
.merchantId(parkingInfo.getParkingMerchantId())
.couponId(parkingInfo.getCouponId())
.secretKey(parkingInfo.getSecretKey())
.plateNumber(orderBasicInfo.getPlateNumber())
.plateColor(5) // 5-绿牌车
.build();
// 绑定优惠券
return ltytService.bindCoupon(dto);
} else if (StringUtils.equals(ParkingEnum.RUAN_JIE_PLATFORM.getCode(), stationInfo.getParkingId())) {
// 软杰
UseCouponDTO dto = UseCouponDTO.builder()
.fCouponCode(orderBasicInfo.getOrderCode()) // 优惠券编号(使用订单编号)
.fCouponType("2") // 优惠类型 2-时长
.fCouponValue("120") // 优惠券面额 单位:分钟
.fPlateCode(orderBasicInfo.getPlateNumber()) // 车牌号
.build();
return rjService.useCoupon(dto);
}
return null;
}
/**
* 转换枪口状态
* @param connectorStatus 有电充平台枪口状态
* @param putGunType 是否插枪
* @return 第三方平台枪口状态
*/
private String changeConnectorStatus(String connectorStatus, String putGunType) {
if (StringUtils.equals(connectorStatus, "02")) {
// 空闲
return Constants.ONE;
} else if (StringUtils.equals(connectorStatus, "02") && StringUtils.equals(putGunType, "01")) {
// 占用(未充电)
return Constants.TWO;
} else if (StringUtils.equals(connectorStatus, "01")) {
// 故障
return "255";
}else {
// 0-离网和 3-充电中不需要转换,直接返回
return connectorStatus;
}
}
}

View File

@@ -797,15 +797,15 @@ public class LianLianServiceImpl implements LianLianService {
// 如果是新电途平台,则将 startChargeSeqStat 改为 1-启动中
vo.setStartChargeSeqStat(1);
}
// 异步推送启动充电结果
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
pushStartChargeResult(orderCode);
});
// 异步推送启动充电结果 2024.01.25改为在0x33帧类型中统一回复
// CompletableFuture.runAsync(() -> {
// try {
// Thread.sleep(200);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// pushStartChargeResult(orderCode);
// });
// 加密
Map<String, String> resultMap = Maps.newLinkedHashMap();