Kaynağa Gözat

互联互通对接调试:EN_PLUS名称修改等

skyline 1 yıl önce
ebeveyn
işleme
94ff7fcbdd

+ 16 - 16
common/src/main/java/com/kym/common/constant/ResponseEnum.java

@@ -25,7 +25,7 @@ public enum ResponseEnum implements BusinessExceptionAssert {
     WX_MP_LOGIN_ERROR(301, "微信登录异常"),
 
     // 微信支付
-    WX_PAY_AMOUNT_ERROR(300001,"微信支付金额异常"),
+    WX_PAY_AMOUNT_ERROR(300001, "微信支付金额异常"),
 
 
     // 登录 权限
@@ -37,24 +37,24 @@ public enum ResponseEnum implements BusinessExceptionAssert {
     ORDER_IN_PROGRESS(20001, "用户有进行中的订单"),
     NO_ORDER_IN_PROGRESS(20002, "用户无进行中的订单"),
     INSUFFICIENT_USER_BALANCE(20003, "用户余额不足"),
-    EN_PLUS_EQUIP_AUTH_FAIL(20004, "设备认证失败"),
-    EN_PLUS_EQUIP_NOT_CONNECTED(20005, "设备未连接"),
-    EN_PLUS_ORDER_IS_PARKING(20006, "此订单为停车中"),
-    EN_PLUS_ORDER_CLOSED(20007, "此订单已关闭"),
-    EN_PLUS_EQUIP_CHECK_FAIL(20008, "设备检测失败"),
-    EN_PLUS_EQUIP_START_FAIL(20009, "设备启动充电失败"),
-    EN_PLUS_EQUIP_NOT_EXIST(20010, "设备不存在"),
-    EN_PLUS_EQUIP_OFFLINE(20011, "设备离线"),
-    EN_PLUS_EQUIP_STOP_FAIL(20012, "设备停止充电失败"),
-    EN_PLUS_EQUIP_EXIST_ORDER_UNFINISHED(20013, "设备存在未完成的订单"),
+    PLATFORM_EQUIP_AUTH_FAIL(20004, "设备认证失败"),
+    PLATFORM_EQUIP_NOT_CONNECTED(20005, "设备未连接"),
+    PLATFORM_ORDER_IS_PARKING(20006, "此订单为停车中"),
+    PLATFORM_ORDER_CLOSED(20007, "此订单已关闭"),
+    PLATFORM_EQUIP_CHECK_FAIL(20008, "设备检测失败"),
+    PLATFORM_EQUIP_START_FAIL(20009, "设备启动充电失败"),
+    PLATFORM_EQUIP_NOT_EXIST(20010, "设备不存在"),
+    PLATFORM_EQUIP_OFFLINE(20011, "设备离线"),
+    PLATFORM_EQUIP_STOP_FAIL(20012, "设备停止充电失败"),
+    PLATFORM_EQUIP_EXIST_ORDER_UNFINISHED(20013, "设备存在未完成的订单"),
     ORDER_IN_BOOKING(20014, "用户有预约中的订单"),
 
 
-    // EN+
-    EN_PLUS_API_EXCEPTION(90000, "接口数据异常"),
-    EN_PLUS_QUERY_TOKEN_ERROR(90001, "TOKEN获取异常"),
-    EN_PLUS_PUSH_SIGN_FAIL(90002, "推送数据验签失败"),
-    EN_PLUS_TOKEN_EXCEPTION(90003,"EN+TOKEN过期");
+    // 互联互通平台
+    PLATFORM__API_EXCEPTION(90000, "接口数据异常"),
+    PLATFORM_QUERY_TOKEN_ERROR(90001, "TOKEN获取异常"),
+    PLATFORM_PUSH_SIGN_FAIL(90002, "推送数据验签失败"),
+    PLATFORM_TOKEN_EXCEPTION(90003, "EN+TOKEN过期");
 
     private final Integer code;
     private final String message;

+ 1 - 1
miniapp/src/main/java/com/kym/miniapp/jobs/StartChargeDelayJob.java

@@ -101,7 +101,7 @@ public class StartChargeDelayJob implements DelayService<DelayChargeOrder> {
                         log.error("预约充电队列take异常", e);
                     } else {
                         log.info("预约启动充电失败,订单号:{}", threadLocal.get());
-                        if (e instanceof BusinessException && (ResponseEnum.EN_PLUS_TOKEN_EXCEPTION.getCode().equals(((BusinessException) e).getCode()))) {
+                        if (e instanceof BusinessException && (ResponseEnum.PLATFORM_TOKEN_EXCEPTION.getCode().equals(((BusinessException) e).getCode()))) {
                             if (retryList.contains(threadLocal.get())) {
                                 log.info("EN+ token异常,预约订单:{}已重试忽略", threadLocal.get());
                                 log.error(e.getMessage());

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

@@ -22,7 +22,7 @@ import com.kym.service.admin.*;
 import com.kym.service.cache.KymCache;
 import com.kym.service.cache.PlatformCache;
 import com.kym.service.mybatisplus.MyBaseServiceImpl;
-import com.kym.service.platform.CommonApi;
+import com.kym.service.platform.PlatformApi;
 import com.kym.service.platform.PlatformApiService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.aop.framework.AopContext;
@@ -94,7 +94,7 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                     "LastQueryTime":""
                 }
                 """.formatted(pageNum, pageSize);
-        var response = platformApiService.platformPost(platformName, CommonApi.EN_PLUS_QUERY_STATION_INFO.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
+        var response = platformApiService.platformPost(platformName, PlatformApi.PLATFORM_QUERY_STATION_INFO.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
         var enStations = parsePlatformResponseData(response, platformName);
         var stationList = enStations.getJSONArray("StationInfos").toJavaList(StationVo.class);
         // 我方station表数据
@@ -141,7 +141,7 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                     "LastQueryTime":""
                 }
                 """.formatted(pageNum, pageSize);
-        var response = platformApiService.platformPost(platformName, CommonApi.EN_PLUS_QUERY_STATION_INFO.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
+        var response = platformApiService.platformPost(platformName, PlatformApi.PLATFORM_QUERY_STATION_INFO.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
         var enStations = parsePlatformResponseData(response, platformName);
         var stationList = enStations.getJSONArray("StationInfos").toJavaList(StationVo.class);
         // 我方station表数据
@@ -251,7 +251,7 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                         "StationIDs":["%s"]
                     }
                     """.formatted(String.join("\",\"", String.join(",", platform2StationIds.get(platformName))));
-            var response = platformApiService.platformPost(platformName, CommonApi.EN_PLUS_QUERY_STATION_STATUS.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
+            var response = platformApiService.platformPost(platformName, PlatformApi.PLATFORM_QUERY_STATION_STATUS.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
             var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
             var enStationStatus = JSONObject.parseObject(PlatformAesUtil.decrypt(platform.getDataSecret(), platform.getDataSecretIv(), response.getData()));
             res.addAll(enStationStatus.getJSONArray("StationStatusInfos").toJavaList(PlatformStationStatusInfo.class));
@@ -278,7 +278,7 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
                 }
                 """.formatted(stationId, startTime, endTime);
         var platformName = PlatformCache.INSTANCE.getPlatformNameByStationId(stationId);
-        var response = platformApiService.platformPost(platformName, CommonApi.EN_PLUS_QUERY_STATION_STATS.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
+        var response = platformApiService.platformPost(platformName, PlatformApi.PLATFORM_QUERY_STATION_STATS.getApi(platformName), platformApiService.buildPlatformParams(platformName, param));
         // TODO: 2023-08-12 包装成自己的数据格式
         var enStationStats = parsePlatformResponseData(response, platformName);
         return enStationStats.getJSONObject("StationStats").toJavaObject(PlatformStationStatsInfo.class);

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

@@ -401,33 +401,33 @@ public class ChargeServiceImpl implements ChargeService {
                 LOGGER.error("设备启动充电失败:{}", startCharge);
                 switch (equipAuth.getIntValue("FailReason")) {
                     case 1 -> // 设备不存在
-                            throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_NOT_EXIST);
+                            throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_NOT_EXIST);
                     case 2 -> // 设备离线
                         // todo 设备离线,加入重试机制
-                            throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_OFFLINE);
+                            throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_OFFLINE);
                     case 3 -> // 存在未完成的订单
-                            throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_EXIST_ORDER_UNFINISHED);
+                            throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_EXIST_ORDER_UNFINISHED);
                     case 4 -> // 此订单为停车中
-                            throw new BusinessException(ResponseEnum.EN_PLUS_ORDER_IS_PARKING);
+                            throw new BusinessException(ResponseEnum.PLATFORM_ORDER_IS_PARKING);
                     case 5 -> // 此订单已关闭
-                            throw new BusinessException(ResponseEnum.EN_PLUS_ORDER_CLOSED);
+                            throw new BusinessException(ResponseEnum.PLATFORM_ORDER_CLOSED);
                     case 6 -> // 设备未插枪
-                            throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_NOT_CONNECTED);
+                            throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_NOT_CONNECTED);
                     case 7 -> // 预充金额存在且小于1元
                             throw new BusinessException(ResponseEnum.INSUFFICIENT_USER_BALANCE);
                 }
-                throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_START_FAIL);
+                throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_START_FAIL);
             }
         } else {
             // 设备认证失败
             LOGGER.error("设备认证失败:{}", equipAuth);
             switch (equipAuth.getIntValue("FailReason")) {
                 case 1 -> // 设备未插枪
-                        throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_NOT_CONNECTED);
+                        throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_NOT_CONNECTED);
                 case 2 -> // 设备检测失败
-                        throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_CHECK_FAIL);
+                        throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_CHECK_FAIL);
             }
-            throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_AUTH_FAIL);
+            throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_AUTH_FAIL);
         }
     }
 
@@ -551,7 +551,7 @@ public class ChargeServiceImpl implements ChargeService {
         if (data.containsKey("SuccStat") && data.getIntValue("SuccStat") != 0) {
             // 记录失败原因
             LOGGER.error("订单:{}停止充电失败,返回结果:{}", chargeOrder.getStartChargeSeq(), data);
-            throw new BusinessException(ResponseEnum.EN_PLUS_EQUIP_STOP_FAIL);
+            throw new BusinessException(ResponseEnum.PLATFORM_EQUIP_STOP_FAIL);
         }
         // 这里不更新订单状态,等待EN+推送停止充电结果信息再处理
 

+ 0 - 42
service/src/main/java/com/kym/service/platform/CommonApi.java

@@ -1,42 +0,0 @@
-package com.kym.service.platform;
-
-import com.kym.service.cache.PlatformCache;
-import lombok.AllArgsConstructor;
-import org.springframework.web.bind.annotation.RequestMethod;
-
-
-/**
- * @author skyline
- * @description EN+接口
- * @date 2023-07-29 12:33
- */
-@AllArgsConstructor
-public enum CommonApi implements Api {
-
-    // 认证-获取token
-    EN_PLUS_QUERY_TOKEN("query_token", RequestMethod.POST), //获取AccessToken
-
-    // 站点
-    EN_PLUS_QUERY_STATION_INFO("query_stations_info", RequestMethod.POST), // 站点信息
-    EN_PLUS_QUERY_STATION_STATUS("query_station_status", RequestMethod.POST), // 站点状态
-    EN_PLUS_QUERY_STATION_STATS("query_station_stats", RequestMethod.POST), // 站点统计
-    //充电
-    EN_PLUS_QUERY_EQUIP_AUTH("query_equip_auth", RequestMethod.POST), // 请求设备认证
-    EN_PLUS_QUERY_EQUIP_BUSINESS_POLICY("query_equip_business_policy", RequestMethod.POST), // 查询业务策略信息
-    EN_PLUS_QUERY_START_CHARGE("query_start_charge", RequestMethod.POST), // 查询启动充电
-    EN_PLUS_QUERY_STOP_CHARGE("query_stop_charge", RequestMethod.POST), // 请求停止充电
-    EN_PLUS_QUERY_EQUIP_CHARGE_STATUS("query_equip_charge_status", RequestMethod.POST), // 查询设备充电状态
-
-    //微信
-    WX_MP_GET_PHONE("", RequestMethod.POST), // 获取手机号
-    WX_GET_ACCESS_TOKEN("", RequestMethod.POST); // 获取AccessToken
-
-    private final String api;
-    private final RequestMethod requestMethod;
-
-    public String getApi(String platformName) {
-        var config = PlatformCache.INSTANCE.getPlatformByName(platformName);
-        return config.getApiDomain() + api;
-    }
-
-}

+ 38 - 0
service/src/main/java/com/kym/service/platform/PlatformApi.java

@@ -0,0 +1,38 @@
+package com.kym.service.platform;
+
+import com.kym.service.cache.PlatformCache;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+
+/**
+ * @author skyline
+ * 公共接口
+ */
+@AllArgsConstructor
+public enum PlatformApi implements Api {
+
+    // 认证-获取token
+    PLATFORM_QUERY_TOKEN("query_token", RequestMethod.POST), //获取AccessToken
+
+    // 站点
+    PLATFORM_QUERY_STATION_INFO("query_stations_info", RequestMethod.POST), // 站点信息
+    PLATFORM_QUERY_STATION_STATUS("query_station_status", RequestMethod.POST), // 站点状态
+    PLATFORM_QUERY_STATION_STATS("query_station_stats", RequestMethod.POST), // 站点统计
+    //充电
+    PLATFORM_QUERY_EQUIP_AUTH("query_equip_auth", RequestMethod.POST), // 请求设备认证
+    PLATFORM_QUERY_EQUIP_BUSINESS_POLICY("query_equip_business_policy", RequestMethod.POST), // 查询业务策略信息
+    PLATFORM_QUERY_START_CHARGE("query_start_charge", RequestMethod.POST), // 查询启动充电
+    PLATFORM_QUERY_STOP_CHARGE("query_stop_charge", RequestMethod.POST), // 请求停止充电
+    PLATFORM_QUERY_EQUIP_CHARGE_STATUS("query_equip_charge_status", RequestMethod.POST); // 查询设备充电状态
+
+
+    private final String api;
+    private final RequestMethod requestMethod;
+
+    public String getApi(String platformName) {
+        var config = PlatformCache.INSTANCE.getPlatformByName(platformName);
+        return config.getApiDomain() + api;
+    }
+
+}

+ 14 - 14
service/src/main/java/com/kym/service/platform/impl/PlatformApiServiceImpl.java

@@ -19,7 +19,7 @@ import com.kym.entity.common.RedisKeys;
 import com.kym.entity.platform.PlatformRespQueryToken;
 import com.kym.entity.platform.response.PlatformResponse;
 import com.kym.service.cache.PlatformCache;
-import com.kym.service.platform.CommonApi;
+import com.kym.service.platform.PlatformApi;
 import com.kym.service.platform.PlatformApiService;
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.*;
@@ -87,9 +87,9 @@ public class PlatformApiServiceImpl implements PlatformApiService {
             if (4002 == response.getRet()) {
                 // 如果返回Ret=4002,token错误的情况下,删除redis中的token,如果是预约订单则将此订单设置为延迟启动
                 redisTemplate.delete(RedisKeys.EN_PLUS_TOKEN + platformName);
-                throw new BusinessException(ResponseEnum.EN_PLUS_TOKEN_EXCEPTION);
+                throw new BusinessException(ResponseEnum.PLATFORM_TOKEN_EXCEPTION);
             }
-            throw new BusinessException(ResponseEnum.EN_PLUS_API_EXCEPTION);
+            throw new BusinessException(ResponseEnum.PLATFORM__API_EXCEPTION);
         }
     }
 
@@ -130,7 +130,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
 
         var requestParams = buildPlatformParams(platformName, data);
 
-        var response = platformGetToken(CommonApi.EN_PLUS_QUERY_TOKEN.getApi(platformName), requestParams);
+        var response = platformGetToken(PlatformApi.PLATFORM_QUERY_TOKEN.getApi(platformName), requestParams);
 
         if (response != null && 0 == response.getRet()) {
             // 解密Data获取token
@@ -143,7 +143,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
         } else {
             // 记录错误码,返回错误信息
             log.error("{}接口错误:接口名{}:返回信息:{}", platformName, "query_token", response);
-            throw new BusinessException(ResponseEnum.EN_PLUS_QUERY_TOKEN_ERROR);
+            throw new BusinessException(ResponseEnum.PLATFORM_QUERY_TOKEN_ERROR);
         }
     }
 
@@ -160,7 +160,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
             return response;
         } else {
             log.error("互联互通接口数据异常:url:{}, params:{},返回信息:{}", url, params, response);
-            throw new BusinessException(ResponseEnum.EN_PLUS_API_EXCEPTION);
+            throw new BusinessException(ResponseEnum.PLATFORM__API_EXCEPTION);
         }
     }
 
@@ -224,9 +224,9 @@ public class PlatformApiServiceImpl implements PlatformApiService {
             // 验签失败
             PlatformResponse enResponse = new PlatformResponse();
             enResponse.setRet(4001);
-            enResponse.setMsg(ResponseEnum.EN_PLUS_PUSH_SIGN_FAIL.getMessage());
+            enResponse.setMsg(ResponseEnum.PLATFORM_PUSH_SIGN_FAIL.getMessage());
             log.error("{}推送数据验签失败,数据:{}", platformName, json);
-            throw new EnPushException(ResponseEnum.EN_PLUS_PUSH_SIGN_FAIL, enResponse);
+            throw new EnPushException(ResponseEnum.PLATFORM_PUSH_SIGN_FAIL, enResponse);
         }
 
     }
@@ -249,7 +249,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
                     "ConnectorID":"%s"
                 }
                 """.formatted(equipAuthSeq, PlatformConvertUtil.convert2LongshineConnectorId(connectorId));
-        var response = platformPost(platformName, CommonApi.EN_PLUS_QUERY_EQUIP_AUTH.getApi(platformName), buildPlatformParams(platformName, param));
+        var response = platformPost(platformName, PlatformApi.PLATFORM_QUERY_EQUIP_AUTH.getApi(platformName), buildPlatformParams(platformName, param));
 
         return parsePlatformResponseData(response, platformName);
     }
@@ -273,7 +273,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
                     "ConnectorID":"%s"
                 }
                 """.formatted(equipBizSeq, connectorId);
-        var response = platformPost(platformName, CommonApi.EN_PLUS_QUERY_EQUIP_BUSINESS_POLICY.getApi(platformName), buildPlatformParams(platformName, param));
+        var response = platformPost(platformName, PlatformApi.PLATFORM_QUERY_EQUIP_BUSINESS_POLICY.getApi(platformName), buildPlatformParams(platformName, param));
         return parsePlatformResponseData(response, platformName);
     }
 
@@ -298,7 +298,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
                 }
                 """.formatted(startChargeSeq, PlatformConvertUtil.convert2LongshineConnectorId(connectorId), qrCode);
         var completeParams = PlatformConvertUtil.queryStartChargeParamsConvert(platformName, param, amount);
-        var response = platformPost(platformName, CommonApi.EN_PLUS_QUERY_START_CHARGE.getApi(platformName), buildPlatformParams(platformName, completeParams));
+        var response = platformPost(platformName, PlatformApi.PLATFORM_QUERY_START_CHARGE.getApi(platformName), buildPlatformParams(platformName, completeParams));
         return parsePlatformResponseData(response, platformName);
     }
 
@@ -316,7 +316,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
                     "StartChargeSeq":"%s"
                 }
                 """.formatted(startChargeSeq);
-        var response = platformPost(platformName, CommonApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(platformName), buildPlatformParams(platformName, param));
+        var response = platformPost(platformName, PlatformApi.PLATFORM_QUERY_EQUIP_CHARGE_STATUS.getApi(platformName), buildPlatformParams(platformName, param));
         return parsePlatformResponseData(response, platformName);
     }
 
@@ -336,7 +336,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
                     "amount":%d
                 }
                 """.formatted(startChargeSeq, amount);
-        var response = platformPost(platformName, CommonApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(platformName), buildPlatformParams(platformName, param));
+        var response = platformPost(platformName, PlatformApi.PLATFORM_QUERY_EQUIP_CHARGE_STATUS.getApi(platformName), buildPlatformParams(platformName, param));
         return parsePlatformResponseData(response, platformName);
     }
 
@@ -357,7 +357,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
                     "ConnectorID":"%s"
                 }
                 """.formatted(startChargeSeq, connectorId);
-        var response = platformPost(platformName, CommonApi.EN_PLUS_QUERY_STOP_CHARGE.getApi(platformName), buildPlatformParams(platformName, param));
+        var response = platformPost(platformName, PlatformApi.PLATFORM_QUERY_STOP_CHARGE.getApi(platformName), buildPlatformParams(platformName, param));
         return parsePlatformResponseData(response, platformName);
     }