From 53e39ce17b132aa3fc38ff5d571bc2933f92a286 Mon Sep 17 00:00:00 2001 From: "YAS\\29473" <2947326429@qq.com> Date: Tue, 24 Jun 2025 14:26:23 +0800 Subject: [PATCH] update --- .../impl/SiChuanPlatformServiceImpl.java | 257 ++++++------------ 1 file changed, 90 insertions(+), 167 deletions(-) diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java index 55e7933c7..1855f3534 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/SiChuanPlatformServiceImpl.java @@ -938,104 +938,109 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { */ @Override public String notificationPowerInfo(List stationIds) { - List supStationPowerInfoList = new ArrayList<>(); - stationIds.forEach(stationId -> { - PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(stationId); - String dateTimeNow = DateUtils.getDateTime(); + List list = new ArrayList<>(); + String dateTimeNow = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD_HH_MM_SS); + + for (String stationId : stationIds) { + BigDecimal stationPower = BigDecimal.ZERO; SupStationPowerInfo supStationPowerInfo = new SupStationPowerInfo(); - // 根据站点id查询桩列表 - List pileList = pileBasicInfoService.getPileListByStationId(stationId); - SupStationPowerInfo.EquipmentPowerInfo equipmentPowerInfo = null; - List equipmentPowerInfoList = new ArrayList<>(); - //充换电站实时功率 初始化,指定精度保留4位小数 - BigDecimal stationInstantPower = BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP); supStationPowerInfo.setOperatorId(Constants.OPERATORID_JIANG_SU); - String equipmentOwnerID = ThirdPartyPlatformUtils.extractEquipmentOwnerID(pileMerchantInfoVO.getOrganizationCode()); - supStationPowerInfo.setEquipmentOwnerID(equipmentOwnerID); - supStationPowerInfo.setStationId(stationId); - supStationPowerInfo.setStationClassification(Constants.one); //站点分类 - supStationPowerInfo.setDataTime(dateTimeNow); - - - for (PileBasicInfo pileBasicInfo : pileList) { - equipmentPowerInfo = new SupStationPowerInfo.EquipmentPowerInfo(); - equipmentPowerInfo.setEquipmentID(pileBasicInfo.getSn()); - equipmentPowerInfo.setEquipmentClassification(Constants.one); - equipmentPowerInfo.setDataTime(dateTimeNow); - - // 根据桩sn查询枪口列表 - List pileConnectorInfos = pileConnectorInfoService.selectPileConnectorInfoList(pileBasicInfo.getSn()); - // 如果枪口状态为充电中,则查询枪口功率等信息 - SupStationPowerInfo.EquipmentPowerInfo.ConnectorPowerInfo connectorPowerInfo = null; - List connectorPowerInfoList = new ArrayList<>(); - // 初始化桩功率 - BigDecimal pileInstantPower = BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP); - for (PileConnectorInfo pileConnectorInfo : pileConnectorInfos) { - if (StringUtils.equals(PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue(), pileConnectorInfo.getStatus())) { - // 查询充电枪口状态 - PileConnectorInfoVO connectorInfo = pileConnectorInfoService.getPileConnectorInfoByConnectorCode(pileConnectorInfo.getPileConnectorCode()); - if (Objects.isNull(connectorInfo)) { - throw new BusinessException(ReturnCodeEnum.CODE_CONNECTOR_INFO_NULL_ERROR); - } - //获取该枪充电中的订单信息 - OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(pileConnectorInfo.getPileConnectorCode()); - if(Objects.isNull(orderBasicInfo)){ - throw new BusinessException(ReturnCodeEnum.valueOf("枪口订单查询失败")); - } - //获取到实时数据 - List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); - if(CollectionUtils.isEmpty(chargingRealTimeData)){ - throw new BusinessException(ReturnCodeEnum.valueOf("枪口实时数据查询失败")); - } - RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); - //获取到实时功率 - BigDecimal instantPower = realTimeMonitorData.getOutputPower() == null ? BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP) : - new BigDecimal(realTimeMonitorData.getOutputPower()).setScale(4, RoundingMode.HALF_UP); - - //计算桩的功率 = 枪的功率之和 - pileInstantPower = pileInstantPower.add(instantPower); - - connectorPowerInfo = new SupStationPowerInfo.EquipmentPowerInfo.ConnectorPowerInfo(); - connectorPowerInfo.setConnectorID(connectorInfo.getPileConnectorCode()); - connectorPowerInfo.setEquipmentClassification(Constants.one); - connectorPowerInfo.setDataTime(dateTimeNow); - connectorPowerInfo.setConnectorRealTimePower(instantPower); - - connectorPowerInfoList.add(connectorPowerInfo); - } - // 计算桩的功率(枪口功率之和) - equipmentPowerInfo.setEquipRealTimePower(pileInstantPower); - // 汇总站点功率 - stationInstantPower = stationInstantPower.add(pileInstantPower); - - equipmentPowerInfo.setConnectorPowerInfos(connectorPowerInfoList); - equipmentPowerInfoList.add(equipmentPowerInfo); - } + // 查询运营商基本信息 + PileMerchantInfoVO pileMerchantInfoVO = pileMerchantInfoService.queryMerchantInfoByStationId(stationId); + String organizationCode = pileMerchantInfoVO.getOrganizationCode(); + if (StringUtils.isNotBlank(organizationCode) && organizationCode.length() == 18) { + supStationPowerInfo.setEquipmentOwnerID(ThirdPartyPlatformUtils.extractEquipmentOwnerID(organizationCode)); } - supStationPowerInfo.setStationRealTimePower(stationInstantPower); - supStationPowerInfo.setEquipmentPowerInfos(equipmentPowerInfoList); - supStationPowerInfoList.add(supStationPowerInfo); - }); - // 发送请求 - ThirdPartySecretInfoVO zheJiangPlatformSecretInfo = getSiChuanSecretInfo(); + supStationPowerInfo.setStationId(stationId); + supStationPowerInfo.setStationClassification(Constants.one); + supStationPowerInfo.setDataTime(dateTimeNow); + supStationPowerInfo.setStationRealTimePower(stationPower); + + + // 根据站点id查询桩信息 + List pileList = pileBasicInfoService.getPileListByStationId(stationId); + if (CollectionUtils.isEmpty(pileList)) { + log.error("推送充换电站实时功率 error, 查询桩列表信息为空"); + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + + // 将桩id筛选出来用于批量查询枪口数据 + List pileIds = pileList.stream() + .map(PileBasicInfo::getId) + .collect(Collectors.toList()); + QueryConnectorListDTO dto = new QueryConnectorListDTO(); + dto.setPileIds(pileIds); + dto.setRequestSource("thirdPartyPlatform"); + List connectorList = pileConnectorInfoService.getConnectorInfoListByParams(dto); + + if (CollectionUtils.isEmpty(connectorList)) { + log.error("推送充换电站实时功率 error, 查询枪口列表信息为空"); + throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL); + } + + List supPileInfoList = new ArrayList<>(); + for (PileBasicInfo pileBasicInfo : pileList) { + SupStationPowerInfo.EquipmentPowerInfo supPileInfo = new SupStationPowerInfo.EquipmentPowerInfo(); + supPileInfo.setEquipmentID(pileBasicInfo.getSn()); + supPileInfo.setEquipmentClassification(Constants.one); + supPileInfo.setDataTime(dateTimeNow); + supPileInfo.setEquipRealTimePower(BigDecimal.ZERO); + BigDecimal pileInstantPower = BigDecimal.ZERO; + List connectorPowerInfoList = new ArrayList<>(); + for (PileConnectorInfoVO pileConnectorInfoVO : connectorList) { + if (!StringUtils.equals(pileBasicInfo.getSn(), pileConnectorInfoVO.getPileSn())) { + continue; + } + BigDecimal instantPower = pileConnectorInfoVO.getInstantPower() == null ? BigDecimal.ZERO : pileConnectorInfoVO.getInstantPower(); + SupStationPowerInfo. + EquipmentPowerInfo. + ConnectorPowerInfo connectorPowerInfo = new SupStationPowerInfo.EquipmentPowerInfo.ConnectorPowerInfo(); + connectorPowerInfo.setConnectorID(pileConnectorInfoVO.getPileConnectorCode()); + connectorPowerInfo.setEquipmentClassification(Constants.one); + connectorPowerInfo.setDataTime(dateTimeNow); + BigDecimal InstantPower = instantPower.setScale(4, BigDecimal.ROUND_HALF_UP); + connectorPowerInfo.setConnectorRealTimePower(InstantPower); + // 计算桩此时实时功率 + pileInstantPower = pileInstantPower.add(InstantPower); + + connectorPowerInfoList.add(connectorPowerInfo); + } + supPileInfo.setConnectorPowerInfos(connectorPowerInfoList); + // 桩实时功率 + supPileInfo.setEquipRealTimePower(pileInstantPower.setScale(4, RoundingMode.HALF_UP)); + stationPower = stationPower.add(pileInstantPower); + supPileInfoList.add(supPileInfo); + } + supStationPowerInfo.setEquipmentPowerInfos(supPileInfoList); + supStationPowerInfo.setStationRealTimePower(stationPower.setScale(4, RoundingMode.HALF_UP)); + list.add(supStationPowerInfo); + } + + log.info("推送充电站实时功率信息:{}", JSON.toJSONString(list)); + + // 获取推送配置密钥信息 + ThirdPartySecretInfoVO guiZhouPlatformSecretInfo = getSiChuanSecretInfo(); + + String operatorId = Constants.OPERATORID_JIANG_SU; + String operatorSecret = guiZhouPlatformSecretInfo.getTheirOperatorSecret(); + String signSecret = guiZhouPlatformSecretInfo.getTheirSigSecret(); + String dataSecret = guiZhouPlatformSecretInfo.getTheirDataSecret(); + String dataSecretIv = guiZhouPlatformSecretInfo.getTheirDataSecretIv(); + String urlAddress = guiZhouPlatformSecretInfo.getTheirUrlPrefix(); - String operatorId = zheJiangPlatformSecretInfo.getOurOperatorId(); - String operatorSecret = zheJiangPlatformSecretInfo.getTheirOperatorSecret(); - String signSecret = zheJiangPlatformSecretInfo.getTheirSigSecret(); - String dataSecret = zheJiangPlatformSecretInfo.getTheirDataSecret(); - String dataSecretIv = zheJiangPlatformSecretInfo.getTheirDataSecretIv(); - String urlAddress = zheJiangPlatformSecretInfo.getTheirUrlPrefix(); String url = urlAddress + "supervise_notification_realtime_power_info"; // 获取令牌 String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret); if (StringUtils.isBlank(token)) { return null; } - // 调用平台接口 JSONObject json = new JSONObject(); - json.put("SupStationPowerInfos", supStationPowerInfoList); + json.put("SupStationPowerInfos", list); String jsonString = JSON.toJSONString(json); + // 发送请求 String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret); return result; @@ -1057,7 +1062,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { - /** * 订单推送数据封装 * @param orderBasicInfo @@ -1103,87 +1107,6 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService { } - /** - * 转换时段充电明细 - * - * @param orderDetail - * @param billingList - * @return - */ - private List transformSupChargeDetails(OrderDetail orderDetail, List billingList) { - List resultList = Lists.newArrayList(); - SupChargeDetails detail; - for (BillingPriceVO billingPriceVO : billingList) { - detail = new SupChargeDetails(); - - String startTime = convertTime(billingPriceVO.getStartTime()); - String endTime = convertTime(billingPriceVO.getEndTime()); - - if (StringUtils.equals(billingPriceVO.getTimeType(), BillingTimeTypeEnum.SHARP.getValue())) { - // 尖时段 - detail.setDetailStartTime(startTime); - detail.setDetailEndTime(endTime); - 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(), BillingTimeTypeEnum.PEAK.getValue())) { - // 峰时段 - detail.setDetailStartTime(startTime); - detail.setDetailEndTime(endTime); - 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(), BillingTimeTypeEnum.FLAT.getValue())) { - // 平时段 - detail.setDetailStartTime(startTime); - detail.setDetailEndTime(endTime); - 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(), BillingTimeTypeEnum.VALLEY.getValue())) { - // 谷时段 - detail.setDetailStartTime(startTime); - detail.setDetailEndTime(endTime); - 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()); - } - resultList.add(detail); - } - return resultList; - } - - - public static String convertTime(String timeStr) { - try { - // 1. 解析输入的 HH:mm 为 LocalTime - DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); - LocalTime localTime = LocalTime.parse(timeStr, timeFormatter); - - // 2. 获取当前日期(年、月、日) - LocalDate currentDate = LocalDate.now(); - - // 3. 合并日期和时间为 LocalDateTime - LocalDateTime dateTime = LocalDateTime.of(currentDate, localTime); - - // 4. 格式化为目标格式 yyyy-MM-dd HH:mm:ss - DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - return dateTime.format(outputFormatter); - - } catch (Exception e) { - throw new IllegalArgumentException("时间格式错误,应为 HH:mm", e); - } - } - - /** * 获取配置密钥信息