update 联联平台Service

This commit is contained in:
Lemon
2025-03-10 09:59:55 +08:00
parent 7a84fc5c69
commit 87d5b8bb10
2 changed files with 195 additions and 91 deletions

View File

@@ -38,6 +38,30 @@ public class OrderInfo {
@JSONField(name = "StationID") @JSONField(name = "StationID")
private String stationID; private String stationID;
/**
* 累计充电量
*/
@JSONField(name = "TotalPower")
private BigDecimal totalPower;
/**
* 总电费
*/
@JSONField(name = "TotalElecMoney")
private BigDecimal totalElecMoney;
/**
* 总服务费
*/
@JSONField(name = "TotalSeviceMoney")
private BigDecimal totalSeviceMoney;
/**
* 累计总金额
*/
@JSONField(name = "TotalMoney")
private BigDecimal totalMoney;
/** /**
* 设备编码 Y * 设备编码 Y
* 设备唯一编码,对同一对接平台,保证唯一 * 设备唯一编码,对同一对接平台,保证唯一

View File

@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.jsowell.common.constant.Constants; import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.lianlian.PayChannelEnum; import com.jsowell.common.enums.lianlian.PayChannelEnum;
import com.jsowell.common.enums.lianlian.StationPaymentEnum; import com.jsowell.common.enums.lianlian.StationPaymentEnum;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
@@ -52,6 +53,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -87,6 +89,9 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
@Autowired @Autowired
private OrderBasicInfoService orderBasicInfoService; private OrderBasicInfoService orderBasicInfoService;
@Autowired
private RedisCache redisCache;
@Resource @Resource
private ThirdPartyStationRelationService thirdPartyStationRelationService; private ThirdPartyStationRelationService thirdPartyStationRelationService;
@@ -111,14 +116,16 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
// 0:无1:无此对接平台2:密钥错误; 399:自定义 // 0:无1:无此对接平台2:密钥错误; 399:自定义
int failReason = 0; int failReason = 0;
String operatorId = StringUtils.isNotBlank(dto.getOperatorID()) ? dto.getOperatorID() : dto.getPlatformID(); String operatorId = dto.getOperatorID();
// token缓存key值
String redisKey = operatorId + "_token:";
// 通过operatorId 查出 operatorSecret // 通过operatorId 查出 operatorSecret
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId); ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
if (thirdPartySecretInfoVO == null) { if (thirdPartySecretInfoVO == null) {
failReason = 1; failReason = 1;
succStat = 1; succStat = 1;
} else { } else {
String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret();
String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
// 解密data 获取参数中的OperatorSecret // 解密data 获取参数中的OperatorSecret
@@ -128,23 +135,31 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret");
} }
// 对比密钥 // 对比密钥
List<String> operatorSecretList = Lists.newArrayList(theirOperatorSecret, thirdPartySecretInfoVO.getOurOperatorSecret()); if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) {
if (!operatorSecretList.contains(inputOperatorSecret)) {
failReason = 1; failReason = 1;
succStat = 1; succStat = 1;
} else { } else {
// 生成token // 先查缓存中是否有已生成token
String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis); String token = redisCache.getCacheObject(redisKey);
int expiredTime = (int) redisCache.getExpire(redisKey);
if (StringUtils.isBlank(token)) {
// 生成token
token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis);
expiredTime = (int) (JWTUtils.ttlMillis / 1000);
}
vo.setAccessToken(token); vo.setAccessToken(token);
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); vo.setTokenAvailableTime(expiredTime);
// 设置缓存
redisCache.setCacheObject(redisKey, token, expiredTime, TimeUnit.SECONDS);
} }
} }
// 组装返回参数 // 组装返回参数
vo.setPlatformId(operatorId); vo.setOperatorID(operatorId);
vo.setFailReason(failReason); vo.setFailReason(failReason);
vo.setSuccStat(succStat); vo.setSuccStat(succStat);
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
return resultMap; return resultMap;
} }
@@ -709,6 +724,79 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
return result; return result;
} }
/**
* 推送充电状态 notification_equip_charge_status
* @param orderCode 订单编号
* @return
*/
@Override
public String notificationEquipChargeStatus(String orderCode) {
// 根据订单号查询订单信息
OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
// 查询枪口实时状态
List<RealTimeMonitorData> chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
RealTimeMonitorData realTimeMonitorData;
if (CollectionUtils.isEmpty(chargingRealTimeData)) {
realTimeMonitorData = RealTimeMonitorData.builder()
.chargingDegree(Constants.ZERO)
.connectorStatus("3")
.build();
chargingRealTimeData.add(realTimeMonitorData);
} else {
realTimeMonitorData = chargingRealTimeData.get(0);
}
// String orderStatus = orderInfo.getOrderStatus();
// if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderStatus)) {
// // 充电中
// orderStatus = "2";
// } else if (StringUtils.equals(OrderStatusEnum.ORDER_COMPLETE.getValue(), orderStatus)) {
// // 充电完成
// orderStatus = "4";
// }
BigDecimal current = realTimeMonitorData.getOutputCurrent() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputCurrent());
BigDecimal voltage = realTimeMonitorData.getOutputVoltage() == null ? BigDecimal.ZERO : new BigDecimal(realTimeMonitorData.getOutputVoltage());
String soc = realTimeMonitorData.getSOC() == null ? Constants.ZERO : realTimeMonitorData.getSOC();
// 查询相关配置信息
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
String operatorId = Constants.OPERATORID_JIANG_SU;
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
BigDecimal totalElectricityAmount = orderDetail.getTotalElectricityAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalElectricityAmount();
BigDecimal totalServiceAmount = orderDetail.getTotalServiceAmount() == null ? BigDecimal.ZERO : orderDetail.getTotalServiceAmount();
QueryChargingStatusVO vo = QueryChargingStatusVO.builder()
.startChargeSeq(orderInfo.getOrderCode()) // 订单号
.startChargeSeqStat(Integer.parseInt(orderInfo.getOrderStatus())) // 订单状态
.connectorID(orderInfo.getPileConnectorCode()) // 枪口编码
.connectorStatus(Integer.parseInt(realTimeMonitorData.getConnectorStatus())) // 枪口状态
.currentA(current) // 电流
.voltageA(voltage) // 电压
.soc(new BigDecimal(soc))
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderInfo.getChargeStartTime())) // 开始时间
.endTime(DateUtils.getDateTime()) // 本次采样时间
.totalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())) // 累计充电量
.elecMoney(totalElectricityAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计电费
.seviceMoney(totalServiceAmount.setScale(2, BigDecimal.ROUND_HALF_UP)) // 累计服务费
.totalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount())) // 已充金额
.build();
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_EQUIP_CHARGE_STATUS.getValue();
// 调用平台接口
String jsonString = JSON.toJSONString(vo);
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;
}
/** /**
* 订单信息推送 notification_orderInfo * 订单信息推送 notification_orderInfo
* *
@@ -857,96 +945,88 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService {
String dataSecretIv = secretInfoVO.getTheirDataSecretIv(); String dataSecretIv = secretInfoVO.getTheirDataSecretIv();
String urlAddress = secretInfoVO.getTheirUrlPrefix(); String urlAddress = secretInfoVO.getTheirUrlPrefix();
String url = urlAddress + "notification_orderInfo"; String url = urlAddress + "notification_charge_order_info";
// 拼装成联联平台所需格式对象 // 拼装成联联平台所需格式对象
OrderInfo orderInfo = OrderInfo.builder() OrderInfo orderInfo = OrderInfo.builder()
.operatorID(operatorId)
.equipmentOwnerID(Constants.OPERATORID_LIANLIAN)
.stationID("LC" + orderBasicInfo.getStationId())
.equipmentID(orderBasicInfo.getPileSn())
.connectorID(orderBasicInfo.getPileConnectorCode())
.startChargeSeq(orderCode) .startChargeSeq(orderCode)
.userChargeType(Constants.one) .connectorID(orderBasicInfo.getPileConnectorCode())
.money(new BigDecimal(String.valueOf(orderBasicInfo.getOrderAmount())).setScale(2, BigDecimal.ROUND_HALF_UP))
.electMoney(new BigDecimal(String.valueOf(orderDetail.getTotalElectricityAmount())).setScale(2, BigDecimal.ROUND_HALF_UP))
.serviceMoney(new BigDecimal(String.valueOf(orderDetail.getTotalServiceAmount())).setScale(2, BigDecimal.ROUND_HALF_UP))
.elect(new BigDecimal(String.valueOf(orderDetail.getTotalUsedElectricity())).setScale(2, BigDecimal.ROUND_HALF_UP))
.startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime()))
.endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())) .endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime()))
.paymentAmount(orderBasicInfo.getPayAmount()) .totalPower(new BigDecimal(String.valueOf(orderDetail.getTotalUsedElectricity())).setScale(2, BigDecimal.ROUND_HALF_UP))
// .payChannel() .totalElecMoney(new BigDecimal(String.valueOf(orderDetail.getTotalElectricityAmount())).setScale(2, BigDecimal.ROUND_HALF_UP))
.totalSeviceMoney(new BigDecimal(String.valueOf(orderDetail.getTotalServiceAmount())).setScale(2, BigDecimal.ROUND_HALF_UP))
.totalMoney(new BigDecimal(String.valueOf(orderBasicInfo.getOrderAmount())).setScale(2, BigDecimal.ROUND_HALF_UP))
.stopReason(0) .stopReason(0)
// .chargeDetails()
.build(); .build();
if (MerchantUtils.isXiXiaoMerchant(orderBasicInfo.getMerchantId())) { // if (MerchantUtils.isXiXiaoMerchant(orderBasicInfo.getMerchantId())) {
orderInfo.setEquipmentOwnerID(Constants.OPERATORID_XI_XIAO); // orderInfo.setEquipmentOwnerID(Constants.OPERATORID_XI_XIAO);
} // }
if (StringUtils.equals("36", String.valueOf(orderBasicInfo.getMerchantId()))) { // if (StringUtils.equals("36", String.valueOf(orderBasicInfo.getMerchantId()))) {
// 远大 // // 远大
orderInfo.setEquipmentOwnerID(Constants.OPERATORID_YUAN_DA); // orderInfo.setEquipmentOwnerID(Constants.OPERATORID_YUAN_DA);
} // }
// 支付方式 // // 支付方式
if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { // if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
// 微信支付 // // 微信支付
orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.WEXIN_PAY.getCode())); // orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.WEXIN_PAY.getCode()));
} else if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { // } else if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) {
// 支付宝支付 // // 支付宝支付
orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.ALI_PAY.getCode())); // orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.ALI_PAY.getCode()));
} else { // } else {
// 其他 // // 其他
orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.OTHER.getCode())); // orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.OTHER.getCode()));
} // }
// 订单详情 // 订单详情
ChargeDetail detail; // ChargeDetail detail;
//
List<BillingPriceVO> billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId()); // List<BillingPriceVO> billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId());
// 先将list按照 尖、峰、平、谷 时段排序 // // 先将list按照 尖、峰、平、谷 时段排序
// List<BillingPriceVO> collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList()); // // List<BillingPriceVO> collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList());
// 再循环该list拼装对应的充电价格、费率 // // 再循环该list拼装对应的充电价格、费率
List<ChargeDetail> chargeDetails = new ArrayList<>(); // List<ChargeDetail> chargeDetails = new ArrayList<>();
for (BillingPriceVO billingPriceVO : billingList) { // for (BillingPriceVO billingPriceVO : billingList) {
detail = new ChargeDetail(); // detail = new ChargeDetail();
if (StringUtils.equals(billingPriceVO.getTimeType(), "1")) { // if (StringUtils.equals(billingPriceVO.getTimeType(), "1")) {
// 尖时段 // // 尖时段
detail.setDetailStartTime(billingPriceVO.getStartTime()); // detail.setDetailStartTime(billingPriceVO.getStartTime());
detail.setDetailEndTime(billingPriceVO.getEndTime()); // detail.setDetailEndTime(billingPriceVO.getEndTime());
detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setDetailPower(orderDetail.getSharpUsedElectricity()); // detail.setDetailPower(orderDetail.getSharpUsedElectricity());
detail.setDetailElecMoney(orderDetail.getSharpElectricityPrice()); // detail.setDetailElecMoney(orderDetail.getSharpElectricityPrice());
detail.setDetailSeviceMoney(orderDetail.getSharpServicePrice()); // detail.setDetailSeviceMoney(orderDetail.getSharpServicePrice());
} else if (StringUtils.equals(billingPriceVO.getTimeType(), "2")) { // } else if (StringUtils.equals(billingPriceVO.getTimeType(), "2")) {
// 峰时段 // // 峰时段
detail.setDetailStartTime(billingPriceVO.getStartTime()); // detail.setDetailStartTime(billingPriceVO.getStartTime());
detail.setDetailEndTime(billingPriceVO.getEndTime()); // detail.setDetailEndTime(billingPriceVO.getEndTime());
detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setDetailPower(orderDetail.getPeakUsedElectricity()); // detail.setDetailPower(orderDetail.getPeakUsedElectricity());
detail.setDetailElecMoney(orderDetail.getPeakElectricityPrice()); // detail.setDetailElecMoney(orderDetail.getPeakElectricityPrice());
detail.setDetailSeviceMoney(orderDetail.getPeakServicePrice()); // detail.setDetailSeviceMoney(orderDetail.getPeakServicePrice());
} else if (StringUtils.equals(billingPriceVO.getTimeType(), "3")) { // } else if (StringUtils.equals(billingPriceVO.getTimeType(), "3")) {
// 平时段 // // 平时段
detail.setDetailStartTime(billingPriceVO.getStartTime()); // detail.setDetailStartTime(billingPriceVO.getStartTime());
detail.setDetailEndTime(billingPriceVO.getEndTime()); // detail.setDetailEndTime(billingPriceVO.getEndTime());
detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setDetailPower(orderDetail.getFlatUsedElectricity()); // detail.setDetailPower(orderDetail.getFlatUsedElectricity());
detail.setDetailElecMoney(orderDetail.getFlatElectricityPrice()); // detail.setDetailElecMoney(orderDetail.getFlatElectricityPrice());
detail.setDetailSeviceMoney(orderDetail.getFlatServicePrice()); // detail.setDetailSeviceMoney(orderDetail.getFlatServicePrice());
} else if (StringUtils.equals(billingPriceVO.getTimeType(), "4")) { // } else if (StringUtils.equals(billingPriceVO.getTimeType(), "4")) {
// 谷时段 // // 谷时段
detail.setDetailStartTime(billingPriceVO.getStartTime()); // detail.setDetailStartTime(billingPriceVO.getStartTime());
detail.setDetailEndTime(billingPriceVO.getEndTime()); // detail.setDetailEndTime(billingPriceVO.getEndTime());
detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setElecPrice(new BigDecimal(billingPriceVO.getElectricityPrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP)); // detail.setSevicePrice(new BigDecimal(billingPriceVO.getServicePrice()).setScale(4, BigDecimal.ROUND_HALF_UP));
detail.setDetailPower(orderDetail.getValleyUsedElectricity()); // detail.setDetailPower(orderDetail.getValleyUsedElectricity());
detail.setDetailElecMoney(orderDetail.getValleyElectricityPrice()); // detail.setDetailElecMoney(orderDetail.getValleyElectricityPrice());
detail.setDetailSeviceMoney(orderDetail.getValleyServicePrice()); // detail.setDetailSeviceMoney(orderDetail.getValleyServicePrice());
} // }
chargeDetails.add(detail); // chargeDetails.add(detail);
} // }
orderInfo.setChargeDetails(chargeDetails); // orderInfo.setChargeDetails(chargeDetails);
// 获取令牌 // 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);