skyline 2 vuotta sitten
vanhempi
säilyke
7478f21cf5

+ 12 - 5
entity/src/main/java/com/kym/entity/enplus/EnConnectorInfo.java

@@ -1,6 +1,7 @@
 package com.kym.entity.enplus;
 
 import com.alibaba.fastjson2.annotation.JSONField;
+import com.baomidou.mybatisplus.annotation.TableField;
 import lombok.Data;
 
 /**
@@ -13,13 +14,20 @@ public class EnConnectorInfo {
     /**
      * 充电设备接口编码
      */
-    @JSONField(name = "")
-    private String ConnectorID;
+    @JSONField(name = "ConnectorID")
+    private String connectorId;
+
+    /**
+     * 充电桩短ID
+     */
+    @TableField(exist = false)
+    private String shortId;
+
     /**
      * 充电设备接口名称
      */
-    @JSONField(name = "")
-    private String ConnectorName;
+    @JSONField(name = "connectorName")
+    private String connectorName;
     /**
      * 充电设备接口类型
      * 1:家用插座(模式2)
@@ -68,5 +76,4 @@ public class EnConnectorInfo {
     @JSONField(name = "NationalStandard")
     private int nationalStandard;
 
-
 }

+ 0 - 1
entity/src/main/java/com/kym/entity/enplus/EnEquipmentInfo.java

@@ -63,7 +63,6 @@ public class EnEquipmentInfo {
 
     @JSONCreator
     public EnEquipmentInfo(@JSONField(name = "ConnectorInfos") JSONArray array) {
-        System.out.println(array);
         this.connectorInfos = array.toJavaList(EnConnectorInfo.class);
     }
 

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

@@ -44,7 +44,7 @@ public class ChargerController {
     private EnNotifyService enNotifyService;
 
     /**
-     * 充电列表
+     * 充电列表
      *
      * @param pageNum
      * @param pageSize
@@ -90,7 +90,7 @@ public class ChargerController {
     }
 
     /**
-     * 查询充电状态
+     * 查询当前用户充电状态
      *
      * @return
      */

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

@@ -11,6 +11,7 @@ import com.kym.entity.enplus.EnStationStatusInfo;
 import com.kym.mapper.admin.StationMapper;
 import com.kym.service.admin.StationService;
 import com.kym.service.enplus.EnPlusService;
+import com.kym.service.utils.KymCache;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +33,9 @@ import java.util.List;
 public class StationServiceImpl extends ServiceImpl<StationMapper, Station> implements StationService {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(StationServiceImpl.class);
+    @Autowired
+    private KymCache kymCache;
+
 
     @Autowired
     private EnPlusService enPlusService;
@@ -47,7 +51,9 @@ public class StationServiceImpl extends ServiceImpl<StationMapper, Station> impl
                 """.formatted(pageNum, pageSize);
         var response = enPlusService.enPlusPost(EnPlusApi.EN_PLUS_QUERY_STATION_INFO.getApi(), enPlusService.buildParams(param));
         var enStations = JSONObject.parseObject(AESUtil.decrypt(response.getData()));
-        return enStations.getJSONArray("StationInfos").toJavaList(Station.class);
+        var stationList = enStations.getJSONArray("StationInfos").toJavaList(Station.class);
+        stationList.forEach(station -> station.getEquipmentInfos().forEach(enEquipmentInfo -> enEquipmentInfo.getConnectorInfos().forEach(connector -> connector.setShortId(kymCache.getShortId(enEquipmentInfo.getEquipmentId())))));
+        return stationList;
 
     }
 
@@ -84,7 +90,7 @@ public class StationServiceImpl extends ServiceImpl<StationMapper, Station> impl
                 """.formatted(stationId, startTime, endTime);
         var response = enPlusService.enPlusPost(EnPlusApi.EN_PLUS_QUERY_STATION_STATS.getApi(), enPlusService.buildParams(param));
         // TODO: 2023-08-12 包装成自己的数据格式
-        var enStationStats =  JSONObject.parseObject(AESUtil.decrypt(response.getData()));
+        var enStationStats = JSONObject.parseObject(AESUtil.decrypt(response.getData()));
         return enStationStats.getJSONObject("StationStats").toJavaObject(EnStationStatsInfo.class);
     }
 

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

@@ -30,20 +30,23 @@ import java.util.Map;
 public class ChargeServiceImpl implements ChargeService {
     private static final Logger LOGGER = LoggerFactory.getLogger(ChargeServiceImpl.class);
 
-    @Autowired
-    private EquipmentRelationService equipmentRelationService;
+    private final EquipmentRelationService equipmentRelationService;
 
-    @Autowired
-    private ChargeOrderService chargeOrderService;
+    private final ChargeOrderService chargeOrderService;
 
-    @Autowired
-    private AccountService accountService;
+    private final AccountService accountService;
 
-    @Autowired
-    private EnPlusService enPlusService;
+    private final EnPlusService enPlusService;
 
-    @Autowired
-    private EnPlusConfig enPlusConfig;
+    private final EnPlusConfig enPlusConfig;
+
+    public ChargeServiceImpl(EquipmentRelationService equipmentRelationService, ChargeOrderService chargeOrderService, AccountService accountService, EnPlusService enPlusService, EnPlusConfig enPlusConfig) {
+        this.equipmentRelationService = equipmentRelationService;
+        this.chargeOrderService = chargeOrderService;
+        this.accountService = accountService;
+        this.enPlusService = enPlusService;
+        this.enPlusConfig = enPlusConfig;
+    }
 
     /**
      * 启动充电
@@ -147,7 +150,7 @@ public class ChargeServiceImpl implements ChargeService {
             chargeOrderService.updateById(chargeOrder);
             return chargeOrder;
         } else {
-            LOGGER.error("用户:{}无进行中的订单", userId);
+            LOGGER.debug("用户:{}无进行中的订单", userId);
             throw new BusinessException(ResponseEnum.NO_ORDER_IN_PROGRESS);
         }
     }

+ 29 - 0
service/src/main/java/com/kym/service/utils/KymCache.java

@@ -0,0 +1,29 @@
+package com.kym.service.utils;
+
+import com.kym.entity.admin.EquipmentRelation;
+import com.kym.service.admin.EquipmentRelationService;
+import lombok.Data;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author skyline
+ * @description
+ * @date 2023-08-25 22:58
+ */
+@Component
+@Data
+public class KymCache {
+
+    private static Map<String, String> SHORT_ID_MAPPING;
+
+    public KymCache(EquipmentRelationService relationService) {
+        SHORT_ID_MAPPING = relationService.list().stream().collect(Collectors.toMap(EquipmentRelation::getEquipmentId, EquipmentRelation::getShortId));
+    }
+
+    public String getShortId(String key) {
+        return SHORT_ID_MAPPING.get(key);
+    }
+}