| | |
| | | import com.ruoyi.other.api.feignClient.SystemConfigurationClient; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | @Resource |
| | | private SiteClient siteClient; |
| | | |
| | | @Autowired |
| | | private TCECSuperviseUtil tcecSuperviseUtil; |
| | | @Resource |
| | | private ChargingPileClient chargingPileClient; |
| | | |
| | |
| | | log.info("监管平台查询充电站信息响应参数:" + JacksonUtils.toJson(baseResult)); |
| | | return baseResult; |
| | | } |
| | | /** |
| | | * 推送充电用能统计 |
| | | * @return |
| | | */ |
| | | @PostMapping("/supervise_notification_operation_stats_info") |
| | | public void superviseNotificationOperationStatsInfo(){ |
| | | List<Site> data = siteClient.getSiteAll().getData(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime startLocalDateTime = now.minusDays(1); |
| | | LocalDateTime endLocalDateTime = now.minusDays(1); |
| | | // 获取今天凌晨 |
| | | startLocalDateTime.withHour(0); |
| | | startLocalDateTime.withMinute(0); |
| | | startLocalDateTime.withSecond(0); |
| | | String start = DateUtils.localDateTimeToString(startLocalDateTime); |
| | | endLocalDateTime.withHour(23); |
| | | endLocalDateTime.withMinute(59); |
| | | endLocalDateTime.withSecond(59); |
| | | String end = DateUtils.localDateTimeToString(endLocalDateTime); |
| | | ChargingStatisticeDTO chargingStatisticeDTO = new ChargingStatisticeDTO(); |
| | | chargingStatisticeDTO.setStartTime(startLocalDateTime); |
| | | chargingStatisticeDTO.setEndTime(endLocalDateTime); |
| | | List<TChargingOrder> data1 = chargingOrderClient.getChargingStatistics(chargingStatisticeDTO).getData(); |
| | | List<StationStatsInfo> stationStatsInfos = new ArrayList<>(); |
| | | for (Site datum : data) { |
| | | StationStatsInfo stationStatsInfo = new StationStatsInfo(); |
| | | stationStatsInfo.setStationID(datum.getId().toString()); |
| | | stationStatsInfo.setEquipmentOwnerID("906171535"); |
| | | stationStatsInfo.setOperatorID("906171535"); |
| | | stationStatsInfo.setStationClassification(1); |
| | | stationStatsInfo.setStartTime(start); |
| | | stationStatsInfo.setEndTime(end); |
| | | List<TChargingOrder> chargingOrders = data1.stream().filter(e -> e.getSiteId().equals(datum.getId())).collect(Collectors.toList()); |
| | | // 充电电量 |
| | | BigDecimal electricity = new BigDecimal("0"); |
| | | int chargingCount = 0; |
| | | for (TChargingOrder chargingOrder : chargingOrders) { |
| | | if (chargingOrder.getElectricity()!=null){ |
| | | electricity = electricity.add(chargingOrder.getElectricity()); |
| | | chargingCount++; |
| | | } |
| | | } |
| | | stationStatsInfo.setStationElectricity(electricity.divide(new BigDecimal("24")).setScale(4, BigDecimal.ROUND_DOWN)); |
| | | stationStatsInfo.setStationTotalChargeEnergy(electricity.setScale(4, BigDecimal.ROUND_DOWN)); |
| | | stationStatsInfo.setStationTotalWarningNum(0); |
| | | stationStatsInfo.setStationTotalOtherEnergy(new BigDecimal("0")); |
| | | stationStatsInfo.setStationTotalChargeNum(chargingCount); |
| | | //构建设备统计数据 |
| | | List<EquipmentStatsInfo> EquipmentStatsInfos = new ArrayList<>(); |
| | | Map<Integer, List<TChargingOrder>> collect = chargingOrders.stream().collect(Collectors.groupingBy(TChargingOrder::getChargingPileId)); |
| | | for (Integer integer : collect.keySet()) { |
| | | List<TChargingOrder> tChargingOrders = collect.get(integer); |
| | | BigDecimal reduce1 = tChargingOrders.stream().map(TChargingOrder::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | EquipmentStatsInfo equipmentStatsInfo = new EquipmentStatsInfo(); |
| | | equipmentStatsInfo.setEquipmentClassification(1); |
| | | long chargingTime = 0L; |
| | | for (TChargingOrder tChargingOrder : tChargingOrders) { |
| | | // 累加充电时长 |
| | | LocalDateTime startTime = tChargingOrder.getStartTime(); |
| | | LocalDateTime endTime = tChargingOrder.getEndTime(); |
| | | // 计算时间差 单位分钟 |
| | | chargingTime += ChronoUnit.SECONDS.between(startTime, endTime)/60; |
| | | } |
| | | equipmentStatsInfo.setEquipmentTotalChargeTime(chargingTime); |
| | | equipmentStatsInfo.setEquipmentTotalChargeNum(tChargingOrders.size()); |
| | | equipmentStatsInfo.setEquipmentTotalWarningNum(0); |
| | | equipmentStatsInfo.setEquipmentID(integer.toString()); |
| | | equipmentStatsInfo.setEquipmentElectricity(reduce1); |
| | | //构建设备接口统计数据 |
| | | Map<Integer, List<TChargingOrder>> collect2 = tChargingOrders.stream().collect(Collectors.groupingBy(TChargingOrder::getChargingGunId)); |
| | | List<ConnectorStatsInfo> ConnectorStatsInfos = new ArrayList<>(); |
| | | for (Integer integer1 : collect2.keySet()) { |
| | | List<TChargingOrder> tChargingOrders1 = collect2.get(integer1); |
| | | BigDecimal reduce2 = tChargingOrders1.stream().map(TChargingOrder::getChargingCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | TChargingGun chargingGun = chargingGunClient.getChargingGunById(integer1).getData(); |
| | | ConnectorStatsInfo connectorStatsInfo = new ConnectorStatsInfo(); |
| | | connectorStatsInfo.setConnectorID(chargingGun.getFullNumber()); |
| | | connectorStatsInfo.setConnectorElectricity(reduce2); |
| | | ConnectorStatsInfos.add(connectorStatsInfo); |
| | | } |
| | | equipmentStatsInfo.setConnectorStatsInfos(ConnectorStatsInfos); |
| | | EquipmentStatsInfos.add(equipmentStatsInfo); |
| | | } |
| | | stationStatsInfo.setEquipmentStatsInfos(EquipmentStatsInfos); |
| | | stationStatsInfos.add(stationStatsInfo); |
| | | } |
| | | } |
| | | /** |
| | | * 推送充换电站实时功率 |
| | | * @return |
| | | */ |
| | | @PostMapping("/supervise_notification_realtime_power_info") |
| | | public void superviseNotificationRealtimePowerInfo(){ |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 推送充换电站信息 |
| | | * @param datum |
| | | * @return |
| | | */ |
| | | @PostMapping("/supervise_notification_station_info") |
| | | public void superviseNotificationStationInfo(@RequestBody Site datum){ |
| | | BaseResult baseResult = new BaseResult(); |
| | | StationInfo stationInfo = new StationInfo(); |
| | | List<TChargingPile> tChargingPiles = chargingPileClient.getChargingPileBySiteIds(Collections.singletonList(datum.getId())).getData(); |
| | | List<Integer> collect1 = tChargingPiles.stream().map(TChargingPile::getId).collect(Collectors.toList()); |
| | | List<TChargingGun> chargingGunList = chargingGunClient.getChargingGunByChargingPileIds(collect1).getData(); |
| | | String serviceTel = systemConfigurationClient.getServerPhone().getData(); |
| | | stationInfo.setAreaCodeCountryside(datum.getAreaCodeCountryside()); |
| | | stationInfo.setStationClassification(datum.getStationClassification()); |
| | | stationInfo.setGeneralApplicationType(datum.getGeneralApplicationType()); |
| | | if (org.springframework.util.StringUtils.hasLength(datum.getSwapMatchCars())){ |
| | | stationInfo.setSwapMatchCars(Arrays.asList(datum.getSwapMatchCars().split(","))); |
| | | } |
| | | stationInfo.setBusineHours(datum.getStartServiceTime()); |
| | | stationInfo.setRoundTheClock(datum.getRoundTheClock()); |
| | | stationInfo.setParkType(datum.getParkType()); |
| | | stationInfo.setElectricityFee("{"+datum.getElectricityFee()+"}"); |
| | | stationInfo.setServiceFee("{"+datum.getServiceFee()+"}"); |
| | | stationInfo.setParkFee("{\"rules\":"+datum.getParkFee()+","+"\"freeDuration\":"+datum.getParkFeeFree()+"}"); |
| | | stationInfo.setElectricityType(datum.getElectricityType()); |
| | | stationInfo.setBusinessExpandType(datum.getBusinessExpandType()); |
| | | stationInfo.setCapacity(datum.getCapacity()); |
| | | stationInfo.setRatedPower(datum.getRatedPower()); |
| | | stationInfo.setPeriodFee(datum.getPeriodFee()); |
| | | stationInfo.setOfficialRunTime(datum.getOfficialRunTime()); |
| | | stationInfo.setStationOrientation(datum.getStationOrientation()); |
| | | stationInfo.setStationArea(datum.getStationArea()); |
| | | stationInfo.setHavePerson(datum.getHavePerson()); |
| | | stationInfo.setVideoMonitor(datum.getVideoMonitor()); |
| | | if (StringUtils.isNotEmpty(datum.getSupportingFacilities())){ |
| | | String[] split = datum.getSupportingFacilities().split(","); |
| | | List<Integer> collect = Arrays.stream(split).map(Integer::parseInt).collect(Collectors.toList()); |
| | | stationInfo.setSupportingFacilities(collect); |
| | | } |
| | | stationInfo.setPrinterFlag(datum.getPrinterFlag()); |
| | | stationInfo.setBarrierFlag(datum.getBarrierFlag()); |
| | | stationInfo.setParkingLockFlag(datum.getParkingLockFlag()); |
| | | stationInfo.setEquipmentOwnerName(datum.getEquipmentOwnerName()); |
| | | stationInfo.setResidentNo(datum.getResidentNo()); |
| | | stationInfo.setSupplyType(datum.getSupplyType()); |
| | | stationInfo.setWattHourMeterNo(datum.getWattHourMeterNo()); |
| | | BigDecimal forwardPower = datum.getForwardPower(); |
| | | if (forwardPower!=null){ |
| | | stationInfo.setForwardPower(forwardPower.setScale(4, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | stationInfo.setRecordUniqueNo(datum.getRecordUniqueNo()); |
| | | stationInfo.setStationID(datum.getId().toString()); |
| | | stationInfo.setOperatorID("906171535"); |
| | | stationInfo.setEquipmentOwnerID("906171535"); |
| | | stationInfo.setStationName(datum.getName()); |
| | | stationInfo.setCountryCode(StringUtils.isNotEmpty(datum.getCountryCode()) ? datum.getCountryCode() : "CN"); |
| | | stationInfo.setAreaCode(datum.getDistrictsCode()); |
| | | stationInfo.setAddress(datum.getAddress()); |
| | | stationInfo.setStationTel(datum.getPhone()); |
| | | stationInfo.setServiceTel(serviceTel); |
| | | switch (datum.getSiteType()){ |
| | | case 0: |
| | | stationInfo.setStationType(StationTypeEnum.OTHER.getType()); |
| | | break; |
| | | case 1: |
| | | stationInfo.setStationType(StationTypeEnum.PUBLIC.getType()); |
| | | break; |
| | | case 2: |
| | | stationInfo.setStationType(StationTypeEnum.PERSONAGE.getType()); |
| | | break; |
| | | case 3: |
| | | stationInfo.setStationType(StationTypeEnum.BUS_SPECIFIC.getType()); |
| | | break; |
| | | case 4: |
| | | stationInfo.setStationType(StationTypeEnum.SANITATION_SPECIFIC.getType()); |
| | | break; |
| | | case 5: |
| | | stationInfo.setStationType(StationTypeEnum.LOGISTICS_SPECIFIC.getType()); |
| | | break; |
| | | case 6: |
| | | stationInfo.setStationType(StationTypeEnum.TEXT_SPECIFIC.getType()); |
| | | break; |
| | | } |
| | | if(datum.getStatus() == 1){ |
| | | stationInfo.setStationStatus(StationStatusEnum.NORMAL_USE.getStatus()); |
| | | } |
| | | if(datum.getStatus() == 2){ |
| | | stationInfo.setStationStatus(StationStatusEnum.MAINTAIN.getStatus()); |
| | | } |
| | | if(datum.getStatus() == 3){ |
| | | stationInfo.setStationStatus(StationStatusEnum.OFF_LINE.getStatus()); |
| | | } |
| | | stationInfo.setParkNums(datum.getParkingSpace()); |
| | | stationInfo.setStationLat(new BigDecimal(datum.getLat()).setScale(6, RoundingMode.DOWN)); |
| | | stationInfo.setStationLng(new BigDecimal(datum.getLon()).setScale(6, RoundingMode.DOWN)); |
| | | stationInfo.setConstruction(datum.getConstructionSite() == 0 ? ConstructionEnum.OTHER.getType() : datum.getConstructionSite()); |
| | | stationInfo.setPictures(StringUtils.isNotEmpty(datum.getImgUrl()) ? Arrays.asList(datum.getImgUrl().split(",")) : new ArrayList<>()); |
| | | stationInfo.setSiteGuide(datum.getGuide()); |
| | | stationInfo.setMatchCars(datum.getVehicleDescription()); |
| | | stationInfo.setElectricityFee(datum.getRateDescription()); |
| | | //构建充电设备信息数据 |
| | | stationInfo.setEquipmentInfos(buildEquipmentInfo(datum.getId(), tChargingPiles, chargingGunList)); |
| | | // 推送 |
| | | HttpRequest post = HttpUtil.createPost(url + "supervise_notification_station_info"); |
| | | buildBody(post, stationInfo); |
| | | HttpResponse execute = post.execute(); |
| | | if(200 != execute.getStatus()){ |
| | | log.error("推送监管平台电站信息失败:" + execute.body()); |
| | | return ; |
| | | } |
| | | log.info("推送监管平台电站信息响应:" + execute.body()); |
| | | String data = baseResult.getData(); |
| | | // 转化为json |
| | | if(!data.contains("0")){ |
| | | log.error("推送监管平台电站信息失败:" + baseResult.getMsg()); |
| | | // 重试 |
| | | for (int i = 1; i <= 3; i++) { |
| | | try { |
| | | Thread.sleep(5000); |
| | | HttpRequest post1 = HttpUtil.createPost(url + "supervise_notification_station_info"); |
| | | buildBody(post1, stationInfo); |
| | | HttpResponse execute1 = post1.execute(); |
| | | if(200 == execute1.getStatus()){ |
| | | log.info("重试次数:"+i+"推送监管平台电站信息响应:" + execute1.body()); |
| | | BaseResult baseResult2 = JSON.parseObject(execute1.body(), BaseResult.class); |
| | | String data1 = baseResult2.getData(); |
| | | if (data1.contains("0")){ |
| | | break; |
| | | } |
| | | } |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 构建请求参数和消息头 |
| | | * @param post |
| | | * @param o |
| | | */ |
| | | public static void buildBody(HttpRequest post, Object o){ |
| | | Long timeStamp = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); |
| | | post.contentType("application/json;charset=utf-8"); |
| | | // post.header("Authorization", "Bearer " + getToken(operator)); |
| | | BaseRequest baseRequest = new BaseRequest(); |
| | | baseRequest.setOperatorID("906171535"); |
| | | baseRequest.setTimeStamp(timeStamp); |
| | | baseRequest.setSeq("0001"); |
| | | String jsonString = JacksonUtils.toJson(o); |
| | | String encrypt = AESUtil.encrypt(jsonString, ourDataSecret, ourDataSecretIv); |
| | | baseRequest.setData(encrypt); |
| | | baseRequest.setSig(TCECUtil.ourBuildSign(baseRequest)); |
| | | log.info("监管平台推送参数:" + JacksonUtils.toJson(baseRequest)); |
| | | String request_json = JacksonUtils.toJson(baseRequest); |
| | | post.body(request_json); |
| | | |
| | | } |
| | | |
| | | // |
| | | // |