فهرست منبع

feat(charging): 优化充电接口状态管理与设备类型映射

- 将AppletHomeController中获取站点列表接口改为GET方法
- AppletHomeService接口及实现中统一使用List泛型声明
- AppletHomeServiceImpl新增第三方设备信息查询,改进充电接口设备类型判定逻辑
- 根据设备表设备类型映射接口,支持更多设备类型分类(直流、交流、交直流一体、无线、其他)
- 充电接口状态字段补充至实体类,状态含义0-离网,1-空闲,2-占用(未充电),3-占用(充电中),4-占用(预约锁定),255-故障
- ChargingReceptionServiceImpl新增推送数据解析及充电接口状态动态更新逻辑
- 优化状态名称设置及统计,提升接口状态展示准确性
SheepHy 3 روز پیش
والد
کامیت
c19fff35a4

+ 1 - 1
src/main/java/com/zsElectric/boot/business/controller/applet/AppletHomeController.java

@@ -45,7 +45,7 @@ public class AppletHomeController {
      * @return 站点列表
      */
     @Operation(summary = "首页地图模式-获取充电站列表(按距离排序)")
-    @PostMapping("/getStationInfoMapList")
+    @GetMapping("/getStationInfoMapList")
     public Result<List<StationInfoMapVO>> getStationInfoMapList(
             @RequestParam BigDecimal longitude,
             @RequestParam BigDecimal latitude) {

+ 3 - 3
src/main/java/com/zsElectric/boot/business/service/AppletHomeService.java

@@ -6,9 +6,9 @@ import com.zsElectric.boot.business.model.vo.AppletStationDetailVO;
 import com.zsElectric.boot.business.model.vo.BannerInfoVO;
 import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
-import io.swagger.v3.oas.annotations.media.Schema;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 public interface AppletHomeService {
 
@@ -20,13 +20,13 @@ public interface AppletHomeService {
     /**
      * 首页地图模式-获取站点列表(按距离排序)
      * */
-    java.util.List<StationInfoMapVO> getStationInfoMapList(BigDecimal longitude, BigDecimal latitude);
+    List<StationInfoMapVO> getStationInfoMapList(BigDecimal longitude, BigDecimal latitude);
 
     /**
      * 获取启用状态的Banner列表
      * @return Banner列表
      */
-    java.util.List<BannerInfoVO> getBannerList();
+    List<BannerInfoVO> getBannerList();
 
     /**
      * 获取电站详情

+ 87 - 15
src/main/java/com/zsElectric/boot/business/service/impl/AppletHomeServiceImpl.java

@@ -7,8 +7,10 @@ import com.zsElectric.boot.business.mapper.BannerInfoMapper;
 import com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper;
 import com.zsElectric.boot.business.mapper.UserFirmMapper;
 import com.zsElectric.boot.charging.entity.ThirdPartyConnectorInfo;
+import com.zsElectric.boot.charging.entity.ThirdPartyEquipmentInfo;
 import com.zsElectric.boot.charging.mapper.ThirdPartyConnectorInfoMapper;
 import com.zsElectric.boot.charging.entity.ThirdPartyStationInfo;
+import com.zsElectric.boot.business.mapper.ThirdPartyEquipmentInfoMapper;
 import com.zsElectric.boot.business.model.entity.BannerInfo;
 import com.zsElectric.boot.business.model.entity.UserFirm;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
@@ -41,6 +43,7 @@ public class AppletHomeServiceImpl implements AppletHomeService {
     private final BannerInfoMapper bannerInfoMapper;
     private final BannerInfoConverter bannerInfoConverter;
     private final ThirdPartyConnectorInfoMapper thirdPartyConnectorInfoMapper;
+    private final ThirdPartyEquipmentInfoMapper thirdPartyEquipmentInfoMapper;
 
     /**
      * 时间格式化器 HHmmss
@@ -153,12 +156,32 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             return result;
         }
         
-        // 查询充电终端列表
-        List<ThirdPartyConnectorInfo> connectorList = thirdPartyConnectorInfoMapper.selectList(
-                new LambdaQueryWrapper<ThirdPartyConnectorInfo>()
-                        .eq(ThirdPartyConnectorInfo::getStationId, stationInfo.getStationId())
+        // 根据站点stationId查询设备列表(third_party_equipment_info)
+        List<ThirdPartyEquipmentInfo> equipmentList = thirdPartyEquipmentInfoMapper.selectList(
+                new LambdaQueryWrapper<ThirdPartyEquipmentInfo>()
+                        .eq(ThirdPartyEquipmentInfo::getStationId, stationInfo.getStationId())
         );
         
+        // 构建设备ID到设备类型的映射
+        Map<String, Integer> equipmentTypeMap = equipmentList.stream()
+                .collect(Collectors.toMap(
+                        ThirdPartyEquipmentInfo::getEquipmentId,
+                        e -> e.getEquipmentType() != null ? e.getEquipmentType() : 0,
+                        (v1, v2) -> v1
+                ));
+        
+        // 根据设备列表的equipmentId查询充电接口信息(third_party_connector_info)
+        List<ThirdPartyConnectorInfo> connectorList = new ArrayList<>();
+        if (!equipmentList.isEmpty()) {
+            List<String> equipmentIds = equipmentList.stream()
+                    .map(ThirdPartyEquipmentInfo::getEquipmentId)
+                    .collect(Collectors.toList());
+            connectorList = thirdPartyConnectorInfoMapper.selectList(
+                    new LambdaQueryWrapper<ThirdPartyConnectorInfo>()
+                            .in(ThirdPartyConnectorInfo::getEquipmentId, equipmentIds)
+            );
+        }
+        
         // 统计终端状态
         int idleCount = 0;
         int occupiedCount = 0;
@@ -171,20 +194,69 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             vo.setConnectorName(connector.getConnectorName());
             vo.setConnectorCode(connector.getConnectorId());
             
-            // 设备分类:根据接口类型判断
-            Integer connectorType = connector.getConnectorType();
-            if (connectorType != null) {
-                if (connectorType == 1 || connectorType == 2 || connectorType == 5) {
-                    vo.setEquipmentType("直流设备");
-                } else {
-                    vo.setEquipmentType("交流设备");
+            // 设备分类:从设备表获取设备类型(1-直流设备,2-交流设备,3-交直流一体设备,4-无线设备,5-其他)
+            Integer equipmentType = equipmentTypeMap.get(connector.getEquipmentId());
+            if (equipmentType != null) {
+                switch (equipmentType) {
+                    case 1:
+                        vo.setEquipmentType("直流设备");
+                        break;
+                    case 2:
+                        vo.setEquipmentType("交流设备");
+                        break;
+                    case 3:
+                        vo.setEquipmentType("交直流一体设备");
+                        break;
+                    case 4:
+                        vo.setEquipmentType("无线设备");
+                        break;
+                    case 5:
+                        vo.setEquipmentType("其他");
+                        break;
+                    default:
+                        vo.setEquipmentType("未知");
                 }
             }
             
-            // TODO: 实际状态需要从实时数据获取,这里暂时默认为空闲
-            vo.setStatus(1);
-            vo.setStatusName("空闲");
-            idleCount++;
+            // 从充电接口表获取实际状态
+            // 0-离网,1-空闲,2-占用(未充电),3-占用(充电中),4-占用(预约锁定),255-故障
+            Integer connectorStatus = connector.getStatus();
+            if (connectorStatus == null) {
+                // 默认为离网
+                connectorStatus = 0;
+            }
+            vo.setStatus(connectorStatus);
+            
+            // 设置状态名称并统计
+            switch (connectorStatus) {
+                case 0:
+                    vo.setStatusName("离网");
+                    offlineCount++;
+                    break;
+                case 1:
+                    vo.setStatusName("空闲");
+                    idleCount++;
+                    break;
+                case 2:
+                    vo.setStatusName("占用(未充电)");
+                    occupiedCount++;
+                    break;
+                case 3:
+                    vo.setStatusName("占用(充电中)");
+                    occupiedCount++;
+                    break;
+                case 4:
+                    vo.setStatusName("占用(预约锁定)");
+                    occupiedCount++;
+                    break;
+                case 255:
+                    vo.setStatusName("故障");
+                    offlineCount++;
+                    break;
+                default:
+                    vo.setStatusName("未知");
+                    offlineCount++;
+            }
             
             connectorVOList.add(vo);
         }

+ 3 - 0
src/main/java/com/zsElectric/boot/charging/entity/ConnectorStatusInfo.java

@@ -11,6 +11,9 @@ public class ConnectorStatusInfo {
     @JsonProperty("ConnectorID")
     private String ConnectorID;
 
+    /**
+     * 0-离网,1-空闲,2-占用(未充电),3-占用(充电中),4-占用(预约锁定),255-故障
+     * */
     @JsonProperty("Status")
     private Integer Status;
 }

+ 7 - 1
src/main/java/com/zsElectric/boot/charging/entity/ThirdPartyConnectorInfo.java

@@ -42,7 +42,7 @@ public class ThirdPartyConnectorInfo extends BaseEntity {
     private String connectorName;
 
     /**
-     * 接口类型
+     * 接口类型 1-家用插座(模式2),2-交流接口插座(模式3,连接方式B),3-交流接口插头(带枪线,模式3,连接方式C),4-直流接口枪头(带枪线,模式4),5-无线充电座,6-其他
      */
     private Integer connectorType;
 
@@ -76,6 +76,12 @@ public class ThirdPartyConnectorInfo extends BaseEntity {
      */
     private Integer nationalStandard;
 
+    /**
+     * 充电设备接口状态
+     * 0-离网,1-空闲,2-占用(未充电),3-占用(充电中),4-占用(预约锁定),255-故障
+     */
+    private Integer status;
+
     /**
      * 创建人ID
      */

+ 1 - 1
src/main/java/com/zsElectric/boot/charging/entity/ThirdPartyEquipmentInfo.java

@@ -52,7 +52,7 @@ public class ThirdPartyEquipmentInfo extends BaseEntity {
     private String productionDate;
 
     /**
-     * 设备类型
+     * 设备类型 1-直流设备,2-交流设备,3-交直流一体设备,4-无线设备,5-其他
      */
     private Integer equipmentType;
 

+ 25 - 1
src/main/java/com/zsElectric/boot/charging/service/impl/ChargingReceptionServiceImpl.java

@@ -1,7 +1,12 @@
 package com.zsElectric.boot.charging.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zsElectric.boot.charging.entity.ConnectorStatusInfo;
+import com.zsElectric.boot.charging.entity.StationStatusInfo;
+import com.zsElectric.boot.charging.entity.ThirdPartyConnectorInfo;
+import com.zsElectric.boot.charging.mapper.ThirdPartyConnectorInfoMapper;
 import com.zsElectric.boot.charging.service.ChargingReceptionService;
 import com.zsElectric.boot.charging.vo.*;
 import com.zsElectric.boot.common.constant.ConnectivityConstants;
@@ -12,8 +17,10 @@ import com.zsElectric.boot.core.exception.BusinessException;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import static com.zsElectric.boot.common.constant.ConnectivityConstants.FAIL_REASON_NONE;
@@ -27,6 +34,7 @@ import static com.zsElectric.boot.common.util.HmacMD5Util.verify;
 public class ChargingReceptionServiceImpl implements ChargingReceptionService {
 
     private final ChargingUtil chargingUtil;
+    private final ThirdPartyConnectorInfoMapper connectorInfoMapper;
 
     private final ObjectMapper objectMapper = new ObjectMapper();
 
@@ -209,7 +217,23 @@ public class ChargingReceptionServiceImpl implements ChargingReceptionService {
                 String decryptData = chargingUtil.decryptData(requestDTO.getData());
                 log.info("解密后的数据:{}", decryptData);
 
-                // todo 业务代码待处理
+                // 解析设备状态变化推送数据
+                QueryStationStatusVO stationStatusVO = objectMapper.readValue(decryptData, QueryStationStatusVO.class);
+                if (stationStatusVO != null && !CollectionUtils.isEmpty(stationStatusVO.getStationStatusInfos())) {
+                    for (StationStatusInfo stationStatusInfo : stationStatusVO.getStationStatusInfos()) {
+                        List<ConnectorStatusInfo> connectorStatusInfos = stationStatusInfo.getConnectorStatusInfos();
+                        if (!CollectionUtils.isEmpty(connectorStatusInfos)) {
+                            for (ConnectorStatusInfo connectorStatus : connectorStatusInfos) {
+                                // 根据连接器ID更新状态
+                                connectorInfoMapper.update(null, Wrappers.<ThirdPartyConnectorInfo>lambdaUpdate()
+                                        .eq(ThirdPartyConnectorInfo::getConnectorId, connectorStatus.getConnectorID())
+                                        .set(ThirdPartyConnectorInfo::getStatus, connectorStatus.getStatus()));
+                                log.debug("更新充电接口状态 - connectorId: {}, status: {}",
+                                        connectorStatus.getConnectorID(), connectorStatus.getStatus());
+                            }
+                        }
+                    }
+                }
 
                 Map<String, Integer> statusMap = new HashMap<>();
                 statusMap.put("Status", 0);