ThirdPartyStationInfoMapper.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.zsElectric.boot.business.mapper.ThirdPartyStationInfoMapper">
  4. <resultMap id="StationInfoResultMap" type="com.zsElectric.boot.business.model.vo.ThirdPartyStationInfoVO">
  5. <id property="id" column="id"/>
  6. <result property="stationId" column="station_id"/>
  7. <result property="stationName" column="station_name"/>
  8. <result property="areaCode" column="area_code"/>
  9. <result property="equipmentOwnerId" column="equipment_owner_id"/>
  10. <result property="address" column="address"/>
  11. <result property="construction" column="construction"/>
  12. <result property="equipmentCount" column="equipment_count"/>
  13. <result property="stationStatus" column="station_status"/>
  14. <result property="serviceTel" column="service_tel"/>
  15. <result property="stationType" column="station_type"/>
  16. <result property="stationLng" column="station_lng"/>
  17. <result property="stationLat" column="station_lat"/>
  18. <result property="siteGuide" column="site_guide"/>
  19. <result property="stationTips" column="station_tips"/>
  20. <result property="salesType" column="sales_type"/>
  21. <result property="firmId" column="firm_id"/>
  22. <result property="thirdPartyId" column="third_party_id"/>
  23. </resultMap>
  24. <select id="selectStationInfoPage" resultMap="StationInfoResultMap">
  25. SELECT
  26. tpsi.id,
  27. tpsi.station_id,
  28. tpsi.station_name,
  29. tpsi.area_code,
  30. tpsi.equipment_owner_id,
  31. tpsi.address,
  32. tpsi.construction,
  33. COUNT(DISTINCT tpei.id) AS equipment_count,
  34. tpsi.station_status,
  35. tpsi.service_tel,
  36. tpsi.station_type,
  37. tpsi.station_lng,
  38. tpsi.station_lat,
  39. tpsi.site_guide
  40. FROM third_party_station_info tpsi
  41. LEFT JOIN third_party_equipment_info tpei ON tpsi.station_id = tpei.station_id AND tpei.is_deleted = 0
  42. WHERE tpsi.is_deleted = 0
  43. <if test="query.stationId != null and query.stationId != ''">
  44. AND tpsi.station_id = #{query.stationId}
  45. </if>
  46. <if test="query.stationName != null and query.stationName != ''">
  47. AND tpsi.station_name LIKE CONCAT('%', #{query.stationName}, '%')
  48. </if>
  49. <if test="query.areaCode != null and query.areaCode != ''">
  50. AND tpsi.area_code = #{query.areaCode}
  51. </if>
  52. <if test="query.equipmentOwnerId != null and query.equipmentOwnerId != ''">
  53. AND tpsi.equipment_owner_id = #{query.equipmentOwnerId}
  54. </if>
  55. <if test="query.stationStatus != null and query.stationStatus != 0">
  56. AND tpsi.station_status = #{query.stationStatus}
  57. </if>
  58. <if test="query.stationType != null and query.stationType != 0">
  59. AND tpsi.station_type = #{query.stationType}
  60. </if>
  61. <if test="query.serviceTel != null and query.serviceTel != ''">
  62. AND tpsi.service_tel = #{query.serviceTel}
  63. </if>
  64. GROUP BY tpsi.id
  65. ORDER BY tpsi.update_time DESC
  66. </select>
  67. <select id="selectStationInfoPageByEquipment" resultMap="StationInfoResultMap">
  68. SELECT
  69. tpsi.id,
  70. tpsi.station_id,
  71. tpsi.station_name,
  72. tpsi.area_code,
  73. tpsi.equipment_owner_id,
  74. tpsi.address,
  75. tpsi.construction,
  76. COUNT(DISTINCT tpei.id) AS equipment_count,
  77. tpsi.station_status,
  78. tpsi.service_tel,
  79. tpsi.station_type,
  80. tpsi.station_lng,
  81. tpsi.station_lat,
  82. tpsi.site_guide,
  83. tpsi.station_tips,
  84. CASE
  85. WHEN pf.firm_id IS NOT NULL THEN 1
  86. WHEN pf.third_party_id IS NOT NULL THEN 2
  87. ELSE 0
  88. END AS sales_type,
  89. pf.firm_id,
  90. pf.third_party_id
  91. FROM third_party_station_info tpsi
  92. LEFT JOIN third_party_equipment_info tpei ON tpsi.station_id = tpei.station_id AND tpei.is_deleted = 0
  93. LEFT JOIN (
  94. SELECT p1.station_info_id, p1.firm_id, p1.third_party_id
  95. FROM c_policy_fee p1
  96. INNER JOIN (
  97. SELECT station_info_id,
  98. IFNULL(firm_id, 0) AS grp_firm_id,
  99. IFNULL(third_party_id, 0) AS grp_third_party_id,
  100. MIN(id) AS min_id
  101. FROM c_policy_fee
  102. WHERE is_deleted = 0
  103. GROUP BY station_info_id, IFNULL(firm_id, 0), IFNULL(third_party_id, 0)
  104. ) p2 ON p1.id = p2.min_id
  105. WHERE p1.is_deleted = 0
  106. ) pf ON pf.station_info_id = tpsi.id
  107. WHERE tpsi.is_deleted = 0
  108. AND tpsi.equipment_owner_id = 'MA6DP6BE7'
  109. AND tpsi.policy_configured = 1
  110. <if test="query.stationId != null and query.stationId != ''">
  111. AND tpsi.station_id = #{query.stationId}
  112. </if>
  113. <if test="query.stationName != null and query.stationName != ''">
  114. AND tpsi.station_name LIKE CONCAT('%', #{query.stationName}, '%')
  115. </if>
  116. <if test="query.areaCode != null and query.areaCode != ''">
  117. AND tpsi.area_code = #{query.areaCode}
  118. </if>
  119. <if test="query.equipmentOwnerId != null and query.equipmentOwnerId != ''">
  120. AND tpsi.equipment_owner_id = #{query.equipmentOwnerId}
  121. </if>
  122. <if test="query.stationStatus != null and query.stationStatus != 0">
  123. AND tpsi.station_status = #{query.stationStatus}
  124. </if>
  125. <if test="query.stationType != null and query.stationType != 0">
  126. AND tpsi.station_type = #{query.stationType}
  127. </if>
  128. <if test="query.serviceTel != null and query.serviceTel != ''">
  129. AND tpsi.service_tel = #{query.serviceTel}
  130. </if>
  131. GROUP BY tpsi.id, pf.firm_id, pf.third_party_id
  132. ORDER BY tpsi.update_time DESC
  133. </select>
  134. <!-- 小程序首页站点信息查询结果映射 -->
  135. <resultMap id="AppletStationInfoResultMap" type="com.zsElectric.boot.business.model.vo.StationInfoVO">
  136. <result property="stationId" column="station_info_id"/>
  137. <result property="stationName" column="station_name"/>
  138. <result property="tips" column="station_tips"/>
  139. <result property="distance" column="distance"/>
  140. <result property="fastCharging" column="fast_charging"/>
  141. <result property="slowCharging" column="slow_charging"/>
  142. <result property="peakValue" column="peak_value"/>
  143. <result property="peakTime" column="peak_time"/>
  144. <result property="platformPrice" column="platform_price"/>
  145. <result property="enterprisePrice" column="enterprise_price"/>
  146. </resultMap>
  147. <!-- 小程序首页分页查询站点信息 -->
  148. <select id="selectAppletStationInfoPage" resultMap="AppletStationInfoResultMap">
  149. SELECT
  150. tpsi.id AS station_info_id,
  151. tpsi.station_name,
  152. tpsi.station_tips,
  153. <!-- 计算距离(km) -->
  154. <if test="query.longitude != null and query.latitude != null">
  155. ROUND(
  156. 6371 * ACOS(
  157. COS(RADIANS(#{query.latitude})) * COS(RADIANS(tpsi.station_lat))
  158. * COS(RADIANS(tpsi.station_lng) - RADIANS(#{query.longitude}))
  159. + SIN(RADIANS(#{query.latitude})) * SIN(RADIANS(tpsi.station_lat))
  160. ), 2
  161. ) AS distance,
  162. </if>
  163. <if test="query.longitude == null or query.latitude == null">
  164. NULL AS distance,
  165. </if>
  166. <!-- 快充统计(空闲/总数) -->
  167. CONCAT(
  168. COUNT(tpci.id),
  169. '/',
  170. COUNT(tpci.id)
  171. ) AS fast_charging,
  172. <!-- 慢充统计(直接0/0) -->
  173. '0/0' AS slow_charging,
  174. <!-- 峰值(根据当前时段获取) -->
  175. (
  176. SELECT
  177. CASE tppi.period_flag
  178. WHEN 1 THEN '尖'
  179. WHEN 2 THEN '峰'
  180. WHEN 3 THEN '平'
  181. WHEN 4 THEN '谷'
  182. ELSE ''
  183. END
  184. FROM third_party_policy_info tppi
  185. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  186. INNER JOIN third_party_connector_info tpci2 ON tpepp.connector_id = tpci2.connector_id AND tpci2.is_deleted = 0
  187. WHERE tpci2.station_id = tpsi.station_id
  188. AND tppi.is_deleted = 0
  189. AND tppi.start_time &lt;= #{currentTime}
  190. ORDER BY tppi.start_time DESC
  191. LIMIT 1
  192. ) AS peak_value,
  193. <!-- 峰时段时间(period_flag=2为峰时段),格式: HH:mm - HH:mm -->
  194. (
  195. SELECT CONCAT(
  196. CONCAT(SUBSTRING(tppi.start_time, 1, 2), ':', SUBSTRING(tppi.start_time, 3, 2)),
  197. ' - ',
  198. IFNULL(
  199. (
  200. SELECT CONCAT(SUBSTRING(next_tppi.start_time, 1, 2), ':', SUBSTRING(next_tppi.start_time, 3, 2))
  201. FROM third_party_policy_info next_tppi
  202. WHERE next_tppi.price_policy_id = tppi.price_policy_id
  203. AND next_tppi.is_deleted = 0
  204. AND next_tppi.start_time > tppi.start_time
  205. ORDER BY next_tppi.start_time ASC
  206. LIMIT 1
  207. ),
  208. '24:00'
  209. )
  210. )
  211. FROM third_party_policy_info tppi
  212. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  213. INNER JOIN third_party_connector_info tpci5 ON tpepp.connector_id = tpci5.connector_id AND tpci5.is_deleted = 0
  214. WHERE tpci5.station_id = tpsi.station_id
  215. AND tppi.is_deleted = 0
  216. AND tppi.period_flag = 2
  217. LIMIT 1
  218. ) AS peak_time,
  219. <!-- 平台价(电费+服务费+运营费+综合销售费) -->
  220. (
  221. SELECT
  222. ROUND(
  223. IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)
  224. + IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0),
  225. 4
  226. )
  227. FROM c_policy_fee pf
  228. INNER JOIN third_party_policy_info tppi ON pf.start_time = tppi.start_time
  229. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  230. INNER JOIN third_party_connector_info tpci3 ON tpepp.connector_id = tpci3.connector_id AND tpci3.is_deleted = 0
  231. WHERE tpci3.station_id = tpsi.station_id
  232. AND pf.station_info_id = tpsi.id
  233. AND pf.sales_type = 0
  234. AND pf.is_deleted = 0
  235. AND tppi.is_deleted = 0
  236. AND pf.start_time &lt;= #{currentTime}
  237. ORDER BY pf.start_time DESC
  238. LIMIT 1
  239. ) AS platform_price,
  240. <!-- 企业价(如果有企业ID) -->
  241. <if test="firmId != null">
  242. (
  243. SELECT
  244. ROUND(
  245. IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)
  246. + IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0),
  247. 4
  248. )
  249. FROM c_policy_fee pf
  250. INNER JOIN third_party_policy_info tppi ON pf.start_time = tppi.start_time
  251. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  252. INNER JOIN third_party_connector_info tpci4 ON tpepp.connector_id = tpci4.connector_id AND tpci4.is_deleted = 0
  253. WHERE tpci4.station_id = tpsi.station_id
  254. AND pf.station_info_id = tpsi.id
  255. AND pf.sales_type = 1
  256. AND pf.firm_id = #{firmId}
  257. AND pf.is_deleted = 0
  258. AND tppi.is_deleted = 0
  259. AND pf.start_time &lt;= #{currentTime}
  260. ORDER BY pf.start_time DESC
  261. LIMIT 1
  262. ) AS enterprise_price
  263. </if>
  264. <if test="firmId == null">
  265. NULL AS enterprise_price
  266. </if>
  267. FROM third_party_station_info tpsi
  268. LEFT JOIN third_party_connector_info tpci ON tpsi.station_id = tpci.station_id AND tpci.is_deleted = 0
  269. WHERE tpsi.is_deleted = 0
  270. AND tpsi.equipment_owner_id = 'MA6DP6BE7'
  271. AND tpsi.policy_configured = 1
  272. <!-- 确保存在平台价配置 -->
  273. AND EXISTS (
  274. SELECT 1 FROM c_policy_fee pf_check
  275. WHERE pf_check.station_info_id = tpsi.id
  276. AND pf_check.sales_type = 0
  277. AND pf_check.is_deleted = 0
  278. AND (pf_check.op_fee IS NOT NULL OR pf_check.comp_sales_fee IS NOT NULL)
  279. )
  280. GROUP BY tpsi.id
  281. <if test="query.sortType != null">
  282. <if test="query.sortType == 1 and query.longitude != null and query.latitude != null">
  283. ORDER BY distance ASC
  284. </if>
  285. <if test="query.sortType == 3">
  286. ORDER BY platform_price ASC
  287. </if>
  288. </if>
  289. <if test="query.sortType == null or (query.sortType == 1 and (query.longitude == null or query.latitude == null))">
  290. ORDER BY tpsi.update_time DESC
  291. </if>
  292. </select>
  293. <!-- 小程序首页地图模式站点信息查询结果映射 -->
  294. <resultMap id="AppletStationInfoMapResultMap" type="com.zsElectric.boot.business.model.vo.StationInfoMapVO">
  295. <result property="stationId" column="station_info_id"/>
  296. <result property="stationName" column="station_name"/>
  297. <result property="tips" column="station_tips"/>
  298. <result property="distance" column="distance"/>
  299. <result property="fastCharging" column="fast_charging"/>
  300. <result property="slowCharging" column="slow_charging"/>
  301. <result property="peakValue" column="peak_value"/>
  302. <result property="peakTime" column="peak_time"/>
  303. <result property="platformPrice" column="platform_price"/>
  304. <result property="enterprisePrice" column="enterprise_price"/>
  305. <result property="parkingFee" column="parking_fee"/>
  306. <result property="address" column="address"/>
  307. <result property="longitude" column="station_lng"/>
  308. <result property="latitude" column="station_lat"/>
  309. </resultMap>
  310. <!-- 小程序首页地图模式查询站点列表(按距离排序) -->
  311. <select id="selectStationMapList" resultMap="AppletStationInfoMapResultMap">
  312. SELECT
  313. tpsi.id AS station_info_id,
  314. tpsi.station_name,
  315. tpsi.station_tips,
  316. tpsi.address,
  317. tpsi.station_lng,
  318. tpsi.station_lat,
  319. CAST(tpsi.park_fee AS DECIMAL(10,2)) AS parking_fee,
  320. <!-- 计算距离(km) -->
  321. ROUND(
  322. 6371 * ACOS(
  323. COS(RADIANS(#{latitude})) * COS(RADIANS(tpsi.station_lat))
  324. * COS(RADIANS(tpsi.station_lng) - RADIANS(#{longitude}))
  325. + SIN(RADIANS(#{latitude})) * SIN(RADIANS(tpsi.station_lat))
  326. ), 2
  327. ) AS distance,
  328. <!-- 快充统计(空闲/总数) -->
  329. CONCAT(
  330. COUNT(tpci.id),
  331. '/',
  332. COUNT(tpci.id)
  333. ) AS fast_charging,
  334. <!-- 慢充统计(直接0/0) -->
  335. '0/0' AS slow_charging,
  336. <!-- 峰值(根据当前时段获取) -->
  337. (
  338. SELECT
  339. CASE tppi.period_flag
  340. WHEN 1 THEN '尖'
  341. WHEN 2 THEN '峰'
  342. WHEN 3 THEN '平'
  343. WHEN 4 THEN '谷'
  344. ELSE ''
  345. END
  346. FROM third_party_policy_info tppi
  347. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  348. INNER JOIN third_party_connector_info tpci2 ON tpepp.connector_id = tpci2.connector_id AND tpci2.is_deleted = 0
  349. WHERE tpci2.station_id = tpsi.station_id
  350. AND tppi.is_deleted = 0
  351. AND tppi.start_time &lt;= #{currentTime}
  352. ORDER BY tppi.start_time DESC
  353. LIMIT 1
  354. ) AS peak_value,
  355. <!-- 峰时段时间(period_flag=2为峰时段),格式: HH:mm - HH:mm -->
  356. (
  357. SELECT CONCAT(
  358. CONCAT(SUBSTRING(tppi.start_time, 1, 2), ':', SUBSTRING(tppi.start_time, 3, 2)),
  359. ' - ',
  360. IFNULL(
  361. (
  362. SELECT CONCAT(SUBSTRING(next_tppi.start_time, 1, 2), ':', SUBSTRING(next_tppi.start_time, 3, 2))
  363. FROM third_party_policy_info next_tppi
  364. WHERE next_tppi.price_policy_id = tppi.price_policy_id
  365. AND next_tppi.is_deleted = 0
  366. AND next_tppi.start_time > tppi.start_time
  367. ORDER BY next_tppi.start_time ASC
  368. LIMIT 1
  369. ),
  370. '24:00'
  371. )
  372. )
  373. FROM third_party_policy_info tppi
  374. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  375. INNER JOIN third_party_connector_info tpci5 ON tpepp.connector_id = tpci5.connector_id AND tpci5.is_deleted = 0
  376. WHERE tpci5.station_id = tpsi.station_id
  377. AND tppi.is_deleted = 0
  378. AND tppi.period_flag = 2
  379. LIMIT 1
  380. ) AS peak_time,
  381. <!-- 平台价(电费+服务费+运营费+综合销售费) -->
  382. (
  383. SELECT
  384. ROUND(
  385. IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)
  386. + IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0),
  387. 4
  388. )
  389. FROM c_policy_fee pf
  390. INNER JOIN third_party_policy_info tppi ON pf.start_time = tppi.start_time
  391. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  392. INNER JOIN third_party_connector_info tpci3 ON tpepp.connector_id = tpci3.connector_id AND tpci3.is_deleted = 0
  393. WHERE tpci3.station_id = tpsi.station_id
  394. AND pf.station_info_id = tpsi.id
  395. AND pf.sales_type = 0
  396. AND pf.is_deleted = 0
  397. AND tppi.is_deleted = 0
  398. AND pf.start_time &lt;= #{currentTime}
  399. ORDER BY pf.start_time DESC
  400. LIMIT 1
  401. ) AS platform_price,
  402. <!-- 企业价(地图模式不需要) -->
  403. NULL AS enterprise_price
  404. FROM third_party_station_info tpsi
  405. LEFT JOIN third_party_connector_info tpci ON tpsi.station_id = tpci.station_id AND tpci.is_deleted = 0
  406. WHERE tpsi.is_deleted = 0
  407. AND tpsi.equipment_owner_id = 'MA6DP6BE7'
  408. AND tpsi.policy_configured = 1
  409. <!-- 确保存在平台价配置 -->
  410. AND EXISTS (
  411. SELECT 1 FROM c_policy_fee pf_check
  412. WHERE pf_check.station_info_id = tpsi.id
  413. AND pf_check.sales_type = 0
  414. AND pf_check.is_deleted = 0
  415. AND (pf_check.op_fee IS NOT NULL OR pf_check.comp_sales_fee IS NOT NULL)
  416. )
  417. GROUP BY tpsi.id
  418. ORDER BY distance ASC
  419. </select>
  420. <!-- 小程序站点详情查询结果映射 -->
  421. <resultMap id="AppletStationDetailResultMap" type="com.zsElectric.boot.business.model.vo.AppletStationDetailVO">
  422. <result property="stationId" column="station_info_id"/>
  423. <result property="stationName" column="station_name"/>
  424. <result property="tips" column="station_tips"/>
  425. <result property="distance" column="distance"/>
  426. <result property="address" column="address"/>
  427. <result property="pictures" column="pictures"/>
  428. <result property="currentPrice" column="current_price"/>
  429. <result property="currentPeriod" column="current_period"/>
  430. <result property="enterprisePrice" column="enterprise_price"/>
  431. <result property="originalPrice" column="original_price"/>
  432. <result property="businessHours" column="business_hours"/>
  433. <result property="serviceProvider" column="service_provider"/>
  434. <result property="invoiceProvider" column="invoice_provider"/>
  435. <result property="customerServiceHotline" column="customer_service_hotline"/>
  436. </resultMap>
  437. <!-- 小程序查询站点详情 -->
  438. <select id="selectStationDetail" resultMap="AppletStationDetailResultMap">
  439. SELECT
  440. tpsi.id AS station_info_id,
  441. tpsi.station_name,
  442. tpsi.station_tips,
  443. tpsi.address,
  444. tpsi.banner_pictures AS pictures,
  445. tpsi.own_business_hours AS business_hours,
  446. tpsi.customer_service_hotline,
  447. '华能贵州盘州市风电有限责任公司' AS service_provider,
  448. '华能贵州盘州市风电有限责任公司' AS invoice_provider,
  449. <!-- 计算距离(km) -->
  450. <if test="longitude != null and latitude != null">
  451. ROUND(
  452. 6371 * ACOS(
  453. COS(RADIANS(#{latitude})) * COS(RADIANS(tpsi.station_lat))
  454. * COS(RADIANS(tpsi.station_lng) - RADIANS(#{longitude}))
  455. + SIN(RADIANS(#{latitude})) * SIN(RADIANS(tpsi.station_lat))
  456. ), 2
  457. ) AS distance,
  458. </if>
  459. <if test="longitude == null or latitude == null">
  460. NULL AS distance,
  461. </if>
  462. <!-- 当前价(电费+服务费+运营费+综合销售费) -->
  463. (
  464. SELECT
  465. ROUND(
  466. IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)
  467. + IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0),
  468. 4
  469. )
  470. FROM c_policy_fee pf
  471. INNER JOIN third_party_policy_info tppi ON pf.start_time = tppi.start_time
  472. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  473. INNER JOIN third_party_connector_info tpci3 ON tpepp.connector_id = tpci3.connector_id AND tpci3.is_deleted = 0
  474. WHERE tpci3.station_id = tpsi.station_id
  475. AND pf.station_info_id = tpsi.id
  476. AND pf.sales_type = 0
  477. AND pf.is_deleted = 0
  478. AND tppi.is_deleted = 0
  479. AND pf.start_time &lt;= #{currentTime}
  480. ORDER BY pf.start_time DESC
  481. LIMIT 1
  482. ) AS current_price,
  483. <!-- 当前时段名称 -->
  484. (
  485. SELECT
  486. CONCAT(
  487. CASE tppi.period_flag
  488. WHEN 1 THEN '尖'
  489. WHEN 2 THEN '峰'
  490. WHEN 3 THEN '平'
  491. WHEN 4 THEN '谷'
  492. ELSE ''
  493. END,
  494. CONCAT(SUBSTRING(tppi.start_time, 1, 2), ':', SUBSTRING(tppi.start_time, 3, 2)),
  495. '-',
  496. IFNULL(
  497. (
  498. SELECT CONCAT(SUBSTRING(next_tppi.start_time, 1, 2), ':', SUBSTRING(next_tppi.start_time, 3, 2))
  499. FROM third_party_policy_info next_tppi
  500. WHERE next_tppi.price_policy_id = tppi.price_policy_id
  501. AND next_tppi.is_deleted = 0
  502. AND next_tppi.start_time > tppi.start_time
  503. ORDER BY next_tppi.start_time ASC
  504. LIMIT 1
  505. ),
  506. '24:00'
  507. )
  508. )
  509. FROM third_party_policy_info tppi
  510. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  511. INNER JOIN third_party_connector_info tpci2 ON tpepp.connector_id = tpci2.connector_id AND tpci2.is_deleted = 0
  512. WHERE tpci2.station_id = tpsi.station_id
  513. AND tppi.is_deleted = 0
  514. AND tppi.start_time &lt;= #{currentTime}
  515. ORDER BY tppi.start_time DESC
  516. LIMIT 1
  517. ) AS current_period,
  518. <!-- 原价(电费+服务费) -->
  519. (
  520. SELECT
  521. ROUND(IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0), 4)
  522. FROM third_party_policy_info tppi
  523. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  524. INNER JOIN third_party_connector_info tpci4 ON tpepp.connector_id = tpci4.connector_id AND tpci4.is_deleted = 0
  525. WHERE tpci4.station_id = tpsi.station_id
  526. AND tppi.is_deleted = 0
  527. AND tppi.start_time &lt;= #{currentTime}
  528. ORDER BY tppi.start_time DESC
  529. LIMIT 1
  530. ) AS original_price,
  531. <!-- 企业价 -->
  532. <if test="firmId != null">
  533. (
  534. SELECT
  535. ROUND(
  536. IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)
  537. + IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0),
  538. 4
  539. )
  540. FROM c_policy_fee pf
  541. INNER JOIN third_party_policy_info tppi ON pf.start_time = tppi.start_time
  542. INNER JOIN third_party_equipment_price_policy tpepp ON tppi.price_policy_id = tpepp.id AND tpepp.is_deleted = 0
  543. INNER JOIN third_party_connector_info tpci5 ON tpepp.connector_id = tpci5.connector_id AND tpci5.is_deleted = 0
  544. WHERE tpci5.station_id = tpsi.station_id
  545. AND pf.station_info_id = tpsi.id
  546. AND pf.sales_type = 1
  547. AND pf.firm_id = #{firmId}
  548. AND pf.is_deleted = 0
  549. AND tppi.is_deleted = 0
  550. AND pf.start_time &lt;= #{currentTime}
  551. ORDER BY pf.start_time DESC
  552. LIMIT 1
  553. ) AS enterprise_price
  554. </if>
  555. <if test="firmId == null">
  556. NULL AS enterprise_price
  557. </if>
  558. FROM third_party_station_info tpsi
  559. WHERE tpsi.is_deleted = 0
  560. AND tpsi.id = #{stationId}
  561. </select>
  562. <!-- 查询用户当前正在充电中的订单实时费用 -->
  563. <resultMap id="AppletChargingCostResultMap" type="com.zsElectric.boot.business.model.vo.applet.AppletChargingCostVO">
  564. <result property="chargeOrderNo" column="charge_order_no"/>
  565. <result property="stationName" column="station_name"/>
  566. <result property="connectorName" column="connector_name"/>
  567. <result property="orderStatus" column="order_status"/>
  568. <result property="orderStatusDesc" column="order_status_desc"/>
  569. <result property="chargingDuration" column="charging_duration"/>
  570. <result property="chargingDurationDesc" column="charging_duration_desc"/>
  571. <result property="totalPower" column="total_power"/>
  572. <result property="elecMoney" column="elec_money"/>
  573. <result property="serviceMoney" column="service_money"/>
  574. <result property="totalMoney" column="total_money"/>
  575. <result property="soc" column="soc"/>
  576. <result property="current" column="current"/>
  577. <result property="voltage" column="voltage"/>
  578. <result property="power" column="power"/>
  579. <result property="startTime" column="start_time"/>
  580. <result property="lastUpdateTime" column="last_update_time"/>
  581. </resultMap>
  582. <select id="selectCurrentChargingCost" resultMap="AppletChargingCostResultMap">
  583. SELECT
  584. coi.charge_order_no,
  585. tpsi.station_name,
  586. tpci.connector_name,
  587. tcs.start_charge_seq_stat AS order_status,
  588. CASE tcs.start_charge_seq_stat
  589. WHEN 1 THEN '启动中'
  590. WHEN 2 THEN '充电中'
  591. WHEN 3 THEN '停止中'
  592. WHEN 4 THEN '已结束'
  593. WHEN 5 THEN '未知'
  594. ELSE '未知'
  595. END AS order_status_desc,
  596. TIMESTAMPDIFF(SECOND, tcs.start_time, tcs.end_time) AS charging_duration,
  597. CONCAT(
  598. LPAD(FLOOR(TIMESTAMPDIFF(SECOND, tcs.start_time, tcs.end_time) / 3600), 2, '0'), ':',
  599. LPAD(FLOOR((TIMESTAMPDIFF(SECOND, tcs.start_time, tcs.end_time) % 3600) / 60), 2, '0'), ':',
  600. LPAD(TIMESTAMPDIFF(SECOND, tcs.start_time, tcs.end_time) % 60, 2, '0')
  601. ) AS charging_duration_desc,
  602. IFNULL(tcs.total_power, 0) AS total_power,
  603. IFNULL(tcs.elec_money, 0) AS elec_money,
  604. IFNULL(tcs.service_money, 0) AS service_money,
  605. IFNULL(tcs.total_money, 0) AS total_money,
  606. tcs.soc,
  607. COALESCE(tcs.current_a, tcs.current_b, tcs.current_c) AS current,
  608. COALESCE(tcs.voltage_a, tcs.voltage_b, tcs.voltage_c) AS voltage,
  609. ROUND(
  610. COALESCE(tcs.voltage_a, tcs.voltage_b, tcs.voltage_c) *
  611. COALESCE(tcs.current_a, tcs.current_b, tcs.current_c) / 1000,
  612. 2
  613. ) AS power,
  614. DATE_FORMAT(tcs.start_time, '%Y-%m-%d %H:%i:%s') AS start_time,
  615. DATE_FORMAT(tcs.update_time, '%Y-%m-%d %H:%i:%s') AS last_update_time
  616. FROM c_charge_order_info coi
  617. INNER JOIN third_party_charge_status tcs
  618. ON coi.charge_order_no = tcs.start_charge_seq
  619. INNER JOIN third_party_connector_info tpci
  620. ON tcs.connector_id = tpci.connector_id
  621. AND tpci.is_deleted = 0
  622. INNER JOIN third_party_station_info tpsi
  623. ON tpci.station_id = tpsi.station_id
  624. AND tpsi.is_deleted = 0
  625. WHERE coi.user_id = #{userId}
  626. AND coi.status = 1
  627. AND coi.is_deleted = 0
  628. ORDER BY tcs.update_time DESC
  629. LIMIT 1
  630. </select>
  631. </mapper>