From cbad982befcf58521b224da1e8898c23c5e0d2c6 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期四, 29 五月 2025 16:49:41 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECController.java | 275 ++++++++++++++++++++++++++---------------------------- 1 files changed, 134 insertions(+), 141 deletions(-) diff --git a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECController.java b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECController.java index 9eaf611..1760e83 100644 --- a/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECController.java +++ b/ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/drainage/TCECController.java @@ -1,6 +1,7 @@ package com.ruoyi.integration.drainage; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.common.utils.JacksonUtils; import com.ruoyi.chargingPile.api.feignClient.*; import com.ruoyi.chargingPile.api.model.*; @@ -13,6 +14,9 @@ import com.ruoyi.integration.drainage.kuaidian.model.*; import com.ruoyi.integration.drainage.model.*; import com.ruoyi.integration.drainage.model.enu.*; +import com.ruoyi.integration.drainage.util.AesEncryption; +import com.ruoyi.integration.drainage.util.HMacMD5Util; +import com.ruoyi.integration.drainage.util.SequenceGenerator; import com.ruoyi.integration.mongodb.service.UploadRealTimeMonitoringDataService; import com.ruoyi.order.api.feignClient.ChargingOrderAccountingStrategyClient; import com.ruoyi.order.api.feignClient.ChargingOrderClient; @@ -103,19 +107,22 @@ Long mapKey = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); baseResult.setTimeStamp(mapKey); baseResult.setSeq("0001"); + //校验token和签名 String operatorID = baseRequest.getOperatorID(); String sig = baseRequest.getSig(); Long timeStamp = baseRequest.getTimeStamp(); String data = baseRequest.getData(); String seq = baseRequest.getSeq(); + if(StringUtils.isEmpty(operatorID) || StringUtils.isEmpty(sig) || StringUtils.isEmpty(data) || StringUtils.isEmpty(seq) || null == timeStamp){ baseResult.setRet(4003); baseResult.setMsg("参数异常"); return baseResult; } - + R<Operator> r = operatorClient.getOperator(operatorID); + if(200 != r.getCode()){ baseResult.setRet(500); baseResult.setMsg("系统异常"); @@ -139,6 +146,30 @@ if(!sign.equals(sig)){ baseResult.setRet(4001); baseResult.setMsg("签名校验失败"); + return baseResult; + } + return baseResult; + } + public BaseResult requestCheckJianGuan(Boolean tokenCheck, BaseRequest baseRequest, HttpServletRequest request){ + Operator operator = new Operator(); + BaseResult baseResult = new BaseResult(); + baseResult.setRet(0); + baseResult.setMsg("成功"); + baseResult.setOperatorID(baseRequest.getOperatorID()); + operator.setOperatorId(baseRequest.getOperatorID()); + Long mapKey = Long.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); + baseResult.setTimeStamp(mapKey); + baseResult.setSeq("0001"); + //校验token和签名 + String operatorID = baseRequest.getOperatorID(); + String sig = baseRequest.getSig(); + Long timeStamp = baseRequest.getTimeStamp(); + String data = baseRequest.getData(); + String seq = baseRequest.getSeq(); + baseResult.setOperator(operator); + if(StringUtils.isEmpty(operatorID) || StringUtils.isEmpty(sig) || StringUtils.isEmpty(data) || StringUtils.isEmpty(seq) || null == timeStamp){ + baseResult.setRet(4003); + baseResult.setMsg("参数异常"); return baseResult; } return baseResult; @@ -211,6 +242,48 @@ String encrypt = AESUtil.encrypt(jsonString, operator.getOurDataSecret(), operator.getOurDataSecretIv()); baseResult.setData(encrypt); baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); + log.info("三方平台获取token响应参数:" + JacksonUtils.toJson(baseResult)); + return baseResult; + } + /** + * 获取token + * @return + */ + @PostMapping("/query_token_jianguan") + public BaseResult queryTokenJianguan(@RequestBody BaseRequest baseRequest, HttpServletRequest request){ + log.info("三方平台获取token请求参数:" + JacksonUtils.toJson(baseRequest)); + BaseResult baseResult = requestCheck(false, baseRequest, request); + if(0 != baseResult.getRet()){ + log.info("三方平台获取token响应Data:"); + baseResult.setData(""); + baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); + log.info("三方平台获取token响应参数:" + JacksonUtils.toJson(baseResult)); + return baseResult; + } + QueryTokenResult queryTokenResult = new QueryTokenResult(); + //生成token + Operator operator = baseResult.getOperator(); + Map<String, Object> token = tokenUtil.createToken(operator); + String access_token = token.get("access_token").toString(); + Long expires_in = Long.valueOf(token.get("expires_in").toString()); + + queryTokenResult.setOperatorID("906171535"); + queryTokenResult.setSuccStat(0); + queryTokenResult.setFailReason(0); + queryTokenResult.setAccessToken(access_token); + queryTokenResult.setTokenAvailableTime(expires_in * 60); + //参数加密 + String jsonString = JacksonUtils.toJson(queryTokenResult); + log.info("三方平台获取token响应Data:" + jsonString); +// String encrypt = AESUtil.encrypt(jsonString, operator.getOurDataSecret(), operator.getOurDataSecretIv()); +// baseResult.setData(encrypt); + String timeStamp = System.currentTimeMillis() + ""; + SequenceGenerator generator = new SequenceGenerator(); + String nextSequence = generator.getNextSequence(); + String data = AesEncryption.encrypt(OurDataSecret, OurDataSecretIV,jsonString); + String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,OurSigSecret); + baseResult.setData(data); + baseResult.setSig(hmacMD5); log.info("三方平台获取token响应参数:" + JacksonUtils.toJson(baseResult)); return baseResult; } @@ -326,8 +399,8 @@ stationInfo.setCountryCode(StringUtils.isNotEmpty(datum.getCountryCode()) ? datum.getCountryCode() : "CN"); stationInfo.setAreaCode(datum.getDistrictsCode()); stationInfo.setAddress(datum.getAddress()); - stationInfo.setStationTel(datum.getPhone()); - stationInfo.setServiceTel(serviceTel); + stationInfo.setStationTel(StringUtils.isNotEmpty(datum.getPhone()) ? datum.getPhone().split(",")[0] : ""); + stationInfo.setServiceTel(StringUtils.isNotEmpty(serviceTel) ? serviceTel.split(",")[0] : ""); switch (datum.getSiteType()){ case 0: stationInfo.setStationType(StationTypeEnum.OTHER.getType()); @@ -515,7 +588,7 @@ * @return */ @PostMapping("/pushChargingGunStatus") - public R pushChargingGunStatus(@RequestParam("fullNumber") String fullNumber, @RequestParam("status") Integer status){ + public R pushChargingGunStatus(@RequestParam(value = "fullNumber") String fullNumber, @RequestParam(value = "status") Integer status){ ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo(); connectorStatusInfo.setConnectorID(fullNumber); switch (status){ @@ -1209,7 +1282,7 @@ } chargeDetail.setElecPrice(datum.getElectrovalence()); chargeDetail.setSevicePrice(datum.getServiceCharge()); - chargeDetail.setDetailPower(datum.getChargingCapacity()); + chargeDetail.setDetailPower(datum.getChargingCapacity().setScale(2, BigDecimal.ROUND_HALF_UP)); chargeDetail.setDetailElecMoney(datum.getPeriodElectricPrice()); chargeDetail.setDetailSeviceMoney(datum.getPeriodServicePrice()); chargeDetails.add(chargeDetail); @@ -1416,6 +1489,7 @@ notificationChargeOrderInfo.setStartChargeSeq(startChargeSeq); TChargingOrder chargingOrder = chargingOrderClient.getChargingOrderByStartChargeSeq(startChargeSeq).getData(); if(null == chargingOrder){ + log.info("三方平台流水号获取订单失败"); return null; } TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData(); @@ -1483,7 +1557,7 @@ } chargeDetail.setElecPrice(datum.getElectrovalence()); chargeDetail.setSevicePrice(datum.getServiceCharge()); - chargeDetail.setDetailPower(datum.getChargingCapacity()); + chargeDetail.setDetailPower(datum.getChargingCapacity().setScale(2, BigDecimal.ROUND_HALF_UP)); chargeDetail.setDetailElecMoney(datum.getPeriodElectricPrice()); chargeDetail.setDetailSeviceMoney(datum.getPeriodServicePrice()); chargeDetails.add(chargeDetail); @@ -1678,7 +1752,7 @@ } chargeDetail.setElecPrice(datum.getElectrovalence()); chargeDetail.setSevicePrice(datum.getServiceCharge()); - chargeDetail.setDetailPower(datum.getChargingCapacity()); + chargeDetail.setDetailPower(datum.getChargingCapacity().setScale(2, BigDecimal.ROUND_HALF_EVEN)); chargeDetail.setDetailElecMoney(datum.getPeriodElectricPrice()); chargeDetail.setDetailSeviceMoney(datum.getPeriodServicePrice()); chargeDetails.add(chargeDetail); @@ -1701,19 +1775,8 @@ */ @PostMapping("/supervise_query_operator_info") public BaseResult superviseQueryOperatorInfo(@RequestBody BaseRequest baseRequest, HttpServletRequest request){ - log.info("监管平台查询充电站信息请求参数:" + JacksonUtils.toJson(baseRequest)); - //校验token和签名 - BaseResult baseResult = requestCheck(true, baseRequest, request); - if(0 != baseResult.getRet()){ - log.info("监管平台查询充电站信息响应Data:"); - baseResult.setData(""); - baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); - log.info("监管平台查询充电站信息响应参数:" + JacksonUtils.toJson(baseResult)); - return baseResult; - } - Operator operator = baseResult.getOperator(); //解密参数 - String decrypt = AESUtil.decrypt(baseRequest.getData(), operator.getOurDataSecret(), operator.getOurDataSecretIv()); + String decrypt = AESUtil.decrypt(baseRequest.getData(), OurDataSecret, OurDataSecretIV); log.info("监管平台查询充电站信息请求Data:" + decrypt); SuperviseQueryOperatorInfo superviseQueryOperatorInfo = JSON.parseObject(decrypt, SuperviseQueryOperatorInfo.class); Integer pageNo = superviseQueryOperatorInfo.getPageNo(); @@ -1740,12 +1803,17 @@ // 将superviseQueryOperatorInfoResults转化为json数组 superviseQueryOperatorInfoResultPage.setOperatorInfos(superviseQueryOperatorInfoResults); String jsonString = JacksonUtils.toJson(superviseQueryOperatorInfoResultPage); - //参数加密 - log.info("监管平台查询充电站信息响应Data:" + jsonString); - String encrypt = AESUtil.encrypt(jsonString, operator.getOurDataSecret(), operator.getOurDataSecretIv()); - baseResult.setData(encrypt); - baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); - log.info("监管平台查询充电站信息响应参数:" + JacksonUtils.toJson(baseResult)); + String timeStamp = System.currentTimeMillis() + ""; + SequenceGenerator generator = new SequenceGenerator(); + String nextSequence = generator.getNextSequence(); + String data = AesEncryption.encrypt(OurDataSecret, OurDataSecretIV,JSONObject.toJSONString(superviseQueryOperatorInfoResultPage)); + String hmacMD5 = HMacMD5Util.getHMacMD5(OperatorID,timeStamp, data,nextSequence,OurSigSecret); + BaseResult baseResult = new BaseResult(); + baseResult.setData(data); + baseResult.setSig(hmacMD5); + baseResult.setRet(0); + baseResult.setMsg("OK"); + baseResult.setOperatorID(OperatorID); return baseResult; } @@ -1759,20 +1827,9 @@ */ @PostMapping("/supervise_query_stations_info") public BaseResult superviseQueryStationsInfo(@RequestBody BaseRequest baseRequest, HttpServletRequest request){ - log.info("监管平台查询充电站信息请求参数:" + JacksonUtils.toJson(baseRequest)); - //校验token和签名 - BaseResult baseResult = requestCheck(true, baseRequest, request); - if(0 != baseResult.getRet()){ - log.info("监管平台查询充电站信息响应Data:"); - baseResult.setData(""); - baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); - log.info("监管平台查询充电站信息响应参数:" + JacksonUtils.toJson(baseResult)); - return baseResult; - } - Operator operator = baseResult.getOperator(); + String decrypt = AESUtil.decrypt(baseRequest.getData(), OurDataSecret, OurDataSecretIV); + log.info("监管平台supervise_query_stations_infoData:" + decrypt); //解密参数 - String decrypt = AESUtil.decrypt(baseRequest.getData(), operator.getOurDataSecret(), operator.getOurDataSecretIv()); - log.info("监管平台查询充电站信息请求Data:" + decrypt); QueryStationsInfo queryStationsInfo = JSON.parseObject(decrypt, QueryStationsInfo.class); Integer pageNo = queryStationsInfo.getPageNo(); Integer pageSize = queryStationsInfo.getPageSize(); @@ -1790,13 +1847,17 @@ queryStationsInfoResult.setPageCount((0 == (siteListPaging.getTotal() % pageSize) ? 0 : 1) + Double.valueOf(siteListPaging.getTotal() / pageSize).intValue()); queryStationsInfoResult.setItemSize(Long.valueOf(siteListPaging.getTotal()).intValue()); queryStationsInfoResult.setStationInfos(buildSite(parkingLots, siteListPaging.getRecords())); - //参数加密 - String jsonString = JacksonUtils.toJson(queryStationsInfoResult); - log.info("监管平台查询充电站信息响应Data:" + jsonString); - String encrypt = AESUtil.encrypt(jsonString, operator.getOurDataSecret(), operator.getOurDataSecretIv()); - baseResult.setData(encrypt); - baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); - log.info("监管平台查询充电站信息响应参数:" + JacksonUtils.toJson(baseResult)); + String timeStamp = System.currentTimeMillis() + ""; + SequenceGenerator generator = new SequenceGenerator(); + String nextSequence = generator.getNextSequence(); + String data = AesEncryption.encrypt(OurDataSecret, OurDataSecretIV,JSONObject.toJSONString(queryStationsInfoResult)); + String hmacMD5 = HMacMD5Util.getHMacMD5(OurOperatorID,timeStamp, data,nextSequence,OurSigSecret); + BaseResult baseResult = new BaseResult(); + baseResult.setData(data); + baseResult.setSig(hmacMD5); + baseResult.setRet(0); + baseResult.setMsg("OK"); + baseResult.setOperatorID(OurOperatorID); return baseResult; } /** @@ -1808,18 +1869,9 @@ @PostMapping("/supervise_query_station_status") public BaseResult superviseQueryStationStatus(@RequestBody BaseRequest baseRequest, HttpServletRequest request){ log.info("监管平台查询充换电站状态信息请求参数:" + JacksonUtils.toJson(baseRequest)); - //校验token和签名 - BaseResult baseResult = requestCheck(true, baseRequest, request); - if(0 != baseResult.getRet()){ - log.info("监管平台查询充换电站状态信息响应Data:"); - baseResult.setData(""); - baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); - log.info("监管平台查询充换电站状态信息响应参数:" + JacksonUtils.toJson(baseResult)); - return baseResult; - } - Operator operator = baseResult.getOperator(); + String decrypt = AESUtil.decrypt(baseRequest.getData(), OurDataSecret, OurDataSecretIV); + log.info("监管平台supervise_query_station_statusData:" + decrypt); //解密参数 - String decrypt = AESUtil.decrypt(baseRequest.getData(), operator.getOurDataSecret(), operator.getOurDataSecretIv()); log.info("监管平台查询充换电站状态信息请求Data:" + decrypt); QueryStationStatus queryStationStatus = JSON.parseObject(decrypt, QueryStationStatus.class); List<String> stationIDs = queryStationStatus.getStationIDs(); @@ -1885,15 +1937,34 @@ } queryStationStatusResult.setStationStatusInfos(stationStatusInfos); } - //参数加密 - String jsonString = JacksonUtils.toJson(queryStationStatusResult); - log.info("监管平台查询充电站信息响应Data:" + jsonString); - String encrypt = AESUtil.encrypt(jsonString, operator.getOurDataSecret(), operator.getOurDataSecretIv()); - baseResult.setData(encrypt); - baseResult.setSig(TCECUtil.ourBuildSign(baseResult)); - log.info("监管平台查询充电站信息响应参数:" + JacksonUtils.toJson(baseResult)); + String timeStamp = System.currentTimeMillis() + ""; + SequenceGenerator generator = new SequenceGenerator(); + String nextSequence = generator.getNextSequence(); + String data = AesEncryption.encrypt(OurDataSecret, OurDataSecretIV,JSONObject.toJSONString(queryStationStatusResult)); + String hmacMD5 = HMacMD5Util.getHMacMD5(OurOperatorID,timeStamp, data,nextSequence,OurSigSecret); + BaseResult baseResult = new BaseResult(); + baseResult.setData(data); + baseResult.setSig(hmacMD5); + baseResult.setRet(0); + baseResult.setMsg("OK"); + baseResult.setOperatorID(OurOperatorID); return baseResult; } + + // 测试环境 + 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 static final String OurDataSecret = "50a61b93919c9605"; + private static final String OurDataSecretIV = "7c8ac6861661d585"; + private static final String OurSigSecret = "a6fedf0e1b27d6f6"; + private static final String OurOperatorID = "MA01H3BQ3"; + private static final String OurOperatorSecret = "f1331ef0b37c2d1a"; + + /** @@ -2052,85 +2123,7 @@ } - /** - * 推送充换电站信息 - * @param id - * @return - */ - @PostMapping("/supervise_notification_station_info") - public R superviseNotificationStationInfo(@RequestParam Integer id){ - String serviceTel = systemConfigurationClient.getServerPhone().getData(); - Site site = siteClient.getSiteAll().getData().stream().filter(e -> e.getId().equals(id)).findFirst().orElse(new Site()); - List<TChargingPile> tChargingPiles = chargingPileClient.getChargingPileBySiteIds(Collections.singletonList(site.getId())).getData(); - List<Integer> collect1 = tChargingPiles.stream().map(TChargingPile::getId).collect(Collectors.toList()); - List<TChargingGun> chargingGunList = chargingGunClient.getChargingGunByChargingPileIds(collect1).getData(); - SupStationInfo supStationInfo = new SupStationInfo(); - supStationInfo.setStationID(site.getId().toString()); - supStationInfo.setStationUniqueNumber(site.getDistrictsCode() + "906171535" + site.getId()); - supStationInfo.setOperatorID("906171535"); - supStationInfo.setEquipmentOwnerID("906171535"); - supStationInfo.setStationName(site.getName()); - supStationInfo.setCountryCode(site.getCountryCode()); - supStationInfo.setAreaCode(site.getCityCode()); - supStationInfo.setAddress(site.getAddress()); - supStationInfo.setAreaCodeCountryside(site.getAreaCodeCountryside()); - supStationInfo.setStationTel(site.getPhone()); - - supStationInfo.setServiceTel(serviceTel); - supStationInfo.setStationClassification(site.getStationClassification()); - supStationInfo.setGeneralApplicationType(site.getGeneralApplicationType()); - supStationInfo.setStationType(site.getSiteType()); - supStationInfo.setStationStatus(site.getStatus()); - supStationInfo.setParkNums(site.getParkingSpace()); - supStationInfo.setStationLat(new BigDecimal(site.getLat()).setScale(6, RoundingMode.DOWN)); - supStationInfo.setStationLng(new BigDecimal(site.getLon()).setScale(6, RoundingMode.DOWN)); - supStationInfo.setSiteGuide(site.getGuide()); - supStationInfo.setConstruction(site.getConstructionSite() == 0 ? ConstructionEnum.OTHER.getType() : site.getConstructionSite()); - supStationInfo.setPictures(StringUtils.isNotEmpty(site.getImgUrl()) ? Arrays.asList(site.getImgUrl().split(",")) : new ArrayList<>()); - - supStationInfo.setMatchCars(site.getVehicleDescription()); - if (org.springframework.util.StringUtils.hasLength(site.getSwapMatchCars())){ - supStationInfo.setSwapMatchCars(Arrays.asList(site.getSwapMatchCars().split(","))); - } - supStationInfo.setBusineHours(site.getStartServiceTime()); - supStationInfo.setRoundTheClock(site.getRoundTheClock()); - supStationInfo.setParkType(site.getParkType()); - supStationInfo.setParkFee("{\"rules\":"+site.getParkFee()+","+"\"freeDuration\":"+site.getParkFeeFree()+"}"); - supStationInfo.setElectricityType(site.getElectricityType()); - supStationInfo.setBusinessExpandType(site.getBusinessExpandType()); - supStationInfo.setCapacity(site.getCapacity()); - supStationInfo.setRatedPower(site.getRatedPower()); - supStationInfo.setPeriodFee(site.getPeriodFee()); - supStationInfo.setOfficialRunTime(site.getOfficialRunTime()); - supStationInfo.setStationOrientation(site.getStationOrientation()); - supStationInfo.setStationArea(site.getStationArea()); - supStationInfo.setHavePerson(site.getHavePerson()); - supStationInfo.setVideoMonitor(site.getVideoMonitor()); - if (StringUtils.isNotEmpty(site.getSupportingFacilities())){ - String[] split = site.getSupportingFacilities().split(","); - List<Integer> collect = Arrays.stream(split).map(Integer::parseInt).collect(Collectors.toList()); - supStationInfo.setSupportingFacilities(collect); - } - supStationInfo.setPrinterFlag(site.getPrinterFlag()); - supStationInfo.setBarrierFlag(site.getBarrierFlag()); - supStationInfo.setParkingLockFlag(site.getParkingLockFlag()); - supStationInfo.setEquipmentInfos(buildEquipmentInfo(site.getId(), tChargingPiles, chargingGunList)); -// supStationInfo.setSwapEquipmentInfos(); - supStationInfo.setElectricityFee("{"+site.getElectricityFee()+"}"); - supStationInfo.setEquipmentOwnerName(site.getEquipmentOwnerName()); - supStationInfo.setResidentNo(site.getResidentNo()); - supStationInfo.setSupplyType(site.getSupplyType()); - supStationInfo.setWattHourMeterNo(site.getWattHourMeterNo()); - supStationInfo.setForwardPower(site.getForwardPower()); - supStationInfo.setServiceFee("{"+site.getServiceFee()+"}"); - supStationInfo.setRecordUniqueNo(site.getRecordUniqueNo()); - BaseResult baseResult = new BaseResult(); - SupStationInfoResult supStationInfoResult = new SupStationInfoResult(); - supStationInfoResult.setSupStationInfo(supStationInfo); - tcecSuperviseUtil.superviseNotificationStationInfo(supStationInfoResult); - return R.ok(baseResult); - } // // // /** -- Gitblit v1.7.1