瀏覽代碼

feat(applet): 新增首页地图模式查询最近充电站接口

- 新增StationInfoMapVO视图对象,包含停车费和地址字段
- AppletHomeController新增/getStationInfoMap接口,支持经纬度参数查询
- AppletHomeService及实现类新增getStationInfoMap方法实现业务逻辑
- ThirdPartyStationInfoMapper新增selectNearestStationMap SQL及映射,查询最近站点详细信息
- 关联SQL中计算距离、峰值、电价及停车费等信息,按距离排序返回最近站点
- 完善接口Swagger文档描述,支持首页地图模式功能
SheepHy 12 小時之前
父節點
當前提交
310fe06102

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

@@ -3,15 +3,15 @@ package com.zsElectric.boot.business.controller.applet;
 import io.swagger.v3.oas.annotations.Operation;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
+import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
 import com.zsElectric.boot.core.web.PageResult;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import java.math.BigDecimal;
 
 @Tag(name = "小程序主页相关接口")
 @RestController
@@ -33,4 +33,19 @@ public class AppletHomeController {
         IPage<StationInfoVO> result = appletHomeService.getStationInfoPage(queryParams);
         return PageResult.success(result);
     }
+
+    /**
+     * 首页地图模式-获取最近的充电站信息
+     *
+     * @param longitude 经度
+     * @param latitude 纬度
+     * @return 最近的站点信息
+     */
+    @Operation(summary = "首页地图模式-获取最近的充电站信息")
+    @GetMapping("/getStationInfoMap")
+    public StationInfoMapVO getStationInfoMap(
+            @RequestParam BigDecimal longitude,
+            @RequestParam BigDecimal latitude) {
+        return appletHomeService.getStationInfoMap(longitude, latitude);
+    }
 }

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

@@ -54,4 +54,20 @@ public interface ThirdPartyStationInfoMapper extends BaseMapper<ThirdPartyStatio
             @Param("currentTime") String currentTime,
             @Param("firmId") Long firmId
     );
+
+    /**
+     * 小程序首页地图模式查询最近的站点信息
+     *
+     * @param longitude 经度
+     * @param latitude 纬度
+     * @param currentTime 当前时间(HHmmss格式)
+     * @param firmId 企业ID(可为null)
+     * @return 最近站点信息
+     */
+    com.zsElectric.boot.business.model.vo.StationInfoMapVO selectNearestStationMap(
+            @Param("longitude") java.math.BigDecimal longitude,
+            @Param("latitude") java.math.BigDecimal latitude,
+            @Param("currentTime") String currentTime,
+            @Param("firmId") Long firmId
+    );
 }

+ 17 - 0
src/main/java/com/zsElectric/boot/business/model/vo/StationInfoMapVO.java

@@ -0,0 +1,17 @@
+package com.zsElectric.boot.business.model.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+@Schema(description = "小程序首页站点信息视图对象-地图模式")
+public class StationInfoMapVO extends StationInfoVO{
+    @Schema(description = "停车费")
+    private BigDecimal parkingFee;
+    @Schema(description = "地址")
+    private String address;
+}

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

@@ -2,7 +2,11 @@ package com.zsElectric.boot.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
+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;
 
 public interface AppletHomeService {
 
@@ -10,4 +14,9 @@ public interface AppletHomeService {
      * 用户端分页查询站点信息
      * */
     IPage<StationInfoVO> getStationInfoPage(StationInfoQuery queryParams);
+
+    /**
+     * 首页地图模式
+     * */
+    StationInfoMapVO getStationInfoMap(BigDecimal longitude, BigDecimal latitude);
 }

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

@@ -7,6 +7,7 @@ import com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper;
 import com.zsElectric.boot.business.mapper.UserFirmMapper;
 import com.zsElectric.boot.business.model.entity.UserFirm;
 import com.zsElectric.boot.business.model.query.StationInfoQuery;
+import com.zsElectric.boot.business.model.vo.StationInfoMapVO;
 import com.zsElectric.boot.business.model.vo.StationInfoVO;
 import com.zsElectric.boot.business.service.AppletHomeService;
 import com.zsElectric.boot.security.util.SecurityUtils;
@@ -14,6 +15,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 
@@ -65,4 +67,15 @@ public class AppletHomeServiceImpl implements AppletHomeService {
         
         return resultPage;
     }
+
+    @Override
+    public StationInfoMapVO getStationInfoMap(BigDecimal longitude, BigDecimal latitude) {
+        // 获取当前时间(HHmmss格式)
+        String currentTime = LocalTime.now().format(TIME_FORMATTER);
+        
+        // 查询最近的站点
+        return thirdPartyStationInfoMapper.selectNearestStationMap(
+                longitude, latitude, currentTime, null
+        );
+    }
 }

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

@@ -296,4 +296,155 @@
         </if>
     </select>
 
+    <!-- 小程序首页地图模式站点信息查询结果映射 -->
+    <resultMap id="AppletStationInfoMapResultMap" type="com.zsElectric.boot.business.model.vo.StationInfoMapVO">
+        <result property="stationId" column="station_info_id"/>
+        <result property="stationName" column="station_name"/>
+        <result property="tips" column="station_tips"/>
+        <result property="distance" column="distance"/>
+        <result property="fastCharging" column="fast_charging"/>
+        <result property="slowCharging" column="slow_charging"/>
+        <result property="peakValue" column="peak_value"/>
+        <result property="peakTime" column="peak_time"/>
+        <result property="platformPrice" column="platform_price"/>
+        <result property="enterprisePrice" column="enterprise_price"/>
+        <result property="parkingFee" column="parking_fee"/>
+        <result property="address" column="address"/>
+    </resultMap>
+
+    <!-- 小程序首页地图模式查询最近站点信息 -->
+    <select id="selectNearestStationMap" resultMap="AppletStationInfoMapResultMap">
+        SELECT
+            tpsi.id AS station_info_id,
+            tpsi.station_name,
+            tpsi.station_tips,
+            tpsi.address,
+            CAST(tpsi.park_fee AS DECIMAL(10,2)) AS parking_fee,
+            <!-- 计算距离(km) -->
+            ROUND(
+                6371 * ACOS(
+                    COS(RADIANS(#{latitude})) * COS(RADIANS(tpsi.station_lat))
+                    * COS(RADIANS(tpsi.station_lng) - RADIANS(#{longitude}))
+                    + SIN(RADIANS(#{latitude})) * SIN(RADIANS(tpsi.station_lat))
+                ), 2
+            ) AS distance,
+            <!-- 快充统计(空闲/总数) -->
+            CONCAT(
+                COUNT(tpci.id),
+                '/',
+                COUNT(tpci.id)
+            ) AS fast_charging,
+            <!-- 慢充统计(直接0/0) -->
+            '0/0' AS slow_charging,
+            <!-- 峰值(根据当前时段获取) -->
+            (
+                SELECT
+                    CASE tppi.period_flag
+                        WHEN 1 THEN '尖'
+                        WHEN 2 THEN '峰'
+                        WHEN 3 THEN '平'
+                        WHEN 4 THEN '谷'
+                        ELSE ''
+                    END
+                FROM third_party_policy_info tppi
+                INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
+                INNER JOIN third_party_connector_info tpci2 ON tpepp.connector_id = tpci2.connector_id AND tpci2.is_deleted = 0
+                WHERE tpci2.station_id = tpsi.station_id
+                    AND tppi.is_deleted = 0
+                    AND tppi.start_time &lt;= #{currentTime}
+                ORDER BY tppi.start_time DESC
+                LIMIT 1
+            ) AS peak_value,
+            <!-- 峰时段时间(period_flag=2为峰时段),格式: HH:mm - HH:mm -->
+            (
+                SELECT CONCAT(
+                    CONCAT(SUBSTRING(tppi.start_time, 1, 2), ':', SUBSTRING(tppi.start_time, 3, 2)),
+                    ' - ',
+                    IFNULL(
+                        (
+                            SELECT CONCAT(SUBSTRING(next_tppi.start_time, 1, 2), ':', SUBSTRING(next_tppi.start_time, 3, 2))
+                            FROM third_party_policy_info next_tppi
+                            WHERE next_tppi.price_policy_id = tppi.price_policy_id
+                                AND next_tppi.is_deleted = 0
+                                AND next_tppi.start_time > tppi.start_time
+                            ORDER BY next_tppi.start_time ASC
+                            LIMIT 1
+                        ),
+                        '24:00'
+                    )
+                )
+                FROM third_party_policy_info tppi
+                INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
+                INNER JOIN third_party_connector_info tpci5 ON tpepp.connector_id = tpci5.connector_id AND tpci5.is_deleted = 0
+                WHERE tpci5.station_id = tpsi.station_id
+                    AND tppi.is_deleted = 0
+                    AND tppi.period_flag = 2
+                LIMIT 1
+            ) AS peak_time,
+            <!-- 平台价(电费+服务费+运营费+综合销售费) -->
+            (
+                SELECT
+                    ROUND(
+                        IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)
+                        + IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0),
+                        4
+                    )
+                FROM c_policy_fee pf
+                INNER JOIN third_party_policy_info tppi ON pf.start_time = tppi.start_time
+                INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
+                INNER JOIN third_party_connector_info tpci3 ON tpepp.connector_id = tpci3.connector_id AND tpci3.is_deleted = 0
+                WHERE tpci3.station_id = tpsi.station_id
+                    AND pf.station_info_id = tpsi.id
+                    AND pf.sales_type = 0
+                    AND pf.is_deleted = 0
+                    AND tppi.is_deleted = 0
+                    AND pf.start_time &lt;= #{currentTime}
+                ORDER BY pf.start_time DESC
+                LIMIT 1
+            ) AS platform_price,
+            <!-- 企业价(如果有企业ID) -->
+            <if test="firmId != null">
+            (
+                SELECT
+                    ROUND(
+                        IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)
+                        + IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0),
+                        4
+                    )
+                FROM c_policy_fee pf
+                INNER JOIN third_party_policy_info tppi ON pf.start_time = tppi.start_time
+                INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
+                INNER JOIN third_party_connector_info tpci4 ON tpepp.connector_id = tpci4.connector_id AND tpci4.is_deleted = 0
+                WHERE tpci4.station_id = tpsi.station_id
+                    AND pf.station_info_id = tpsi.id
+                    AND pf.sales_type = 1
+                    AND pf.firm_id = #{firmId}
+                    AND pf.is_deleted = 0
+                    AND tppi.is_deleted = 0
+                    AND pf.start_time &lt;= #{currentTime}
+                ORDER BY pf.start_time DESC
+                LIMIT 1
+            ) AS enterprise_price
+            </if>
+            <if test="firmId == null">
+            NULL AS enterprise_price
+            </if>
+        FROM third_party_station_info tpsi
+        LEFT JOIN third_party_connector_info tpci ON tpsi.station_id = tpci.station_id AND tpci.is_deleted = 0
+        WHERE tpsi.is_deleted = 0
+            AND tpsi.equipment_owner_id = 'MA6DP6BE7'
+            AND tpsi.policy_configured = 1
+            <!-- 确保存在平台价配置 -->
+            AND EXISTS (
+                SELECT 1 FROM c_policy_fee pf_check
+                WHERE pf_check.station_info_id = tpsi.id
+                    AND pf_check.sales_type = 0
+                    AND pf_check.is_deleted = 0
+                    AND (pf_check.op_fee IS NOT NULL OR pf_check.comp_sales_fee IS NOT NULL)
+            )
+        GROUP BY tpsi.id
+        ORDER BY distance ASC
+        LIMIT 1
+    </select>
+
 </mapper>