| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper">
- <resultMap id="StationInfoResultMap" type="com.zsElectric.boot.business.model.vo.ThirdPartyStationInfoVO">
- <id property="id" column="id"/>
- <result property="stationId" column="station_id"/>
- <result property="stationName" column="station_name"/>
- <result property="areaCode" column="area_code"/>
- <result property="equipmentOwnerId" column="equipment_owner_id"/>
- <result property="address" column="address"/>
- <result property="construction" column="construction"/>
- <result property="equipmentCount" column="equipment_count"/>
- <result property="stationStatus" column="station_status"/>
- <result property="serviceTel" column="service_tel"/>
- <result property="stationType" column="station_type"/>
- <result property="stationLng" column="station_lng"/>
- <result property="stationLat" column="station_lat"/>
- <result property="siteGuide" column="site_guide"/>
- <result property="stationTips" column="station_tips"/>
- <result property="salesType" column="sales_type"/>
- <result property="firmId" column="firm_id"/>
- <result property="thirdPartyId" column="third_party_id"/>
- </resultMap>
- <select id="selectStationInfoPage" resultMap="StationInfoResultMap">
- SELECT
- tpsi.id,
- tpsi.station_id,
- tpsi.station_name,
- tpsi.area_code,
- tpsi.equipment_owner_id,
- tpsi.address,
- tpsi.construction,
- COUNT(DISTINCT tpei.id) AS equipment_count,
- tpsi.station_status,
- tpsi.service_tel,
- tpsi.station_type,
- tpsi.station_lng,
- tpsi.station_lat,
- tpsi.site_guide
- FROM third_party_station_info tpsi
- LEFT JOIN third_party_equipment_info tpei ON tpsi.station_id = tpei.station_id AND tpei.is_deleted = 0
- WHERE tpsi.is_deleted = 0
- <if test="query.stationId != null and query.stationId != ''">
- AND tpsi.station_id = #{query.stationId}
- </if>
- <if test="query.stationName != null and query.stationName != ''">
- AND tpsi.station_name LIKE CONCAT('%', #{query.stationName}, '%')
- </if>
- <if test="query.areaCode != null and query.areaCode != ''">
- AND tpsi.area_code = #{query.areaCode}
- </if>
- <if test="query.equipmentOwnerId != null and query.equipmentOwnerId != ''">
- AND tpsi.equipment_owner_id = #{query.equipmentOwnerId}
- </if>
- <if test="query.stationStatus != null and query.stationStatus != 0">
- AND tpsi.station_status = #{query.stationStatus}
- </if>
- <if test="query.stationType != null and query.stationType != 0">
- AND tpsi.station_type = #{query.stationType}
- </if>
- <if test="query.serviceTel != null and query.serviceTel != ''">
- AND tpsi.service_tel = #{query.serviceTel}
- </if>
- GROUP BY tpsi.id
- ORDER BY tpsi.update_time DESC
- </select>
- <select id="selectStationInfoPageByEquipment" resultMap="StationInfoResultMap">
- SELECT
- tpsi.id,
- tpsi.station_id,
- tpsi.station_name,
- tpsi.area_code,
- tpsi.equipment_owner_id,
- tpsi.address,
- tpsi.construction,
- COUNT(DISTINCT tpei.id) AS equipment_count,
- tpsi.station_status,
- tpsi.service_tel,
- tpsi.station_type,
- tpsi.station_lng,
- tpsi.station_lat,
- tpsi.site_guide,
- tpsi.station_tips,
- CASE
- WHEN pf.firm_id IS NOT NULL THEN 1
- WHEN pf.third_party_id IS NOT NULL THEN 2
- ELSE 0
- END AS sales_type,
- pf.firm_id,
- pf.third_party_id
- FROM third_party_station_info tpsi
- LEFT JOIN third_party_equipment_info tpei ON tpsi.station_id = tpei.station_id AND tpei.is_deleted = 0
- LEFT JOIN (
- SELECT p1.station_info_id, p1.firm_id, p1.third_party_id
- FROM c_policy_fee p1
- INNER JOIN (
- SELECT station_info_id,
- IFNULL(firm_id, 0) AS grp_firm_id,
- IFNULL(third_party_id, 0) AS grp_third_party_id,
- MIN(id) AS min_id
- FROM c_policy_fee
- WHERE is_deleted = 0
- GROUP BY station_info_id, IFNULL(firm_id, 0), IFNULL(third_party_id, 0)
- ) p2 ON p1.id = p2.min_id
- WHERE p1.is_deleted = 0
- ) pf ON pf.station_info_id = tpsi.id
- WHERE tpsi.is_deleted = 0
- AND tpsi.equipment_owner_id = 'MA6DP6BE7'
- AND tpsi.policy_configured = 1
- <if test="query.stationId != null and query.stationId != ''">
- AND tpsi.station_id = #{query.stationId}
- </if>
- <if test="query.stationName != null and query.stationName != ''">
- AND tpsi.station_name LIKE CONCAT('%', #{query.stationName}, '%')
- </if>
- <if test="query.areaCode != null and query.areaCode != ''">
- AND tpsi.area_code = #{query.areaCode}
- </if>
- <if test="query.equipmentOwnerId != null and query.equipmentOwnerId != ''">
- AND tpsi.equipment_owner_id = #{query.equipmentOwnerId}
- </if>
- <if test="query.stationStatus != null and query.stationStatus != 0">
- AND tpsi.station_status = #{query.stationStatus}
- </if>
- <if test="query.stationType != null and query.stationType != 0">
- AND tpsi.station_type = #{query.stationType}
- </if>
- <if test="query.serviceTel != null and query.serviceTel != ''">
- AND tpsi.service_tel = #{query.serviceTel}
- </if>
- GROUP BY tpsi.id, pf.firm_id, pf.third_party_id
- ORDER BY tpsi.update_time DESC
- </select>
- <!-- 小程序首页站点信息查询结果映射 -->
- <resultMap id="AppletStationInfoResultMap" type="com.zsElectric.boot.business.model.vo.StationInfoVO">
- <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"/>
- </resultMap>
- <!-- 小程序首页分页查询站点信息 -->
- <select id="selectAppletStationInfoPage" resultMap="AppletStationInfoResultMap">
- SELECT
- tpsi.id AS station_info_id,
- tpsi.station_name,
- tpsi.station_tips,
- <!-- 计算距离(km) -->
- <if test="query.longitude != null and query.latitude != null">
- ROUND(
- 6371 * ACOS(
- COS(RADIANS(#{query.latitude})) * COS(RADIANS(tpsi.station_lat))
- * COS(RADIANS(tpsi.station_lng) - RADIANS(#{query.longitude}))
- + SIN(RADIANS(#{query.latitude})) * SIN(RADIANS(tpsi.station_lat))
- ), 2
- ) AS distance,
- </if>
- <if test="query.longitude == null or query.latitude == null">
- NULL AS distance,
- </if>
- <!-- 快充统计(空闲/总数) -->
- 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 <= #{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 <= #{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 <= #{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
- <if test="query.sortType != null">
- <if test="query.sortType == 1 and query.longitude != null and query.latitude != null">
- ORDER BY distance ASC
- </if>
- <if test="query.sortType == 3">
- ORDER BY platform_price ASC
- </if>
- </if>
- <if test="query.sortType == null or (query.sortType == 1 and (query.longitude == null or query.latitude == null))">
- ORDER BY tpsi.update_time DESC
- </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 <= #{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 <= #{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 <= #{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>
|