diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/OrderInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/OrderInfo.java index 6d6855f5e..a9c6d4898 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/OrderInfo.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/common/OrderInfo.java @@ -38,6 +38,30 @@ public class OrderInfo { @JSONField(name = "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 * 设备唯一编码,对同一对接平台,保证唯一 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java index 15178ad88..ffaf4434d 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/LianLianPlatformServiceImpl.java @@ -8,6 +8,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; 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.lianlian.PayChannelEnum; import com.jsowell.common.enums.lianlian.StationPaymentEnum; import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; @@ -52,6 +53,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -87,6 +89,9 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { @Autowired private OrderBasicInfoService orderBasicInfoService; + @Autowired + private RedisCache redisCache; + @Resource private ThirdPartyStationRelationService thirdPartyStationRelationService; @@ -111,14 +116,16 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { // 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义 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 - ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByOperatorId(operatorId); + ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo(); if (thirdPartySecretInfoVO == null) { failReason = 1; succStat = 1; } else { - String theirOperatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret(); + String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret(); String dataSecret = thirdPartySecretInfoVO.getOurDataSecret(); String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv(); // 解密data 获取参数中的OperatorSecret @@ -128,23 +135,31 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); } // 对比密钥 - List operatorSecretList = Lists.newArrayList(theirOperatorSecret, thirdPartySecretInfoVO.getOurOperatorSecret()); - if (!operatorSecretList.contains(inputOperatorSecret)) { + if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) { failReason = 1; succStat = 1; } else { - // 生成token - String token = JWTUtils.createToken(operatorId, theirOperatorSecret, JWTUtils.ttlMillis); + // 先查缓存中是否有已生成的token + 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.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.setSuccStat(succStat); - Map resultMap = ThirdPartyPlatformUtils.generateResultMap(vo, thirdPartySecretInfoVO); + Map resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(), + thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret()); return resultMap; } @@ -709,6 +724,79 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { 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 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 * @@ -857,96 +945,88 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { String dataSecretIv = secretInfoVO.getTheirDataSecretIv(); String urlAddress = secretInfoVO.getTheirUrlPrefix(); - String url = urlAddress + "notification_orderInfo"; + String url = urlAddress + "notification_charge_order_info"; // 拼装成联联平台所需格式对象 OrderInfo orderInfo = OrderInfo.builder() - .operatorID(operatorId) - .equipmentOwnerID(Constants.OPERATORID_LIANLIAN) - .stationID("LC" + orderBasicInfo.getStationId()) - .equipmentID(orderBasicInfo.getPileSn()) - .connectorID(orderBasicInfo.getPileConnectorCode()) .startChargeSeq(orderCode) - .userChargeType(Constants.one) - .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)) + .connectorID(orderBasicInfo.getPileConnectorCode()) .startTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())) .endTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeEndTime())) - .paymentAmount(orderBasicInfo.getPayAmount()) - // .payChannel() + .totalPower(new BigDecimal(String.valueOf(orderDetail.getTotalUsedElectricity())).setScale(2, BigDecimal.ROUND_HALF_UP)) + .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) - // .chargeDetails() .build(); - if (MerchantUtils.isXiXiaoMerchant(orderBasicInfo.getMerchantId())) { - orderInfo.setEquipmentOwnerID(Constants.OPERATORID_XI_XIAO); - } - if (StringUtils.equals("36", String.valueOf(orderBasicInfo.getMerchantId()))) { - // 远大 - orderInfo.setEquipmentOwnerID(Constants.OPERATORID_YUAN_DA); - } - // 支付方式 - if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { - // 微信支付 - orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.WEXIN_PAY.getCode())); - } else if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { - // 支付宝支付 - orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.ALI_PAY.getCode())); - } else { - // 其他 - orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.OTHER.getCode())); - } + // if (MerchantUtils.isXiXiaoMerchant(orderBasicInfo.getMerchantId())) { + // orderInfo.setEquipmentOwnerID(Constants.OPERATORID_XI_XIAO); + // } + // if (StringUtils.equals("36", String.valueOf(orderBasicInfo.getMerchantId()))) { + // // 远大 + // orderInfo.setEquipmentOwnerID(Constants.OPERATORID_YUAN_DA); + // } + // // 支付方式 + // if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) { + // // 微信支付 + // orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.WEXIN_PAY.getCode())); + // } else if (StringUtils.equals(orderBasicInfo.getPayMode(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue())) { + // // 支付宝支付 + // orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.ALI_PAY.getCode())); + // } else { + // // 其他 + // orderInfo.setPayChannel(Integer.valueOf(PayChannelEnum.OTHER.getCode())); + // } // 订单详情 - ChargeDetail detail; - - List billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId()); - // 先将list按照 尖、峰、平、谷 时段排序 - // List collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList()); - // 再循环该list,拼装对应的充电价格、费率 - List chargeDetails = new ArrayList<>(); - for (BillingPriceVO billingPriceVO : billingList) { - detail = new ChargeDetail(); - if (StringUtils.equals(billingPriceVO.getTimeType(), "1")) { - // 尖时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - 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.setDetailPower(orderDetail.getSharpUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getSharpElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getSharpServicePrice()); - } else if (StringUtils.equals(billingPriceVO.getTimeType(), "2")) { - // 峰时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - 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.setDetailPower(orderDetail.getPeakUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getPeakElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getPeakServicePrice()); - } else if (StringUtils.equals(billingPriceVO.getTimeType(), "3")) { - // 平时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - 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.setDetailPower(orderDetail.getFlatUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getFlatElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getFlatServicePrice()); - } else if (StringUtils.equals(billingPriceVO.getTimeType(), "4")) { - // 谷时段 - detail.setDetailStartTime(billingPriceVO.getStartTime()); - detail.setDetailEndTime(billingPriceVO.getEndTime()); - 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.setDetailPower(orderDetail.getValleyUsedElectricity()); - detail.setDetailElecMoney(orderDetail.getValleyElectricityPrice()); - detail.setDetailSeviceMoney(orderDetail.getValleyServicePrice()); - } - chargeDetails.add(detail); - } - orderInfo.setChargeDetails(chargeDetails); + // ChargeDetail detail; + // + // List billingList = pileBillingTemplateService.queryBillingPrice(orderBasicInfo.getStationId()); + // // 先将list按照 尖、峰、平、谷 时段排序 + // // List collect = billingList.stream().sorted(Comparator.comparing(BillingPriceVO::getTimeType)).collect(Collectors.toList()); + // // 再循环该list,拼装对应的充电价格、费率 + // List chargeDetails = new ArrayList<>(); + // for (BillingPriceVO billingPriceVO : billingList) { + // detail = new ChargeDetail(); + // if (StringUtils.equals(billingPriceVO.getTimeType(), "1")) { + // // 尖时段 + // detail.setDetailStartTime(billingPriceVO.getStartTime()); + // detail.setDetailEndTime(billingPriceVO.getEndTime()); + // 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.setDetailPower(orderDetail.getSharpUsedElectricity()); + // detail.setDetailElecMoney(orderDetail.getSharpElectricityPrice()); + // detail.setDetailSeviceMoney(orderDetail.getSharpServicePrice()); + // } else if (StringUtils.equals(billingPriceVO.getTimeType(), "2")) { + // // 峰时段 + // detail.setDetailStartTime(billingPriceVO.getStartTime()); + // detail.setDetailEndTime(billingPriceVO.getEndTime()); + // 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.setDetailPower(orderDetail.getPeakUsedElectricity()); + // detail.setDetailElecMoney(orderDetail.getPeakElectricityPrice()); + // detail.setDetailSeviceMoney(orderDetail.getPeakServicePrice()); + // } else if (StringUtils.equals(billingPriceVO.getTimeType(), "3")) { + // // 平时段 + // detail.setDetailStartTime(billingPriceVO.getStartTime()); + // detail.setDetailEndTime(billingPriceVO.getEndTime()); + // 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.setDetailPower(orderDetail.getFlatUsedElectricity()); + // detail.setDetailElecMoney(orderDetail.getFlatElectricityPrice()); + // detail.setDetailSeviceMoney(orderDetail.getFlatServicePrice()); + // } else if (StringUtils.equals(billingPriceVO.getTimeType(), "4")) { + // // 谷时段 + // detail.setDetailStartTime(billingPriceVO.getStartTime()); + // detail.setDetailEndTime(billingPriceVO.getEndTime()); + // 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.setDetailPower(orderDetail.getValleyUsedElectricity()); + // detail.setDetailElecMoney(orderDetail.getValleyElectricityPrice()); + // detail.setDetailSeviceMoney(orderDetail.getValleyServicePrice()); + // } + // chargeDetails.add(detail); + // } + // orderInfo.setChargeDetails(chargeDetails); // 获取令牌 String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);