From 56437dc191f5cc648d0f9b3d9187ab72683a79bb Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 21 May 2024 08:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=B7=B1=E5=9C=B3?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=20=E6=9F=A5=E8=AF=A2=E5=85=85=E7=94=B5?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E4=BF=A1=E6=81=AF=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/StationChargeStatsInfo.java | 93 +++++++++ .../impl/ShenZhenPlatformServiceImpl.java | 193 +++++++++++++++++- 2 files changed, 282 insertions(+), 4 deletions(-) create mode 100644 jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/StationChargeStatsInfo.java diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/StationChargeStatsInfo.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/StationChargeStatsInfo.java new file mode 100644 index 000000000..891c6d216 --- /dev/null +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/domain/StationChargeStatsInfo.java @@ -0,0 +1,93 @@ +package com.jsowell.thirdparty.platform.domain; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 充电站充电统计信息 + * + * @author Lemon + * @Date 2024/5/18 14:36:30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class StationChargeStatsInfo { + /** + * 充电站id + */ + @JSONField(name = "StationID") + private String stationId; + + /** + * 统计的开始时间 + */ + @JSONField(name = "StartTime") + private String startTime; + + /** + * 统计结束时间 + */ + @JSONField(name = "EndTime") + private String endTime; + + /** + * 充电站累计充电量 + */ + @JSONField(name = "StationChargeElectricity") + private BigDecimal stationChargeElectricity; + + /** + * 充电设备统计信息列表 + */ + @JSONField(name = "EquipmentChargeStatsInfos") + private List equipmentChargeStatsInfos; + + @Data + @Builder + public static class EquipmentChargeStatsInfo{ + + /** + * 设备编码 + */ + @JSONField(name = "EquipmentID") + private String equipmentId; + + /** + * 充电设备累计充电量 + */ + @JSONField(name = "EquipmentChargeElectricity") + private BigDecimal equipmentChargeElectricity; + + /** + * 充电设备接口统计信息列表 + */ + @JSONField(name = "ConnectorChargeStatsInfos") + private List connectorChargeStatsInfos; + + + @Data + @Builder + public static class ConnectorChargeStatsInfo{ + + /** + * 充电设备接口编码 + */ + @JSONField(name = "ConnectorID") + private String connectorId; + + /** + * 充电设备接口累计充电量 + */ + @JSONField(name = "ConnectorChargeElectricity") + private BigDecimal connectorChargeElectricity; + } + } +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/ShenZhenPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/ShenZhenPlatformServiceImpl.java index c6986549a..69aa9c9a7 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/ShenZhenPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/ShenZhenPlatformServiceImpl.java @@ -1,35 +1,41 @@ package com.jsowell.thirdparty.platform.service.impl; +import cn.hutool.core.util.PageUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.github.pagehelper.PageInfo; 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.enums.thirdparty.BusinessInformationExchangeEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; +import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.exception.BusinessException; +import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.OrderBasicInfo; import com.jsowell.pile.domain.ThirdPartyPlatformConfig; import com.jsowell.pile.domain.ThirdPartyStationRelation; import com.jsowell.pile.dto.PushRealTimeInfoDTO; import com.jsowell.pile.dto.QueryStationInfoDTO; -import com.jsowell.pile.service.PileBasicInfoService; -import com.jsowell.pile.service.PileStationInfoService; -import com.jsowell.pile.service.ThirdPartyStationRelationService; +import com.jsowell.pile.service.*; import com.jsowell.pile.thirdparty.CommonParamsDTO; import com.jsowell.pile.thirdparty.EquipmentInfo; import com.jsowell.pile.thirdparty.ZDLStationInfo; import com.jsowell.pile.vo.ThirdPartySecretInfoVO; +import com.jsowell.pile.vo.base.ConnectorInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationInfoVO; import com.jsowell.pile.vo.base.ThirdPartyStationRelationVO; +import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO; import com.jsowell.pile.vo.web.PileStationVO; -import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo; +import com.jsowell.thirdparty.lianlian.domain.*; import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; import com.jsowell.thirdparty.platform.common.StationInfo; +import com.jsowell.thirdparty.platform.domain.StationChargeStatsInfo; import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory; import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService; import com.jsowell.thirdparty.platform.util.*; @@ -42,6 +48,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -61,6 +68,12 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService { @Autowired private ThirdpartySecretInfoService thirdpartySecretInfoService; + @Autowired + private PileConnectorInfoService pileConnectorInfoService; + + @Autowired + private OrderBasicInfoService orderBasicInfoService; + @Autowired private ThirdPartyStationRelationService thirdPartyStationRelationService; @@ -290,7 +303,179 @@ public class ShenZhenPlatformServiceImpl implements ThirdPartyPlatformService { } + /** + * 设备接口状态查询 query_stations_status + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStatus(QueryStationInfoDTO dto) { + List stationIds = dto.getStationIds(); + List StationStatusInfos = new ArrayList<>(); + List ConnectorStatusInfos = new ArrayList<>(); + ThirdPartySecretInfoVO shenZhenSecretInfo = getShenZhenSecretInfo(); + ConnectorStatusInfo connectorStatusInfo; + for (String stationId : stationIds) { + StationStatusInfo stationStatusInfo = new StationStatusInfo(); + stationStatusInfo.setStationId(stationId); + // 根据站点id查询 + List list = pileConnectorInfoService.getConnectorListForLianLian(Long.parseLong(stationId)); + for (ConnectorInfoVO connectorInfoVO : list) { + + String connectorStatus = connectorInfoVO.getConnectorStatus(); + if (StringUtils.equals(connectorStatus, PileConnectorDataBaseStatusEnum.OCCUPIED_CHARGING.getValue())) { + // 充电中 + ConnectorChargeStatusInfo info = new ConnectorChargeStatusInfo(); + OrderBasicInfo orderBasicInfo = orderBasicInfoService.queryChargingByPileConnectorCode(connectorInfoVO.getPileConnectorCode()); + if (orderBasicInfo == null) { + continue; + } + List chargingRealTimeData = orderBasicInfoService.getChargingRealTimeData(orderBasicInfo.getTransactionCode()); + if (CollectionUtils.isNotEmpty(chargingRealTimeData)) { + RealTimeMonitorData realTimeMonitorData = chargingRealTimeData.get(0); + + info.setStartChargeSeq(orderBasicInfo.getOrderCode()); + info.setConnectorID(orderBasicInfo.getPileConnectorCode()); + info.setConnectorStatus(Integer.valueOf(connectorInfoVO.getConnectorStatus())); + info.setCurrentA(new BigDecimal(realTimeMonitorData.getOutputCurrent())); + info.setVoltageA(new BigDecimal(realTimeMonitorData.getOutputVoltage())); + info.setSoc(new BigDecimal(realTimeMonitorData.getSOC())); + info.setStartTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, orderBasicInfo.getChargeStartTime())); + info.setEndTime(DateUtils.getDateTime()); // 本次采样时间 + info.setTotalPower(new BigDecimal(realTimeMonitorData.getChargingDegree())); // 累计充电量 + // info.setElecMoney(); // 累计电费 + // info.setSeviceMoney(); // 累计服务费 + info.setTotalMoney(new BigDecimal(realTimeMonitorData.getChargingAmount())); + + ConnectorStatusInfos.add(info); + } + } else { + // 其他 + connectorStatusInfo = new ConnectorStatusInfo(); + connectorStatusInfo.setConnectorID(connectorInfoVO.getPileConnectorCode()); + connectorStatusInfo.setStatus(Integer.parseInt(connectorInfoVO.getConnectorStatus())); + + ConnectorStatusInfos.add(connectorStatusInfo); + } + } + stationStatusInfo.setConnectorStatusInfos(ConnectorStatusInfos); + StationStatusInfos.add(stationStatusInfo); + } + // 将 StationStatusInfos 分页 + int pageNum = 1; + int pageSize = 10; + List collect = StationStatusInfos.stream() + .skip((pageNum - 1) * pageSize) + .limit(pageSize) + .collect(Collectors.toList()); + + int total = StationStatusInfos.size(); + int pages = PageUtil.totalPage(total, pageSize); + + Map map = new LinkedHashMap<>(); + map.put("Total", total); + map.put("StationStatusInfos", collect); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, shenZhenSecretInfo); + return resultMap; + + } + + /** + * 查询充电统计信息 query_station_charge_stats + * @param dto 查询站点信息dto + * @return + */ + @Override + public Map queryStationStats(QueryStationInfoDTO dto) { + // 根据 operatorId 查出配置密钥信息 + ThirdPartySecretInfoVO secretInfoVO = thirdpartySecretInfoService.queryByOperatorId(dto.getOperatorId()); + if (secretInfoVO == null) { + return null; + } + // 根据站点id 查出这段时间的充电量 + List list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto); + if (CollectionUtils.isEmpty(list)) { + return null; + } + + // 根据充电桩编号分组 key=充电桩编号 + Map> pileMap = list.stream() + .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileSn)); + + // 存放所有充电桩设备 + List equipmentStatsInfoList = Lists.newArrayList(); + // 站点用电量 + BigDecimal stationElectricity = BigDecimal.ZERO; + // 用于记录枪口用电量 在循环每个枪口的时候初始化 + BigDecimal pileElec; + for (String pileSn : pileMap.keySet()) { + // 该充电桩下 所有枪口的用电数据 + List accumulativeInfoVOS = pileMap.get(pileSn); + if (CollectionUtils.isEmpty(accumulativeInfoVOS)) { + continue; + } + + // 存放充电桩用电量 + pileElec = BigDecimal.ZERO; + + // key=枪口编号 value 该枪口的用电数据 + Map> collect = accumulativeInfoVOS.stream() + .collect(Collectors.groupingBy(AccumulativeInfoVO::getPileConnectorCode)); + + List connectorStatsInfos = Lists.newArrayList(); + for (Map.Entry> entry : collect.entrySet()) { + String pileConnectorCode = entry.getKey(); + List value = entry.getValue(); + // 枪口用电量求和 + BigDecimal connectorElec = value.stream() + .map(AccumulativeInfoVO::getConnectorElectricity) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + connectorStatsInfos.add( + StationChargeStatsInfo + .EquipmentChargeStatsInfo + .ConnectorChargeStatsInfo.builder() + .connectorId(pileConnectorCode) + .connectorChargeElectricity(connectorElec) + .build() + ); + // 充电桩电量为枪口用电量累计 + pileElec = pileElec.add(connectorElec); + } + + StationChargeStatsInfo + .EquipmentChargeStatsInfo build = StationChargeStatsInfo.EquipmentChargeStatsInfo.builder() + .equipmentId(pileSn) + .equipmentChargeElectricity(pileElec) + .connectorChargeStatsInfos(connectorStatsInfos) + .build(); + equipmentStatsInfoList.add(build); + + // 所有充电桩用电量之和 + stationElectricity = stationElectricity.add(pileElec); + } + + StationChargeStatsInfo stationChargeStatsInfo = StationChargeStatsInfo.builder() + .stationId(dto.getStationID()) + .startTime(dto.getStartTime()) + .endTime(dto.getEndTime()) + .stationChargeElectricity(stationElectricity) + .equipmentChargeStatsInfos(equipmentStatsInfoList) // 设备列表 + .build(); + + Map map = new LinkedHashMap<>(); + map.put("StationStats", stationChargeStatsInfo); + + Map resultMap = ThirdPartyPlatformUtils.generateResultMap(map, secretInfoVO); + return resultMap; + + } /** * 获取深圳平台相关密钥信息