|
|
@@ -18,6 +18,9 @@
|
|
|
<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">
|
|
|
@@ -80,9 +83,24 @@
|
|
|
tpsi.station_lng,
|
|
|
tpsi.station_lat,
|
|
|
tpsi.site_guide,
|
|
|
- tpsi.station_tips
|
|
|
+ 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 station_info_id, firm_id, third_party_id,
|
|
|
+ ROW_NUMBER() OVER (PARTITION BY station_info_id,
|
|
|
+ CASE WHEN firm_id IS NOT NULL THEN 1 WHEN third_party_id IS NOT NULL THEN 2 ELSE 0 END
|
|
|
+ ORDER BY id) AS rn
|
|
|
+ FROM c_policy_fee
|
|
|
+ WHERE is_deleted = 0
|
|
|
+ ) pf ON pf.station_info_id = tpsi.id AND pf.rn = 1
|
|
|
WHERE tpsi.is_deleted = 0
|
|
|
AND tpsi.equipment_owner_id = 'MA6DP6BE7'
|
|
|
AND tpsi.policy_configured = 1
|
|
|
@@ -107,8 +125,142 @@
|
|
|
<if test="query.serviceTel != null and query.serviceTel != ''">
|
|
|
AND tpsi.service_tel = #{query.serviceTel}
|
|
|
</if>
|
|
|
- GROUP BY tpsi.id
|
|
|
+ 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="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_equipment_info tpei2 ON tpepp.equipment_id = tpei2.equipment_id AND tpei2.is_deleted = 0
|
|
|
+ WHERE tpei2.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,
|
|
|
+ <!-- 平台价(电费+服务费+运营费+综合销售费) -->
|
|
|
+ (
|
|
|
+ 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_equipment_info tpei3 ON tpepp.equipment_id = tpei3.equipment_id AND tpei3.is_deleted = 0
|
|
|
+ WHERE tpei3.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_equipment_info tpei4 ON tpepp.equipment_id = tpei4.equipment_id AND tpei4.is_deleted = 0
|
|
|
+ WHERE tpei4.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>
|
|
|
+
|
|
|
</mapper>
|