From 9cf000a2d919558f1d95fd3d480b2fba147956ef Mon Sep 17 00:00:00 2001 From: Lemon Date: Fri, 19 Apr 2024 11:15:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=20=E9=9D=92=E6=B5=B7?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=8E=A8=E9=80=81=E7=AB=99=E7=82=B9=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E5=8A=9F=E7=8E=87=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thirdparty/qinghai/QingHaiController.java | 151 ++++++++++++++++++ .../thirdparty/common/CommonService.java | 31 +++- .../platform/ThirdPartyPlatformService.java | 15 +- .../service/QingHaiPlatformServiceImpl.java | 7 +- 4 files changed, 190 insertions(+), 14 deletions(-) create mode 100644 jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/qinghai/QingHaiController.java diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/qinghai/QingHaiController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/qinghai/QingHaiController.java new file mode 100644 index 000000000..d6481672e --- /dev/null +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/thirdparty/qinghai/QingHaiController.java @@ -0,0 +1,151 @@ +package com.jsowell.web.controller.thirdparty.qinghai; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.jsowell.common.annotation.Anonymous; +import com.jsowell.common.core.controller.BaseController; +import com.jsowell.common.response.RestApiResponse; +import com.jsowell.common.util.JWTUtils; +import com.jsowell.pile.domain.ThirdPartyPlatformConfig; +import com.jsowell.pile.dto.QueryStartChargeDTO; +import com.jsowell.pile.dto.QueryStationInfoDTO; +import com.jsowell.pile.service.ThirdPartyPlatformConfigService; +import com.jsowell.pile.thirdparty.CommonParamsDTO; +import com.jsowell.thirdparty.lianlian.common.CommonResult; +import com.jsowell.thirdparty.platform.ThirdPartyPlatformService; +import com.jsowell.thirdparty.platform.util.Cryptos; +import com.jsowell.thirdparty.platform.util.Encodes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +/** + * 青海平台Controller + * + * @author Lemon + * @Date 2024/4/18 13:46:26 + */ +@Anonymous +@RestController +@RequestMapping("/qinghai") +public class QingHaiController extends BaseController { + + @Autowired + @Qualifier("qingHaiPlatformServiceImpl") + private ThirdPartyPlatformService qingHaiPlatformServiceImpl; + + @Autowired + private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService; + + + /** + * 获取token接口 + */ + @PostMapping("/v1/query_token") + public CommonResult queryToken(@RequestBody CommonParamsDTO dto) { + logger.info("青海平台请求令牌 params:{}", JSON.toJSONString(dto)); + try { + // Map map = lianLianService.generateToken(dto); + Map map = qingHaiPlatformServiceImpl.queryToken(dto); + logger.info("青海平台请求令牌 result:{}", JSON.toJSONString(map)); + return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("获取token接口 异常"); + return CommonResult.failed("获取token发生异常"); + } + } + + /** + * 查询充电站信息 + * @param dto + */ + @RequestMapping("/v1/query_stations_info") + public CommonResult query_stations_info(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("青海平台查询充电站信息 params:{}", JSON.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 查询配置信息 + ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); + String operatorSecret = platformConfig.getOperatorSecret(); + String dataString = dto.getData(); + String dataSecret = platformConfig.getDataSecret(); + String dataSecretIV = platformConfig.getDataSecretIv(); + + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStationInfoDTO queryStationInfoDTO = JSONObject.parseObject(dataStr, QueryStationInfoDTO.class); + queryStationInfoDTO.setOperatorId(dto.getOperatorID()); + Map map = qingHaiPlatformServiceImpl.queryStationsInfo(queryStationInfoDTO); + return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("青海平台查询充电站信息 error", e); + } + return CommonResult.failed("查询充电站信息异常"); + } + + /** + * 查询业务策略信息 + * @param dto + */ + @RequestMapping("/v1/query_equip_business_policy") + public CommonResult query_equip_business_policy(HttpServletRequest request, @RequestBody CommonParamsDTO dto) { + logger.info("青海平台查询业务策略信息 params:{}", JSON.toJSONString(dto)); + try { + // 校验令牌 + String token = request.getHeader("Authorization"); + if (!JWTUtils.checkThirdPartyToken(token)) { + // 校验失败 + return CommonResult.failed("令牌校验错误"); + } + // 查询配置信息 + ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID()); + String operatorSecret = platformConfig.getOperatorSecret(); + String dataString = dto.getData(); + String dataSecret = platformConfig.getDataSecret(); + String dataSecretIV = platformConfig.getDataSecretIv(); + + // 解密data + byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIV.getBytes()); + String dataStr = new String(plainText, StandardCharsets.UTF_8); + // 转换成相应对象 + QueryStartChargeDTO queryStartChargeDTO = JSONObject.parseObject(dataStr, QueryStartChargeDTO.class); + queryStartChargeDTO.setOperatorId(dto.getOperatorID()); + Map map = qingHaiPlatformServiceImpl.queryEquipBusinessPolicy(queryStartChargeDTO); + return CommonResult.success(0, "查询业务策略信息成功!", map.get("Data"), map.get("Sig")); + } catch (Exception e) { + logger.error("青海平台查询业务策略信息 error", e); + } + return CommonResult.failed("查询业务策略信息异常"); + } + + /** + * 推送站点功率 + * @param stationIds + * @return + */ + @PostMapping("/pushStationPower") + public RestApiResponse pushStationPower(List stationIds) { + RestApiResponse response = null; + try { + String result = qingHaiPlatformServiceImpl.notificationPowerInfo(stationIds); + response = new RestApiResponse<>(result); + }catch (Exception e) { + logger.error("青海平台推送站点功率 error", e); + } + logger.info("青海平台推送站点功率 result:{}", response); + return response; + } + +} diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java index 6ab013c87..089086271 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/common/CommonService.java @@ -179,10 +179,11 @@ public class CommonService { // 海南 result = haiNanChargeService.pushStationInfoV2(dto); } - // if (StringUtils.equals(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode(), dto.getThirdPartyType())) { - // // 青海平台 - // qingHaiPlatformService. - // } + if (StringUtils.equals(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode(), dto.getThirdPartyType())) { + // 青海平台 + insertInfo2DataBase(dto); + result = dto.getThirdPartyType() + ":" + "OK"; + } finalResult.append(result).append("\n"); } return finalResult.toString(); @@ -319,8 +320,24 @@ public class CommonService { if (StringUtils.equals(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode(), thirdPartyType)) { // 青海省平台 String result = qingHaiPlatformService.notificationStationStatus(pileConnectorCode, changedStatus); - log.info("推送甬城泊车平台设备状态变化推送 pileConnectorCode:{}, changedStatus:{}, result:{}" + log.info("推送青海平台设备状态变化推送 pileConnectorCode:{}, changedStatus:{}, result:{}" , pileConnectorCode, changedStatus, result); + // 先判断缓存中是否有数据 + String redisKey = CacheConstants.JIANGSU_PUSH_PILE_STATUS + pileConnectorCode; + Object cacheObject = redisCache.getCacheObject(redisKey); + + if (StringUtils.equals(connectorStatus, "03")) { + // 充电状态, 查出订单信息 + OrderBasicInfo orderInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode); + if (orderInfo == null) { + return; + } + // 如果缓存有数据,证明上次推送未超过2分钟,不予推送,若缓存中无数据,说明需要推送 + if (cacheObject == null) { + String pushResult = qingHaiPlatformService.notificationEquipChargeStatus(orderInfo.getOrderCode()); + redisCache.setCacheObject(redisKey, realTimeMonitorData, 2, TimeUnit.MINUTES); + } + } } } @@ -394,6 +411,10 @@ public class CommonService { // log.info("甬城泊车平台 推送充电订单信息 result:{}", result); } } + if (StringUtils.equals(ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode(), thirdPartyType)) { + // 青海平台 + qingHaiPlatformService.notificationChargeOrderInfo(orderBasicInfo.getOrderCode()); + } } } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java index c2fac10c0..e17cc5a02 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java @@ -17,10 +17,7 @@ import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; import com.jsowell.thirdparty.lianlian.vo.LianLianResultVO; import java.nio.charset.StandardCharsets; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; /** * 第三方平台对接需要的api集合 @@ -328,6 +325,15 @@ public interface ThirdPartyPlatformService { throw new UnsupportedOperationException("This method is not yet implemented"); } + /** + * 推送充换电站实时功率 + * @param stationIds + * @return + */ + default String notificationPowerInfo(List stationIds) { + throw new UnsupportedOperationException("This method is not yet implemented"); + } + // -------------------------------------- 以下是公用方法 --------------------------------------- // /** * 从联联平台获取令牌 @@ -458,4 +464,5 @@ public interface ThirdPartyPlatformService { return StringUtils.equals(sig, sign); } + } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/qinghai/service/QingHaiPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/qinghai/service/QingHaiPlatformServiceImpl.java index 5cfd31b40..f56536349 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/qinghai/service/QingHaiPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/qinghai/service/QingHaiPlatformServiceImpl.java @@ -18,10 +18,7 @@ import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.domain.*; -import com.jsowell.pile.dto.QueryConnectorListDTO; -import com.jsowell.pile.dto.QueryEquipChargeStatusDTO; -import com.jsowell.pile.dto.QueryStartChargeDTO; -import com.jsowell.pile.dto.QueryStationInfoDTO; +import com.jsowell.pile.dto.*; import com.jsowell.pile.service.*; import com.jsowell.pile.thirdparty.ZDLEquipmentInfo; import com.jsowell.pile.thirdparty.ZDLStationInfo; @@ -96,7 +93,7 @@ public class QingHaiPlatformServiceImpl implements ThirdPartyPlatformService { // 平台类型 private final String platformType = ThirdPlatformTypeEnum.QING_HAI_PLATFORM.getTypeCode(); - + /** * 查询站点信息 query_stations_info