浏览代码

支持互联互通多平台改造

skyline 1 年之前
父节点
当前提交
cb0999cd23

+ 4 - 1
common/src/main/java/com/kym/common/utils/PlatformAesUtil.java

@@ -2,6 +2,7 @@ package com.kym.common.utils;
 
 
 import com.kym.entity.admin.Platform;
+import lombok.NoArgsConstructor;
 import org.apache.tomcat.util.codec.binary.Base64;
 
 import javax.crypto.Cipher;
@@ -18,6 +19,7 @@ import java.util.logging.Logger;
  *
  * @author skyline
  */
+@NoArgsConstructor
 public class PlatformAesUtil {
 
     //编码方式
@@ -29,8 +31,9 @@ public class PlatformAesUtil {
 
     static Platform config;
 
-    public PlatformAesUtil(Platform config) {
+    public static PlatformAesUtil getUtil(Platform config) {
         PlatformAesUtil.config = config;
+        return new PlatformAesUtil();
     }
 
     /**

+ 0 - 48
entity/src/main/java/com/kym/entity/admin/ConnectorPlatformRelation.java

@@ -1,48 +0,0 @@
-package com.kym.entity.admin;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.kym.entity.BaseEntity;
-import java.io.Serializable;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * <p>
- * 充电桩接口(枪)互联互通平台关联表
- * </p>
- *
- * @author skyline
- * @since 2024-12-20
- */
-@Getter
-@Setter
-@TableName("t_connector_platform_relation")
-public class ConnectorPlatformRelation extends BaseEntity {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 公司id
-     */
-    private Long companyId;
-
-    /**
-     * 站点id
-     */
-    private String stationId;
-
-    /**
-     * 充电桩序列号
-     */
-    private String equipmentId;
-
-    /**
-     * 充电桩接口序列号
-     */
-    private String connectorId;
-
-    /**
-     * 平台名称:EN_PLUS(驿普乐氏),LONGSHINE(朗新)
-     */
-    private String platformName;
-}

+ 4 - 1
entity/src/main/java/com/kym/entity/admin/EquipmentRelation.java

@@ -45,7 +45,10 @@ public class EquipmentRelation extends BaseEntity implements Serializable {
      * 充电枪口编号
      */
     private String connectorId;
-
+    /**
+     * 平台名称
+     */
+    private String platformName;
     /**
      * 停车位编号
      */

+ 1 - 1
entity/src/main/java/com/kym/entity/common/RedisKeys.java

@@ -6,7 +6,7 @@ package com.kym.entity.common;
  * @date 2023-07-31 18:26
  */
 public interface RedisKeys {
-    String EN_PLUS_TOKEN = "EN_PLUS_TOKEN";
+    String EN_PLUS_TOKEN = "EN_PLUS_TOKEN:";
     String EN_PLUS_SASS_TOKEN = "EN_PLUS_SASS_TOKEN";
     String OFFLINE = "OFFLINE:";
     String OFFLINE_EXPIRED = "OFFLINE_EXPIRED:";

+ 0 - 16
mapper/src/main/java/com/kym/mapper/admin/ConnectorPlatformRelationMapper.java

@@ -1,16 +0,0 @@
-package com.kym.mapper.admin;
-
-import com.kym.entity.admin.ConnectorPlatformRelation;
-import com.kym.mapper.mybatisplus.MyBaseMapper;
-
-/**
- * <p>
- * 充电桩接口(枪)互联互通平台关联表 Mapper 接口
- * </p>
- *
- * @author skyline
- * @since 2024-12-20
- */
-public interface ConnectorPlatformRelationMapper extends MyBaseMapper<ConnectorPlatformRelation> {
-
-}

+ 0 - 19
mapper/src/main/resources/mappers/admin/ConnectorPlatformRelationMapper.xml

@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.kym.mapper.admin.ConnectorPlatformRelationMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.kym.entity.admin.ConnectorPlatformRelation">
-        <result column="company_id" property="companyId" />
-        <result column="station_id" property="stationId" />
-        <result column="equipment_id" property="equipmentId" />
-        <result column="connector_id" property="connectorId" />
-        <result column="platform_name" property="platformName" />
-    </resultMap>
-
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        company_id, station_id, equipment_id, connector_id, platform_name
-    </sql>
-
-</mapper>

+ 11 - 11
miniapp/src/main/java/com/kym/miniapp/controller/ChargerController.java

@@ -12,7 +12,6 @@ import com.kym.entity.miniapp.ChargeOrder;
 import com.kym.entity.miniapp.queryParams.OrderQueryParams;
 import com.kym.service.admin.StationService;
 import com.kym.service.enplus.EnNotifyService;
-import com.kym.service.enplus.EnPlusService;
 import com.kym.service.miniapp.ChargeOrderService;
 import com.kym.service.miniapp.ChargeService;
 import lombok.SneakyThrows;
@@ -35,8 +34,6 @@ public class ChargerController {
 
     private final StationService stationService;
 
-    private final EnPlusService enPlusService;
-
     private final ChargeService chargeService;
 
     private final ChargeOrderService chargeOrderService;
@@ -46,9 +43,10 @@ public class ChargerController {
     private final WxConfig wxConfig;
 
 
-    public ChargerController(StationService stationService, EnPlusService enPlusService, ChargeService chargeService, ChargeOrderService chargeOrderService, EnNotifyService enNotifyService, WxConfig wxConfig) {
+    public ChargerController(StationService stationService, ChargeService chargeService,
+                             ChargeOrderService chargeOrderService,
+                             EnNotifyService enNotifyService, WxConfig wxConfig) {
         this.stationService = stationService;
-        this.enPlusService = enPlusService;
         this.chargeService = chargeService;
         this.chargeOrderService = chargeOrderService;
         this.enNotifyService = enNotifyService;
@@ -199,11 +197,12 @@ public class ChargerController {
     //====================================================以下是EN+推送接口==============================================================
 
     /**
-     * EN+场站设备状态变化推送
+     * 【互联互通平台】推送场站设备状态变化
      *
      * @param json
      * @return 0:接收 1:丢弃/忽略,不需要重试
      */
+    @ApiLog("推送场站设备状态变化")
     @PostMapping("/{platformName}/notification_stationStatus")
     //todo 通知en+更新推送地址,加上platformName
     EnResponse notificationStationStatus(@PathVariable(value = "platformName", required = false) String platformName, @RequestBody JSONObject json) {
@@ -211,30 +210,31 @@ public class ChargerController {
     }
 
     /**
-     * EN+推送启动充电结果
+     * 【互联互通平台】推送启动充电结果
      *
      * @param json
      * @return StartChargeSeq SuccStat 0:成功 1:失败  FailReason 0:无 1:接收失败
      */
-    @ApiLog("EN+推送启动充电结果")
+    @ApiLog("推送启动充电结果")
     @PostMapping("/{platformName}/notification_start_charge_result")
     EnResponse notificationStartChargeResult(@PathVariable(value = "platformName", required = false) String platformName, @RequestBody JSONObject json) {
         return new EnResponse(enNotifyService.handleNotificationStartChargeResult(platformName, json));
     }
 
     /**
-     * EN+推送充电状态
+     * 【互联互通平台】推送充电状态
      *
      * @param json
      * @return
      */
+    @ApiLog("推送充电状态")
     @PostMapping("/{platformName}/notification_equip_charge_status")
     EnResponse notificationEquipChargeStatus(@PathVariable(value = "platformName", required = false) String platformName, @RequestBody JSONObject json) {
         return new EnResponse(enNotifyService.handleNotificationEquipChargeStatus(platformName, json));
     }
 
     /**
-     * EN+推送停止充电结果
+     * 【互联互通平台】推送停止充电结果
      *
      * @param json
      * @return
@@ -246,7 +246,7 @@ public class ChargerController {
     }
 
     /**
-     * EN+推送充电订单信息
+     * 【互联互通平台】推送充电订单信息
      *
      * @param json
      * @return

+ 0 - 16
service/src/main/java/com/kym/service/admin/ConnectorPlatformRelationService.java

@@ -1,16 +0,0 @@
-package com.kym.service.admin;
-
-import com.kym.entity.admin.ConnectorPlatformRelation;
-import com.kym.service.mybatisplus.MyBaseService;
-
-/**
- * <p>
- * 充电桩接口(枪)互联互通平台关联表 服务类
- * </p>
- *
- * @author skyline
- * @since 2024-12-20
- */
-public interface ConnectorPlatformRelationService extends MyBaseService<ConnectorPlatformRelation> {
-
-}

+ 0 - 20
service/src/main/java/com/kym/service/admin/impl/ConnectorPlatformRelationServiceImpl.java

@@ -1,20 +0,0 @@
-package com.kym.service.admin.impl;
-
-import com.kym.entity.admin.ConnectorPlatformRelation;
-import com.kym.mapper.admin.ConnectorPlatformRelationMapper;
-import com.kym.service.admin.ConnectorPlatformRelationService;
-import com.kym.service.mybatisplus.MyBaseServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- * 充电桩接口(枪)互联互通平台关联表 服务实现类
- * </p>
- *
- * @author skyline
- * @since 2024-12-20
- */
-@Service
-public class ConnectorPlatformRelationServiceImpl extends MyBaseServiceImpl<ConnectorPlatformRelationMapper, ConnectorPlatformRelation> implements ConnectorPlatformRelationService {
-
-}

+ 0 - 1
service/src/main/java/com/kym/service/admin/impl/InvoiceDetailServiceImpl.java

@@ -139,7 +139,6 @@ public class InvoiceDetailServiceImpl extends MPJBaseServiceImpl<InvoiceDetailMa
                     .setBuyerInformation(fapiaoApplications.getFapiao_information().get(0).getBuyer_information())
                     .setExtraInformation(fapiaoApplications.getFapiao_information().get(0).getExtra_information())
                     .setItems(fapiaoApplications.getFapiao_information().get(0).getItems());
-            // 手动切换数据源
             removeByMap(Map.of("apply_id", applyId));
             save(invoiceDetail);
         }

+ 2 - 0
service/src/main/java/com/kym/service/admin/impl/PlatformServiceImpl.java

@@ -1,5 +1,6 @@
 package com.kym.service.admin.impl;
 
+import com.baomidou.dynamic.datasource.annotation.DS;
 import com.kym.entity.admin.Platform;
 import com.kym.mapper.admin.PlatformMapper;
 import com.kym.service.admin.PlatformService;
@@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
  * @since 2024-12-19
  */
 @Service
+@DS("db-admin")
 public class PlatformServiceImpl extends MyBaseServiceImpl<PlatformMapper, Platform> implements PlatformService {
 
 }

+ 19 - 8
service/src/main/java/com/kym/service/admin/impl/StationServiceImpl.java

@@ -17,6 +17,7 @@ import com.kym.entity.admin.vo.LocalStationVo;
 import com.kym.entity.admin.vo.StationVo;
 import com.kym.entity.enplus.EnStationStatsInfo;
 import com.kym.entity.enplus.EnStationStatusInfo;
+import com.kym.entity.enplus.response.EnResponse;
 import com.kym.mapper.admin.StationMapper;
 import com.kym.service.admin.*;
 import com.kym.service.cache.KymCache;
@@ -93,8 +94,8 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                     "LastQueryTime":""
                 }
                 """.formatted(pageNum, pageSize);
-        var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_INFO.getApi(), enPlusService.buildParams(platformName, param));
-        var enStations = JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_INFO.getApi(), enPlusService.buildPlatformParams(platformName, param));
+        var enStations = parsePlatformResponseData(response, platformName);
         var stationList = enStations.getJSONArray("StationInfos").toJavaList(StationVo.class);
         // 我方station表数据
         var stations = list();
@@ -112,6 +113,16 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
         return stationList;
     }
 
+    /**
+     * 解析平台返回数据为JSONObject
+     * @param response
+     * @param platformName
+     * @return
+     */
+    JSONObject parsePlatformResponseData(EnResponse response, String platformName){
+        return JSONObject.parseObject(PlatformAesUtil.getUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+    }
+
     /**
      * 查询互联互通平台充电站信息
      *
@@ -128,8 +139,8 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                     "LastQueryTime":""
                 }
                 """.formatted(pageNum, pageSize);
-        var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_INFO.getApi(), enPlusService.buildParams(platformName, param));
-        var enStations = JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_INFO.getApi(), enPlusService.buildPlatformParams(platformName, param));
+        var enStations = parsePlatformResponseData(response, platformName);
         var stationList = enStations.getJSONArray("StationInfos").toJavaList(StationVo.class);
         // 我方station表数据
         var stations = list();
@@ -227,8 +238,8 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                         "StationIDs":["%s"]
                     }
                     """.formatted(String.join("\",\"", ids));
-            var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_STATUS.getApi(), enPlusService.buildParams(platformName, param));
-            var enStationStatus = JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+            var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_STATUS.getApi(), enPlusService.buildPlatformParams(platformName, param));
+            var enStationStatus = JSONObject.parseObject(PlatformAesUtil.getUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
             res.addAll(enStationStatus.getJSONArray("StationStatusInfos").toJavaList(EnStationStatusInfo.class));
         });
         return res;
@@ -253,9 +264,9 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                 }
                 """.formatted(stationId, startTime, endTime);
         var platformName = PlatformCache.INSTANCE.getPlatformNameByStationId(stationId);
-        var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_STATS.getApi(), enPlusService.buildParams(platformName, param));
+        var response = enPlusService.platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STATION_STATS.getApi(), enPlusService.buildPlatformParams(platformName, param));
         // TODO: 2023-08-12 包装成自己的数据格式
-        var enStationStats = JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var enStationStats = parsePlatformResponseData(response, platformName);
         return enStationStats.getJSONObject("StationStats").toJavaObject(EnStationStatsInfo.class);
     }
 

+ 23 - 3
service/src/main/java/com/kym/service/cache/KymCache.java

@@ -1,13 +1,17 @@
 package com.kym.service.cache;
 
 import cn.hutool.extra.spring.SpringUtil;
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
 import com.kym.entity.admin.ConnectorInfo;
 import com.kym.entity.admin.EquipmentRelation;
+import com.kym.entity.admin.Platform;
 import com.kym.entity.admin.Station;
 import com.kym.entity.common.RedisKeys;
 import com.kym.service.admin.ConnectorInfoService;
 import com.kym.service.admin.EquipmentRelationService;
+import com.kym.service.admin.PlatformService;
 import com.kym.service.admin.StationService;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.event.ApplicationStartedEvent;
 import org.springframework.context.ApplicationListener;
 import org.springframework.data.redis.core.StringRedisTemplate;
@@ -172,19 +176,27 @@ public enum KymCache {
         private static final StringRedisTemplate redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);
 
         private final EquipmentRelationService equipmentRelationService;
+        private final PlatformService platformService;
         private final StationService stationService;
-
         private final ConnectorInfoService connectorInfoService;
 
 
-        private KymCacheInjector(EquipmentRelationService equipmentRelationService, StationService stationService, ConnectorInfoService connectorInfoService) {
+
+        @Value("${spring.profiles.active}")
+        public String env;
+
+
+        private KymCacheInjector(EquipmentRelationService equipmentRelationService, StationService stationService, ConnectorInfoService connectorInfoService, PlatformService platformService) {
             this.equipmentRelationService = equipmentRelationService;
             this.stationService = stationService;
             this.connectorInfoService = connectorInfoService;
+            this.platformService = platformService;
         }
 
         @Override
         public void onApplicationEvent(ApplicationStartedEvent event) {
+            // 手动切换数据源
+            DynamicDataSourceContextHolder.push("db-admin");
             // 将数据库数据缓存到redis
             var equipmentRelations = equipmentRelationService.list();
 
@@ -202,6 +214,14 @@ public enum KymCache {
 
             var connectorId2Status = connectorInfoService.list().stream().collect(Collectors.toMap(ConnectorInfo::getConnectorId, ConnectorInfo::getStatus));
             KymCache.INSTANCE.putConnectorId2Status(connectorId2Status);
+
+
+            // 缓存平台数据
+            PlatformCache.INSTANCE.putPlatformName2Config(platformService.lambdaQuery().eq(Platform::getEnv, env).list().stream().collect(Collectors.toMap(Platform::getPlatformName, platform -> platform)));
+            PlatformCache.INSTANCE.putConnectorId2PlatformName(equipmentRelations.stream().collect(Collectors.toMap(EquipmentRelation::getConnectorId, EquipmentRelation::getPlatformName)));
+            PlatformCache.INSTANCE.putStationId2PlatformName(equipmentRelations.stream().collect(Collectors.toMap(EquipmentRelation::getStationId, EquipmentRelation::getPlatformName)));
+
+            DynamicDataSourceContextHolder.poll();
         }
     }
-}
+}

+ 0 - 38
service/src/main/java/com/kym/service/cache/PlatformCache.java

@@ -1,21 +1,10 @@
 package com.kym.service.cache;
 
-import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.kym.common.utils.CommUtil;
-import com.kym.entity.admin.ConnectorPlatformRelation;
 import com.kym.entity.admin.Platform;
-import com.kym.service.admin.ConnectorPlatformRelationService;
-import com.kym.service.admin.PlatformService;
-import org.jetbrains.annotations.NotNull;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.event.ApplicationStartedEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.stereotype.Component;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Collectors;
 
 /**
  * 平台配置缓存
@@ -90,31 +79,4 @@ public enum PlatformCache {
         return PLATFORM_CONFIG_MAPPING.get(platformName);
     }
 
-    @Component
-    public static class PlatformCacheInjector implements ApplicationListener<ApplicationStartedEvent> {
-        // private static final StringRedisTemplate redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);
-        private final PlatformService platformService;
-
-        private final ConnectorPlatformRelationService connectorPlatformRelationService;
-
-        @Value("${spring.profiles.active}")
-        public String env;
-
-        public PlatformCacheInjector(PlatformService platformService, ConnectorPlatformRelationService connectorPlatformRelationService) {
-            this.platformService = platformService;
-            this.connectorPlatformRelationService = connectorPlatformRelationService;
-        }
-
-        @Override
-        public void onApplicationEvent(@NotNull ApplicationStartedEvent event) {
-
-            // 手动切换数据源
-            DynamicDataSourceContextHolder.push("db-admin");
-            // 缓存数据
-            PlatformCache.INSTANCE.putPlatformName2Config(platformService.lambdaQuery().eq(Platform::getEnv, env).list().stream().collect(Collectors.toMap(Platform::getPlatformName, platform -> platform)));
-            PlatformCache.INSTANCE.putConnectorId2PlatformName(connectorPlatformRelationService.list().stream().collect(Collectors.toMap(ConnectorPlatformRelation::getConnectorId, ConnectorPlatformRelation::getPlatformName)));
-            PlatformCache.INSTANCE.putStationId2PlatformName(connectorPlatformRelationService.list().stream().collect(Collectors.toMap(ConnectorPlatformRelation::getStationId, ConnectorPlatformRelation::getPlatformName)));
-            DynamicDataSourceContextHolder.poll();
-        }
-    }
 }

+ 1 - 1
service/src/main/java/com/kym/service/enplus/EnPlusService.java

@@ -16,7 +16,7 @@ public interface EnPlusService {
     String queryPlatformToken(String platformName);
 
 
-    String buildParams(String platformName, String params);
+    String buildPlatformParams(String platformName, String params);
 
 
     String signValidation(String platformName, JSONObject json);

+ 35 - 24
service/src/main/java/com/kym/service/enplus/impl/EnPlusServiceImpl.java

@@ -92,13 +92,24 @@ public class EnPlusServiceImpl implements EnPlusService {
             LOGGER.error(":url:{}\n params:{}\ntoken:{}\n返回信息:{}", url, params, token, response);
             if (4002 == response.getRet()) {
                 // 如果返回Ret=4002,token错误的情况下,删除redis中的token,如果是预约订单则将此订单设置为延迟启动
-                redisTemplate.delete(RedisKeys.EN_PLUS_TOKEN);
+                redisTemplate.delete(RedisKeys.EN_PLUS_TOKEN + platformName);
                 throw new BusinessException(ResponseEnum.EN_PLUS_TOKEN_EXCEPTION);
             }
             throw new BusinessException(ResponseEnum.EN_PLUS_API_EXCEPTION);
         }
     }
 
+    /**
+     * 解析平台返回数据为JSONObject
+     *
+     * @param response
+     * @param platformName
+     * @return
+     */
+    JSONObject parsePlatformResponseData(EnResponse response, String platformName) {
+        return JSONObject.parseObject(PlatformAesUtil.getUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+    }
+
 
     /**
      * 查询平台互联互通token
@@ -109,10 +120,10 @@ public class EnPlusServiceImpl implements EnPlusService {
     @Override
     public String queryPlatformToken(String platformName) {
         LOGGER.info("查询互联互通平台token:{}", platformName);
-        var token = redisTemplate.opsForValue().get(RedisKeys.EN_PLUS_TOKEN);
+        var token = redisTemplate.opsForValue().get(RedisKeys.EN_PLUS_TOKEN + platformName);
         if (CommUtil.isNotEmptyAndNull(token)) {
-            // todo 不同平台不同key
-            LOGGER.debug("从缓存中查询到token:{},ttl:{}", token, redisTemplate.getExpire(RedisKeys.EN_PLUS_TOKEN));
+            // 不同平台不同key
+            LOGGER.debug("从缓存中查询到token:{},ttl:{}", token, redisTemplate.getExpire(RedisKeys.EN_PLUS_TOKEN + platformName));
             return token;
         }
         var data = """
@@ -122,17 +133,17 @@ public class EnPlusServiceImpl implements EnPlusService {
                 }
                 """.formatted(OperatorId, OperatorSecret);
 
-        var requestParams = buildParams(platformName, data);
+        var requestParams = buildPlatformParams(platformName, data);
 
         var response = enGetToken(EnPlusApi.EN_PLUS_QUERY_TOKEN.getApi(), requestParams);
 
         if (response != null && 0 == response.getRet()) {
             // 解密Data获取token
-            var platformRespQueryToken = JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()), EnRespQueryToken.class);
+            var jsonObject = parsePlatformResponseData(response, platformName);
+            var platformRespQueryToken = parse(jsonObject.getString("Data"), EnRespQueryToken.class);
             LOGGER.debug("{}接口AccessToken:{}", platformName, platformRespQueryToken.toString());
-            // 缓存token,有效期7天(我们这里每次请求en+获取token的有效期并不是从7天开始,有效期是在en+的剩余有效时间)
-            // todo 不同平台不同key
-            redisTemplate.opsForValue().set(RedisKeys.EN_PLUS_TOKEN, platformRespQueryToken.getAccessToken(), platformRespQueryToken.getTokenAvailableTime(), TimeUnit.SECONDS);
+            // 缓存token不同平台不同key,有效期7天(我们这里每次请求en+获取token的有效期并不是从7天开始,有效期是在en+的剩余有效时间)
+            redisTemplate.opsForValue().set(RedisKeys.EN_PLUS_TOKEN + platformName, platformRespQueryToken.getAccessToken(), platformRespQueryToken.getTokenAvailableTime(), TimeUnit.SECONDS);
             return platformRespQueryToken.getAccessToken();
         } else {
             // 记录错误码,返回错误信息
@@ -167,9 +178,9 @@ public class EnPlusServiceImpl implements EnPlusService {
      * @return
      */
     @Override
-    public String buildParams(String platformName, String params) {
+    public String buildPlatformParams(String platformName, String params) {
         // 使用DataSecret对data加密
-        var dataStr = new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).encrypt(params);
+        var dataStr = PlatformAesUtil.getUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).encrypt(params);
         // 时间戳
         var timeStamp = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN);
         // 自增序列
@@ -211,7 +222,7 @@ public class EnPlusServiceImpl implements EnPlusService {
         var sign = mac.digestHex(signString).toUpperCase();
         if (sign.equals(Sig)) {
             // 解密数据
-            return new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(Data);
+            return PlatformAesUtil.getUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(Data);
         } else {
             // 验签失败
             EnResponse enResponse = new EnResponse();
@@ -240,9 +251,9 @@ public class EnPlusServiceImpl implements EnPlusService {
                     "ConnectorID":"%s"
                 }
                 """.formatted(equipAuthSeq, connectorId);
-        var response = platformPost(platformName,EnPlusApi.EN_PLUS_QUERY_EQUIP_AUTH.getApi(), buildParams(platformName,param));
+        var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_AUTH.getApi(), buildPlatformParams(platformName, param));
 
-        return JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        return parsePlatformResponseData(response, platformName);
     }
 
 
@@ -263,8 +274,8 @@ public class EnPlusServiceImpl implements EnPlusService {
                     "ConnectorID":"%s"
                 }
                 """.formatted(equipBizSeq, connectorId);
-        var response = platformPost(platformName,EnPlusApi.EN_PLUS_QUERY_EQUIP_BUSINESS_POLICY.getApi(), buildParams(platformName,param));
-        return JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_BUSINESS_POLICY.getApi(), buildPlatformParams(platformName, param));
+        return parsePlatformResponseData(response, platformName);
     }
 
     /**
@@ -287,8 +298,8 @@ public class EnPlusServiceImpl implements EnPlusService {
                     "amount":"%d"
                 }
                 """.formatted(startChargeSeq, connectorId, qrCode, amount);
-        var response = platformPost(platformName,EnPlusApi.EN_PLUS_QUERY_START_CHARGE.getApi(), buildParams(platformName,param));
-        return JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_START_CHARGE.getApi(), buildPlatformParams(platformName, param));
+        return parsePlatformResponseData(response, platformName);
     }
 
     /**
@@ -305,8 +316,8 @@ public class EnPlusServiceImpl implements EnPlusService {
                     "StartChargeSeq":"%s"
                 }
                 """.formatted(startChargeSeq);
-        var response = platformPost(platformName,EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(), buildParams(platformName,param));
-        return JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(), buildPlatformParams(platformName, param));
+        return parsePlatformResponseData(response, platformName);
     }
 
     /**
@@ -325,8 +336,8 @@ public class EnPlusServiceImpl implements EnPlusService {
                     "amount":%d
                 }
                 """.formatted(startChargeSeq, amount);
-        var response = platformPost(platformName,EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(), buildParams(platformName,param));
-        return JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(), buildPlatformParams(platformName, param));
+        return parsePlatformResponseData(response, platformName);
     }
 
     /**
@@ -345,8 +356,8 @@ public class EnPlusServiceImpl implements EnPlusService {
                     "ConnectorID":"%s"
                 }
                 """.formatted(startChargeSeq, connectorId);
-        var response = platformPost(platformName,EnPlusApi.EN_PLUS_QUERY_STOP_CHARGE.getApi(), buildParams(platformName,param));
-        return JSONObject.parseObject(new PlatformAesUtil(PlatformCache.INSTANCE.getPlatformByName(platformName)).decrypt(response.getData()));
+        var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STOP_CHARGE.getApi(), buildPlatformParams(platformName, param));
+        return parsePlatformResponseData(response, platformName);
     }
 
 }

+ 3 - 2
service/src/main/java/com/kym/service/miniapp/impl/ChargeServiceImpl.java

@@ -193,7 +193,8 @@ public class ChargeServiceImpl implements ChargeService {
      */
     @Override
     @DSTransactional(rollbackFor = Exception.class)
-    public Map<String, String> queryStartCharge(Long userId, String connectorId, Long userRechargeRightsId, Long userCouponId, Boolean isBooking, LocalDateTime startTime, LocalDateTime endTime) {
+    public Map<String, String> queryStartCharge(Long userId, String connectorId, Long userRechargeRightsId, Long userCouponId,
+                                                Boolean isBooking, LocalDateTime startTime, LocalDateTime endTime) {
         var connectorId2StationId = getConnectorIdAndStationId(connectorId);
         connectorId = connectorId2StationId.get("connectorId");
         var stationId = connectorId2StationId.get("stationId");
@@ -570,7 +571,7 @@ public class ChargeServiceImpl implements ChargeService {
     @Override
     public EnBusinessPolicy queryEquipBusinessPolicy(String connectorId) {
         var equipBizSeq = OrderUtils.getOrderNo(enPlusConfig.getOperatorId());
-        var data = enPlusService.queryEquipBusinessPolicy(PlatformCache.INSTANCE.getPlatformNameByConnectorId(connectorId),equipBizSeq, connectorId);
+        var data = enPlusService.queryEquipBusinessPolicy(PlatformCache.INSTANCE.getPlatformNameByConnectorId(connectorId), equipBizSeq, connectorId);
         return data.toJavaObject(EnBusinessPolicy.class);
     }