ThirdPartyConnectorInfoMapper.xml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.charging.mapper.ThirdPartyConnectorInfoMapper">
  4. <!-- 充电接口详情结果映射 -->
  5. <resultMap id="ConnectorDetailResultMap" type="com.zsElectric.boot.business.model.vo.applet.AppletConnectorDetailVO">
  6. <result property="connectorId" column="connector_id"/>
  7. <result property="connectorCode" column="connector_code"/>
  8. <result property="connectorName" column="connector_name"/>
  9. <result property="stationId" column="station_id"/>
  10. <result property="stationName" column="station_name"/>
  11. <result property="stationAddress" column="station_address"/>
  12. <result property="equipmentId" column="equipment_id"/>
  13. <result property="equipmentCode" column="equipment_code"/>
  14. <result property="equipmentName" column="equipment_name"/>
  15. <result property="equipmentType" column="equipment_type"/>
  16. <result property="equipmentTypeName" column="equipment_type_name"/>
  17. <result property="parkNo" column="park_no"/>
  18. <result property="status" column="status"/>
  19. <result property="statusName" column="status_name"/>
  20. <result property="connectorType" column="connector_type"/>
  21. <result property="connectorTypeName" column="connector_type_name"/>
  22. <result property="voltageUpperLimits" column="voltage_upper_limits"/>
  23. <result property="voltageLowerLimits" column="voltage_lower_limits"/>
  24. <result property="current" column="current"/>
  25. <result property="power" column="power"/>
  26. <result property="nationalStandard" column="national_standard"/>
  27. <result property="nationalStandardName" column="national_standard_name"/>
  28. <result property="currentPrice" column="current_price"/>
  29. <result property="enterprisePrice" column="enterprise_price"/>
  30. <result property="currentPeriodDesc" column="current_period_desc"/>
  31. <result property="parkingTips" column="parking_tips"/>
  32. <result property="availableBalance" column="available_balance"/>
  33. <result property="newUserDiscount" column="new_user_discount"/>
  34. <result property="lastUpdateTime" column="last_update_time"/>
  35. </resultMap>
  36. <!-- 获取充电接口详情(一次SQL查询获取所有信息) -->
  37. <select id="selectConnectorDetailById" resultMap="ConnectorDetailResultMap">
  38. SELECT
  39. -- 充电接口基本信息
  40. tpci.id AS connector_id,
  41. tpci.connector_id AS connector_code,
  42. tpci.connector_name,
  43. tpci.park_no,
  44. tpci.status,
  45. CASE tpci.status
  46. WHEN 0 THEN '离网'
  47. WHEN 1 THEN '空闲'
  48. WHEN 2 THEN '占用(未充电)'
  49. WHEN 3 THEN '占用(充电中)'
  50. WHEN 4 THEN '占用(预约锁定)'
  51. WHEN 255 THEN '故障'
  52. ELSE '未知'
  53. END AS status_name,
  54. tpci.connector_type,
  55. CASE tpci.connector_type
  56. WHEN 1 THEN '家用插座'
  57. WHEN 2 THEN '交流接口插座'
  58. WHEN 3 THEN '交流接口插头'
  59. WHEN 4 THEN '直流接口枪头'
  60. WHEN 5 THEN '无线充电座'
  61. WHEN 6 THEN '其他'
  62. ELSE '未知'
  63. END AS connector_type_name,
  64. tpci.voltage_upper_limits,
  65. tpci.voltage_lower_limits,
  66. tpci.current,
  67. tpci.power,
  68. tpci.national_standard,
  69. CASE tpci.national_standard
  70. WHEN 1 THEN '2011版'
  71. WHEN 2 THEN '2015版'
  72. ELSE '未知'
  73. END AS national_standard_name,
  74. tpci.update_time AS last_update_time,
  75. -- 设备信息
  76. tpei.id AS equipment_id,
  77. tpei.equipment_id AS equipment_code,
  78. tpei.equipment_name,
  79. tpei.equipment_type,
  80. CASE tpei.equipment_type
  81. WHEN 1 THEN '直流设备'
  82. WHEN 2 THEN '交流设备'
  83. WHEN 3 THEN '交直流一体设备'
  84. WHEN 4 THEN '无线设备'
  85. WHEN 5 THEN '其他'
  86. ELSE '未知'
  87. END AS equipment_type_name,
  88. -- 站点信息
  89. tpsi.id AS station_id,
  90. tpsi.station_name,
  91. tpsi.address AS station_address,
  92. tpsi.station_tips AS parking_tips,
  93. -- 当前价格(电价 + 服务费)
  94. (IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0)) AS current_price,
  95. -- 当前时段描述(格式:峰 HH:mm-HH:mm)
  96. (
  97. SELECT CONCAT(
  98. CASE t1.period_flag
  99. WHEN 1 THEN '尖 '
  100. WHEN 2 THEN '峰 '
  101. WHEN 3 THEN '平 '
  102. WHEN 4 THEN '谷 '
  103. ELSE ''
  104. END,
  105. CONCAT(SUBSTRING(t1.start_time, 1, 2), ':', SUBSTRING(t1.start_time, 3, 2)),
  106. '-',
  107. IFNULL(
  108. CONCAT(SUBSTRING(t2.start_time, 1, 2), ':', SUBSTRING(t2.start_time, 3, 2)),
  109. '24:00'
  110. )
  111. )
  112. FROM third_party_policy_info t1
  113. LEFT JOIN third_party_policy_info t2 ON t2.price_policy_id = t1.price_policy_id
  114. AND t2.is_deleted = 0
  115. AND t2.start_time > t1.start_time
  116. AND t2.id = (
  117. SELECT id FROM third_party_policy_info
  118. WHERE price_policy_id = t1.price_policy_id
  119. AND is_deleted = 0
  120. AND start_time > t1.start_time
  121. ORDER BY start_time ASC
  122. LIMIT 1
  123. )
  124. WHERE t1.id = tppi.id
  125. ) AS current_period_desc,
  126. -- 企业价格(电价 + 服务费 + 运营费 + 综合销售费)
  127. (IFNULL(tppi.elec_price, 0) + IFNULL(tppi.service_price, 0) +
  128. IFNULL(pf.op_fee, 0) + IFNULL(pf.comp_sales_fee, 0)) AS enterprise_price,
  129. -- 用户余额(从参数传入)
  130. #{userBalance} AS available_balance,
  131. -- 新用户优惠金额(从参数传入)
  132. #{newUserDiscount} AS new_user_discount
  133. FROM third_party_connector_info tpci
  134. -- 关联设备信息
  135. LEFT JOIN third_party_equipment_info tpei
  136. ON tpci.equipment_id = tpei.equipment_id
  137. AND tpei.is_deleted = 0
  138. -- 关联站点信息
  139. LEFT JOIN third_party_station_info tpsi
  140. ON tpei.station_id = tpsi.station_id
  141. AND tpsi.is_deleted = 0
  142. -- 关联价格策略
  143. LEFT JOIN third_party_equipment_price_policy tpepp
  144. ON tpci.connector_id = tpepp.connector_id
  145. AND tpepp.is_deleted = 0
  146. -- 关联当前时段的价格信息(子查询获取当前时段)
  147. LEFT JOIN third_party_policy_info tppi ON tppi.id = (
  148. SELECT id
  149. FROM third_party_policy_info
  150. WHERE price_policy_id = tpepp.id
  151. AND is_deleted = 0
  152. AND start_time &lt;= #{currentTime}
  153. ORDER BY start_time DESC
  154. LIMIT 1
  155. )
  156. -- 关联企业价格(仅当用户ID不为空时关联)
  157. LEFT JOIN (
  158. SELECT pf1.*
  159. FROM c_policy_fee pf1
  160. INNER JOIN c_user_firm uf ON pf1.firm_id = uf.firm_id AND uf.is_deleted = 0
  161. WHERE pf1.is_deleted = 0
  162. AND pf1.sales_type = 1
  163. AND uf.user_id = #{userId}
  164. ) pf ON pf.station_info_id = tpsi.id
  165. AND pf.start_time = tppi.start_time
  166. WHERE tpci.id = #{connectorId}
  167. AND tpci.is_deleted = 0
  168. LIMIT 1
  169. </select>
  170. </mapper>