Explorar o código

feat(applet): 新增充电站搜索功能

- 在AppletHomeService接口及实现中添加searchStations方法支持站点名称和地址模糊查询
- 在AppletStationController中新增搜索充电站接口,支持经纬度参数计算距离
- 扩展ThirdPartyStationInfoMapper及XML,增加searchStations SQL查询及结果映射
- 新增AppletStationSearchVO类作为小程序搜索结果数据传输对象
- 搜索结果包含站点基本信息、距离及快慢充电桩数量与空闲状态
SheepHy hai 1 día
pai
achega
1023fb7df0

+ 19 - 0
src/main/java/com/zsElectric/boot/business/controller/applet/AppletStationController.java

@@ -4,6 +4,7 @@ import com.zsElectric.boot.business.model.vo.AppletConnectorListVO;
 import com.zsElectric.boot.business.model.vo.AppletStationDetailVO;
 import com.zsElectric.boot.business.model.vo.AppletStationPriceListVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
 import com.zsElectric.boot.common.annotation.ApiRateLimit;
 import com.zsElectric.boot.core.web.Result;
@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @Tag(name = "充电相关接口")
 @RestController
@@ -78,4 +80,21 @@ public class AppletStationController {
     public Result<AppletChargingCostVO> getCurrentChargingCost() {
         return Result.success(appletHomeService.getCurrentChargingCost());
     }
+
+    /**
+     * 搜索充电站
+     *
+     * @param keyword 搜索关键词(站点名称或地址)
+     * @param longitude 经度(用于计算距离,可选)
+     * @param latitude 纬度(用于计算距离,可选)
+     * @return 搜索结果列表
+     */
+    @Operation(summary = "搜索充电站")
+    @GetMapping("/search")
+    public Result<List<AppletStationSearchVO>> searchStations(
+            @RequestParam String keyword,
+            @RequestParam(required = false) BigDecimal longitude,
+            @RequestParam(required = false) BigDecimal latitude) {
+        return Result.success(appletHomeService.searchStations(keyword, longitude, latitude));
+    }
 }

+ 15 - 0
src/main/java/com/zsElectric/boot/business/mapper/ThirdPartyStationInfoMapper.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zsElectric.boot.business.model.vo.AppletStationDetailVO;
 import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO;
 import com.zsElectric.boot.charging.entity.ThirdPartyStationInfo;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
@@ -98,4 +99,18 @@ public interface ThirdPartyStationInfoMapper extends BaseMapper<ThirdPartyStatio
      * @return 实时充电费用信息
      */
     AppletChargingCostVO selectCurrentChargingCost(@Param("userId") Long userId);
+
+    /**
+     * 搜索充电站(根据站点名称和地址模糊查询)
+     *
+     * @param keyword 关键词(站点名称或地址)
+     * @param longitude 经度(用于计算距离,可为null)
+     * @param latitude 纬度(用于计算距离,可为null)
+     * @return 充电站搜索结果列表
+     */
+    java.util.List<AppletStationSearchVO> searchStations(
+            @Param("keyword") String keyword,
+            @Param("longitude") java.math.BigDecimal longitude,
+            @Param("latitude") java.math.BigDecimal latitude
+    );
 }

+ 48 - 0
src/main/java/com/zsElectric/boot/business/model/vo/applet/AppletStationSearchVO.java

@@ -0,0 +1,48 @@
+package com.zsElectric.boot.business.model.vo.applet;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 小程序充电站搜索结果VO
+ *
+ * @author system
+ * @since 2025-12-19
+ */
+@Getter
+@Setter
+@Schema(description = "小程序充电站搜索结果VO")
+public class AppletStationSearchVO implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    @Schema(description = "站点ID")
+    private Long stationId;
+
+    @Schema(description = "站点名称")
+    private String stationName;
+
+    @Schema(description = "地址")
+    private String address;
+
+    @Schema(description = "距离(km)")
+    private BigDecimal distance;
+
+    @Schema(description = "快充空闲数")
+    private Integer fastIdleCount;
+
+    @Schema(description = "快充总数")
+    private Integer fastTotalCount;
+
+    @Schema(description = "慢充空闲数")
+    private Integer slowIdleCount;
+
+    @Schema(description = "慢充总数")
+    private Integer slowTotalCount;
+}

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

@@ -9,6 +9,7 @@ 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 com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -61,4 +62,15 @@ public interface AppletHomeService {
      * */
     AppletChargingCostVO getCurrentChargingCost();
 
+    /**
+     * 搜索充电站
+     * 根据站点名称和地址进行模糊查询
+     *
+     * @param keyword 搜索关键词(站点名称或地址)
+     * @param longitude 经度(用于计算距离,可为null)
+     * @param latitude 纬度(用于计算距离,可为null)
+     * @return 搜索结果列表
+     */
+    List<AppletStationSearchVO> searchStations(String keyword, BigDecimal longitude, BigDecimal latitude);
+
 }

+ 12 - 0
src/main/java/com/zsElectric/boot/business/service/impl/AppletHomeServiceImpl.java

@@ -29,6 +29,7 @@ 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 com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO;
+import com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
 import com.zsElectric.boot.business.converter.BannerInfoConverter;
 import com.zsElectric.boot.security.util.SecurityUtils;
@@ -625,4 +626,15 @@ public class AppletHomeServiceImpl implements AppletHomeService {
 
         return thirdPartyStationInfoMapper.selectCurrentChargingCost(userId);
     }
+
+    @Override
+    public List<AppletStationSearchVO> searchStations(String keyword, BigDecimal longitude, BigDecimal latitude) {
+        // 关键词为空或空字符串,返回空列表
+        if (keyword == null || keyword.trim().isEmpty()) {
+            return new ArrayList<>();
+        }
+
+        // 调用Mapper查询
+        return thirdPartyStationInfoMapper.searchStations(keyword.trim(), longitude, latitude);
+    }
 }

+ 81 - 0
src/main/resources/mapper/business/ThirdPartyStationInfoMapper.xml

@@ -640,4 +640,85 @@
         LIMIT 1
     </select>
 
+    <!-- 搜索充电站结果映射 -->
+    <resultMap id="AppletStationSearchResultMap" type="com.zsElectric.boot.business.model.vo.applet.AppletStationSearchVO">
+        <result property="stationId" column="station_id"/>
+        <result property="stationName" column="station_name"/>
+        <result property="address" column="address"/>
+        <result property="distance" column="distance"/>
+        <result property="fastIdleCount" column="fast_idle_count"/>
+        <result property="fastTotalCount" column="fast_total_count"/>
+        <result property="slowIdleCount" column="slow_idle_count"/>
+        <result property="slowTotalCount" column="slow_total_count"/>
+    </resultMap>
+
+    <!-- 搜索充电站(根据站点名称和地址模糊查询) -->
+    <select id="searchStations" resultMap="AppletStationSearchResultMap">
+        SELECT
+            tpsi.id AS station_id,
+            tpsi.station_name,
+            tpsi.address,
+            <if test="longitude != null and latitude != null">
+            ROUND(
+                ST_Distance_Sphere(
+                    point(tpsi.station_lng, tpsi.station_lat),
+                    point(#{longitude}, #{latitude})
+                ) / 1000,
+                2
+            ) AS distance,
+            </if>
+            <if test="longitude == null or latitude == null">
+            NULL AS distance,
+            </if>
+            <!-- 快充空闲数 -->
+            IFNULL((
+                SELECT COUNT(1)
+                FROM third_party_connector_info tpci
+                WHERE tpci.station_id = tpsi.station_id
+                    AND tpci.connector_type = 1
+                    AND tpci.connector_status = 1
+                    AND tpci.is_deleted = 0
+            ), 0) AS fast_idle_count,
+            <!-- 快充总数 -->
+            IFNULL((
+                SELECT COUNT(1)
+                FROM third_party_connector_info tpci
+                WHERE tpci.station_id = tpsi.station_id
+                    AND tpci.connector_type = 1
+                    AND tpci.is_deleted = 0
+            ), 0) AS fast_total_count,
+            <!-- 慢充空闲数 -->
+            IFNULL((
+                SELECT COUNT(1)
+                FROM third_party_connector_info tpci
+                WHERE tpci.station_id = tpsi.station_id
+                    AND tpci.connector_type = 2
+                    AND tpci.connector_status = 1
+                    AND tpci.is_deleted = 0
+            ), 0) AS slow_idle_count,
+            <!-- 慢充总数 -->
+            IFNULL((
+                SELECT COUNT(1)
+                FROM third_party_connector_info tpci
+                WHERE tpci.station_id = tpsi.station_id
+                    AND tpci.connector_type = 2
+                    AND tpci.is_deleted = 0
+            ), 0) AS slow_total_count
+        FROM third_party_station_info tpsi
+        WHERE tpsi.is_deleted = 0
+            AND tpsi.equipment_owner_id = 'MA6DP6BE7'
+            AND tpsi.policy_configured = 1
+            AND (
+                tpsi.station_name LIKE CONCAT('%', #{keyword}, '%')
+                OR tpsi.address LIKE CONCAT('%', #{keyword}, '%')
+            )
+        <if test="longitude != null and latitude != null">
+        ORDER BY distance ASC
+        </if>
+        <if test="longitude == null or latitude == null">
+        ORDER BY tpsi.id DESC
+        </if>
+        LIMIT 50
+    </select>
+
 </mapper>