From 1adec9fead03f0f788a73f9349ccba86569e31f3 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期三, 30 四月 2025 19:40:11 +0800 Subject: [PATCH] 修改rocketmq连接方式和修改发起充电异常情况下将订单挂起的功能 --- ruoyi-service/ruoyi-integration/src/test/java/com/ruoyi/integration/RuoYiIntegrationApplicationTests.java | 392 ------------------------------------------------------- 1 files changed, 2 insertions(+), 390 deletions(-) diff --git a/ruoyi-service/ruoyi-integration/src/test/java/com/ruoyi/integration/RuoYiIntegrationApplicationTests.java b/ruoyi-service/ruoyi-integration/src/test/java/com/ruoyi/integration/RuoYiIntegrationApplicationTests.java index c4bcc6b..3d74e3e 100644 --- a/ruoyi-service/ruoyi-integration/src/test/java/com/ruoyi/integration/RuoYiIntegrationApplicationTests.java +++ b/ruoyi-service/ruoyi-integration/src/test/java/com/ruoyi/integration/RuoYiIntegrationApplicationTests.java @@ -30,10 +30,12 @@ import com.ruoyi.other.api.domain.Operator; import com.ruoyi.other.api.feignClient.OperatorClient; import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.core.RocketMQTemplate; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cglib.core.Local; +import org.springframework.messaging.support.MessageBuilder; import org.springframework.util.StringUtils; import javax.annotation.Resource; @@ -50,395 +52,5 @@ @Slf4j @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RuoYiIntegrationApplication.class) public class RuoYiIntegrationApplicationTests { - @Resource - private UploadRealTimeMonitoringDataService uploadRealTimeMonitoringDataService; - - @Resource - private ParkingOrderService parkingOrderService; - @Resource - private SiteClient siteClient; - @Resource - private ChargingGunClient chargingGunClient; - @Resource - private ChargingOrderClient chargingOrderClient; - - @Resource - private OperatorClient operatorClient; - @Test - public void test(){ - /** - * 推送充电设备接口状态信息 - * @param chargingGun - * @return - */ - List<TChargingGun> data = chargingGunClient.getAllGun().getData(); - TChargingGun chargingGun = data.stream().filter(e -> e.getId() == 61).findFirst().orElse(new TChargingGun()); - ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo(); - connectorStatusInfo.setOperatorID("906171535"); - connectorStatusInfo.setEquipmentOwnerID("906171535"); - connectorStatusInfo.setStationID(String.valueOf(chargingGun.getSiteId())); - connectorStatusInfo.setEquipmentID(String.valueOf(chargingGun.getChargingPileId())); - connectorStatusInfo.setConnectorID(chargingGun.getFullNumber()); - connectorStatusInfo.setEquipmentClassification(1); - switch (chargingGun.getStatus()){ - case 1: - connectorStatusInfo.setStatus(0); - break; - case 2: - connectorStatusInfo.setStatus(1); - break; - case 3: - connectorStatusInfo.setStatus(2); - break; - case 4: - connectorStatusInfo.setStatus(3); - break; - case 5: - connectorStatusInfo.setStatus(3); - break; - case 6: - connectorStatusInfo.setStatus(4); - break; - case 7: - connectorStatusInfo.setStatus(255); - break; - } - connectorStatusInfo.setUpdateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); -// List<Operator> operators = operatorClient.getAllOperator().getData(); -// for (Operator operator : operators) { - tcecSuperviseUtil.notificationStationStatus(new Operator(), connectorStatusInfo); -// } - } - @Autowired - private TCECSuperviseUtil tcecSuperviseUtil; - private final static String operatorId = "906171535"; - - @Test - public void test1(){ - TChargingOrder chargingOrder = chargingOrderClient.orderDetail(1884874763556048898L).getData(); - SupEquipChargeStatus supEquipChargeStatus = new SupEquipChargeStatus(); - supEquipChargeStatus.setOperatorID(operatorId); - supEquipChargeStatus.setEquipmentOwnerID(operatorId); - supEquipChargeStatus.setStationID(String.valueOf(chargingOrder.getSiteId())); - supEquipChargeStatus.setEquipmentID(String.valueOf(chargingOrder.getChargingPileId())); - supEquipChargeStatus.setOrderNo(operatorId+chargingOrder.getCode()); - switch (chargingOrder.getStatus()){ - case 2: - supEquipChargeStatus.setConnectorStatus(1); - break; - case 3: - supEquipChargeStatus.setConnectorStatus(2); - break; - case 4: - supEquipChargeStatus.setConnectorStatus(3); - break; - case 5: - supEquipChargeStatus.setConnectorStatus(4); - break; - } - TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); - supEquipChargeStatus.setConnectorID(chargingGun.getFullNumber()); - supEquipChargeStatus.setEquipmentClassification(1); - supEquipChargeStatus.setPushTimeStamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - switch (chargingGun.getStatus()){ - case 1: - supEquipChargeStatus.setConnectorStatus(0); - break; - case 2: - supEquipChargeStatus.setConnectorStatus(1); - break; - case 3: - supEquipChargeStatus.setConnectorStatus(2); - break; - case 4: - supEquipChargeStatus.setConnectorStatus(3); - break; - case 5: - supEquipChargeStatus.setConnectorStatus(3); - break; - case 6: - supEquipChargeStatus.setConnectorStatus(4); - break; - case 7: - supEquipChargeStatus.setConnectorStatus(255); - break; - } - supEquipChargeStatus.setCurrentA(chargingOrder.getCurrent()); - supEquipChargeStatus.setSOC(StringUtils.hasLength(chargingOrder.getEndSoc())?new BigDecimal(chargingOrder.getEndSoc()):new BigDecimal("1")); - supEquipChargeStatus.setStartTime(chargingOrder.getStartTime() != null ? chargingOrder.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : ""); - supEquipChargeStatus.setEndTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - supEquipChargeStatus.setTotalPower(chargingOrder.getElectrovalence()); - tcecSuperviseUtil.notificationSupEquipChargeStatus(new Operator(), supEquipChargeStatus); - } - @Test - public void test2(){ - TChargingOrder chargingOrder = chargingOrderClient.orderDetail(1884874763556048898L).getData(); - SupChargeOrderInfo supChargeOrderInfo = new SupChargeOrderInfo(); - supChargeOrderInfo.setOperatorID(operatorId); - supChargeOrderInfo.setEquipmentOwnerID(operatorId); - supChargeOrderInfo.setStationID(String.valueOf(chargingOrder.getSiteId())); - supChargeOrderInfo.setEquipmentID(String.valueOf(chargingOrder.getChargingPileId())); - supChargeOrderInfo.setOrderNo(operatorId+chargingOrder.getCode()); - TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); - supChargeOrderInfo.setConnectorID(chargingGun.getFullNumber()); - supChargeOrderInfo.setEquipmentClassification(1); - supChargeOrderInfo.setPushTimeStamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); - supChargeOrderInfo.setStartTime(chargingOrder.getStartTime() != null ? chargingOrder.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : ""); - supChargeOrderInfo.setEndTime(chargingOrder.getEndTime() != null ? chargingOrder.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) : ""); - supChargeOrderInfo.setTotalPower(chargingOrder.getElectrovalence()); - supChargeOrderInfo.setTotalElecMoney(chargingOrder.getElectrovalence()); - supChargeOrderInfo.setTotalServiceMoney(chargingOrder.getServiceCharge()); - supChargeOrderInfo.setTotalMoney(chargingOrder.getOrderAmount()); - supChargeOrderInfo.setOrderStatus(chargingOrder.getStatus()); - switch (chargingOrder.getEndMode()){ - case 0: - supChargeOrderInfo.setStopReason(5); - supChargeOrderInfo.setStopDesc("异常终止"); - break; - case 1: - supChargeOrderInfo.setStopReason(0); - supChargeOrderInfo.setStopDesc("用户手动停止充电"); - break; - case 2: - supChargeOrderInfo.setStopReason(1); - supChargeOrderInfo.setStopDesc("客户归属地运营商平台停止充电"); - break; - case 3: - supChargeOrderInfo.setStopReason(1); - supChargeOrderInfo.setStopDesc("费用不足中止"); - break; - } - tcecSuperviseUtil.notificationChargeOrderInfo(new Operator(), supChargeOrderInfo); - } - @Test - public void test3(){ - StationStatsInfoResult res = new StationStatsInfoResult(); - List<Site> data = siteClient.getSiteAll().getData(); - LocalDateTime now = LocalDateTime.now(); - LocalDateTime startLocalDateTime = now.minusDays(1); - LocalDateTime endLocalDateTime = now.minusDays(1); - LocalDateTime localDateTime1 = LocalDateTime.of(2025, 2, 3, 0, 0, 0); - LocalDateTime localDateTime2 = LocalDateTime.of(2025, 2, 3, 23, 59, 59); - - - // 获取今天凌晨 - startLocalDateTime.withHour(0); - startLocalDateTime.withMinute(0); - startLocalDateTime.withSecond(0); - startLocalDateTime.withMonth(1); - startLocalDateTime.withDayOfMonth(28); - String start = DateUtils.localDateTimeToString(startLocalDateTime); - endLocalDateTime.withHour(23); - endLocalDateTime.withMinute(59); - endLocalDateTime.withSecond(59); - startLocalDateTime.withMonth(1); - startLocalDateTime.withDayOfMonth(28); - String end = DateUtils.localDateTimeToString(endLocalDateTime); - ChargingStatisticeDTO chargingStatisticeDTO = new ChargingStatisticeDTO(); - chargingStatisticeDTO.setStartTime(localDateTime1); - chargingStatisticeDTO.setEndTime(localDateTime2); - List<TChargingOrder> data1 = chargingOrderClient.getChargingStatistics(chargingStatisticeDTO).getData(); - List<StationStatsInfo> stationStatsInfos = new ArrayList<>(); - String start1 = DateUtils.localDateTimeToString(localDateTime1); - String start2 = DateUtils.localDateTimeToString(localDateTime2); - - for (Site datum : data) { - StationStatsInfo stationStatsInfo = new StationStatsInfo(); - stationStatsInfo.setStationID(datum.getId().toString()); - stationStatsInfo.setEquipmentOwnerID("906171535"); - stationStatsInfo.setOperatorID("906171535"); - stationStatsInfo.setStationClassification(1); - stationStatsInfo.setStartTime(start1); - stationStatsInfo.setEndTime(start2); - 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"),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); - long chargingTime1 = 0L; - for (TChargingOrder chargingOrder : tChargingOrders1) { - // 累加充电时长 - LocalDateTime startTime = chargingOrder.getStartTime(); - LocalDateTime endTime = chargingOrder.getEndTime(); - // 计算时间差 单位分钟 - chargingTime += ChronoUnit.SECONDS.between(startTime, endTime)/60; - } - TChargingGun chargingGun = chargingGunClient.getChargingGunById(integer1).getData(); - ConnectorStatsInfo connectorStatsInfo = new ConnectorStatsInfo(); - connectorStatsInfo.setConnectorID(chargingGun.getFullNumber()); - connectorStatsInfo.setConnectorElectricity(reduce2); - connectorStatsInfo.setConnectorTotalChargeTime(Integer.valueOf(chargingTime+"")); - connectorStatsInfo.setConnectorTotalChargeNum(tChargingOrders1.size()); - connectorStatsInfo.setConnectorTotalWarningNum(0); - ConnectorStatsInfos.add(connectorStatsInfo); - } - equipmentStatsInfo.setConnectorStatsInfos(ConnectorStatsInfos); - EquipmentStatsInfos.add(equipmentStatsInfo); - } - stationStatsInfo.setEquipmentStatsInfos(EquipmentStatsInfos); - stationStatsInfos.add(stationStatsInfo); - } - res.setStationStatsInfos(stationStatsInfos); - tcecSuperviseUtil.superviseNotificationOperationStatsInfo(res); - } - @Resource - private ChargingPileClient chargingPileClient; - @Test - public void test4(){ - List<Site> data = siteClient.getSiteAll().getData(); - List<Integer> siteIds = data.stream().map(Site::getId).collect(Collectors.toList()); - List<TChargingPile> tChargingPiles = chargingPileClient.getChargingPileBySiteIds(siteIds).getData(); - List<Integer> collect1 = tChargingPiles.stream().map(TChargingPile::getId).collect(Collectors.toList()); - List<TChargingGun> chargingGunList = chargingGunClient.getChargingGunByChargingPileIds(collect1).getData(); - SupStationPowerInfoResult supStationPowerInfoResult = new SupStationPowerInfoResult(); - List<SupStationPowerInfo> stationStatsInfos = new ArrayList<>(); - LocalDateTime now = LocalDateTime.of(2025, 2, 3, 23, 30, 0); - LocalDateTime startLocalDateTime = LocalDateTime.of(2025, 2, 3, 20, 0, 0); - ChargingStatisticeDTO chargingStatisticeDTO = new ChargingStatisticeDTO(); - chargingStatisticeDTO.setStartTime(startLocalDateTime); - chargingStatisticeDTO.setEndTime(now); - List<TChargingOrder> data1 = chargingOrderClient.getChargingStatistics(chargingStatisticeDTO).getData(); - for (Site datum : data) { - List<TChargingOrder> collect = data1.stream().filter(e -> e.getSiteId().equals(datum.getId()) - &&e.getChargingPower()!=null).collect(Collectors.toList()); - SupStationPowerInfo supStationPowerInfo = new SupStationPowerInfo(); - supStationPowerInfo.setOperatorID("906171535"); - supStationPowerInfo.setEquipmentOwnerID("906171535"); - supStationPowerInfo.setStationID(datum.getId().toString()); - supStationPowerInfo.setStationClassification(1); - supStationPowerInfo.setDataTime(DateUtils.localDateTimeToString(LocalDateTime.now())); - if (collect.isEmpty()){ - supStationPowerInfo.setStationRealTimePower(new BigDecimal("0")); - }else{ - BigDecimal divide = collect.stream().map(TChargingOrder::getChargingPower).reduce(BigDecimal.ZERO,BigDecimal::add).divide(new BigDecimal(collect.size()),4,BigDecimal.ROUND_DOWN); - supStationPowerInfo.setStationRealTimePower(divide); - } - supStationPowerInfo.setEquipmentPowerInfos(buildEquipmentPowerInfo(datum.getId(), tChargingPiles, chargingGunList)); - - stationStatsInfos.add(supStationPowerInfo); - } - supStationPowerInfoResult.setSupStationPowerInfos(stationStatsInfos); - tcecSuperviseUtil.superviseNotificationRealtimePowerInfo(supStationPowerInfoResult); - } - /** - * 构建桩数据 - * @param tChargingPiles - * @return - */ - public List<SupEquipmentPowerInfo> buildEquipmentPowerInfo(Integer siteId, List<TChargingPile> tChargingPiles, List<TChargingGun> chargingGunList){ - List<SupEquipmentPowerInfo> equipmentInfos = new ArrayList<>(); - List<TChargingPile> collect = tChargingPiles.stream().filter(s -> s.getSiteId().equals(siteId)).collect(Collectors.toList()); - for (TChargingPile tChargingPile : collect) { - SupEquipmentPowerInfo equipmentInfo = new SupEquipmentPowerInfo(); - equipmentInfo.setEquipmentID(tChargingPile.getId().toString()); - equipmentInfo.setEquipmentClassification(1); - equipmentInfo.setDataTime(DateUtils.localDateTimeToString(LocalDateTime.now())); - equipmentInfo.setEquipRealTimePower(tChargingPile.getRatedPower()); - //构建设备接口信息 - equipmentInfo.setConnectorPowerInfos(buildConnectorPowerInfos(tChargingPile.getId(), tChargingPile.getCode(), chargingGunList)); - equipmentInfos.add(equipmentInfo); - } - return equipmentInfos; - } - public List<SupConnectorPowerInfo> buildConnectorPowerInfos(Integer chargingPileId, String code, List<TChargingGun> chargingGunList){ - List<SupConnectorPowerInfo> connectorInfos = new ArrayList<>(); - List<TChargingGun> collect = chargingGunList.stream().filter(s -> s.getChargingPileId().equals(chargingPileId)).collect(Collectors.toList()); - for (TChargingGun chargingGun : collect) { - SupConnectorPowerInfo connectorInfo = new SupConnectorPowerInfo(); - connectorInfo.setConnectorID(chargingGun.getFullNumber()); - connectorInfo.setEquipmentClassification(chargingGun.getEquipmentClassification()); - connectorInfo.setDataTime(DateUtils.localDateTimeToString(LocalDateTime.now())); - connectorInfo.setConnectorRealTimePower(chargingGun.getChargingPower()); - connectorInfos.add(connectorInfo); - } - return connectorInfos; - } - - private final static String query_token = "/query_token"; - private static final String OperatorID = "MA01H3BQ2"; - private static final String OperatorSecret = "f1331ef0b37c2d1b"; - private static final String SigSecret = "a6fedf0e1b27d6f7"; - private static final String DataSecret = "50a61b93919c9604"; - private static final String DataSecretIV = "7c8ac6861661d584"; - private final static String url = "https://dev-gov-hlht-sc.unievbj.com/evcs/v1.0.0"; - @Test - public void test5(){ - HttpRequest post = HttpUtil.createPost(url + query_token); - JSONObject info = new JSONObject(); - info.put("OperatorID", "906171535"); - info.put("OperatorSecret", OperatorSecret); - Long timeStamp = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); - post.contentType("application/json;charset=utf-8"); - BaseRequestJianGuan baseRequest = new BaseRequestJianGuan(); - baseRequest.setOperatorID("906171535"); - baseRequest.setTimeStamp(timeStamp+""); - baseRequest.setSeq("0001"); - String jsonString = JacksonUtils.toJson(info); - SequenceGenerator generator = new SequenceGenerator(); - String nextSequence = generator.getNextSequence(); - String data = AesEncryption.encrypt(DataSecret, DataSecretIV,jsonString); - String hmacMD5 = HMacMD5Util.getHMacMD5("906171535",timeStamp+"", data,nextSequence,SigSecret); - baseRequest.setData(data); - baseRequest.setSig(hmacMD5); - String request_json = JacksonUtils.toJson(baseRequest); - log.info("获取三方平台授权token请求地址:" + post.getUrl()); - log.info("获取三方平台授权token请求参数:" + request_json); - log.info("获取三方平台授权token请求Data:" + jsonString); - post.body(request_json); - HttpResponse execute = post.execute(); - if(200 != execute.getStatus()){ - log.error("获取三方平台授权token失败:" + execute.body()); - } - log.info("获取三方平台授权token响应参数:" + execute.body()); - BaseResult baseResult = com.alibaba.fastjson.JSON.parseObject(execute.body(), BaseResult.class); - Integer Ret = baseResult.getRet(); - if(0 != Ret){ - log.error("获取三方平台授权token失败:" + baseResult.getMsg()); - } - //解密参数 - String decrypt = AESUtil.decrypt(baseResult.getData(), DataSecret, DataSecretIV); - log.info("获取三方平台授权token响应Data:" + decrypt); - QueryTokenResult queryTokenResult = JSON.parseObject(decrypt, QueryTokenResult.class); - String token = queryTokenResult.getAccessToken(); -// Long tokenAvailableTime = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC) + queryTokenResult.getTokenAvailab - System.err.println(token); - } } -- Gitblit v1.7.1