ChargeOrderMapper.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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.kym.mapper.miniapp.ChargeOrderMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.kym.entity.miniapp.ChargeOrder">
  6. <id column="id" property="id"/>
  7. <result column="user_id" property="userId"/>
  8. <result column="station_id" property="stationId"/>
  9. <result column="start_charge_seq" property="startChargeSeq"/>
  10. <result column="connector_id" property="connectorId"/>
  11. <result column="start_time" property="startTime"/>
  12. <result column="end_time" property="endTime"/>
  13. <result column="soc" property="soc"/>
  14. <result column="total_power" property="totalPower"/>
  15. <result column="total_money" property="totalMoney"/>
  16. <result column="elec_money" property="elecMoney"/>
  17. <result column="service_money" property="serviceMoney"/>
  18. <result column="sum_period" property="sumPeriod"/>
  19. <result column="charge_detail" property="chargeDetail"/>
  20. <result column="order_status" property="orderStatus"/>
  21. <result column="charge_status" property="chargeStatus"/>
  22. <result column="stop_reason" property="stopReason"/>
  23. <result column="invoice_status" property="invoiceStatus"/>
  24. <result column="invoice_id" property="invoiceId"/>
  25. <result column="create_time" property="createTime"/>
  26. <result column="update_time" property="updateTime"/>
  27. </resultMap>
  28. <resultMap id="CustomChargeOrderMap" type="com.kym.entity.admin.vo.CustomOrderVo">
  29. <result column="user_id" property="userId"/>
  30. <result column="mobile_phone" property="mobilePhone"/>
  31. <result column="start_charge_seq" property="startChargeSeq"/>
  32. <result column="station_id" property="stationId"/>
  33. <result column="connector_id" property="connectorId"/>
  34. <result column="start_time" property="startTime"/>
  35. <result column="end_time" property="endTime"/>
  36. <result column="total_power" property="totalPower"/>
  37. <result column="total_money" property="totalMoney"/>
  38. <result column="elec_money" property="elecMoney"/>
  39. <result column="service_money" property="serviceMoney"/>
  40. <result column="order_status" property="orderStatus"/>
  41. <result column="charge_status" property="chargeStatus"/>
  42. </resultMap>
  43. <resultMap id="StationStatMap" type="com.kym.entity.admin.vo.StationStatVo">
  44. <!-- <result column="station_id" property="stationId"/>-->
  45. <result column="start_time" property="startTime"/>
  46. <result column="total_orders" property="totalOrders"/>
  47. <result column="total_power" property="totalPower"/>
  48. <result column="total_money" property="totalMoney"/>
  49. <result column="elec_money" property="elecMoney"/>
  50. <result column="service_money" property="serviceMoney"/>
  51. </resultMap>
  52. <!-- 通用查询结果列 -->
  53. <sql id="Base_Column_List">
  54. id, user_id, station_id, start_charge_seq, connector_id, start_time, end_time, soc, total_power, total_money, elec_money, service_money, sum_period, charge_detail, order_status, charge_status, stop_reason, invoice_status,invoice_id,create_time, update_time
  55. </sql>
  56. <select id="statChargeOrders" resultType="java.util.Map"
  57. parameterType="com.kym.entity.admin.queryParams.CustomChargeOrdersQueryParam">
  58. SELECT
  59. count(*) totalOrders,
  60. sum(t1.total_power) totalPower,
  61. sum(t1.total_money) totalMoney,
  62. sum(t1.elec_money) elecMoney,
  63. sum(t1.service_money) serviceMoney
  64. FROM
  65. t_charge_order t1
  66. LEFT JOIN t_user t2
  67. ON t1.user_id = t2.id
  68. <where>
  69. <if test="params.userId != null">
  70. and t2.user_id = #{params.userId}
  71. </if>
  72. <if test="params.mobilePhone != null and params.mobilePhone != ''">
  73. and t2.mobile_phone = #{params.mobilePhone}
  74. </if>
  75. <if test="params.connectorId != null and params.connectorId != ''">
  76. and t1.connector_id = #{params.connectorId}
  77. </if>
  78. <if test="params.startChargeSeq != null and params.startChargeSeq != ''">
  79. and t1.start_charge_seq = #{params.startChargeSeq}
  80. </if>
  81. <if test="params.stationId != null and params.stationId != ''">
  82. and t1.station_id = #{params.stationId}
  83. </if>
  84. <if test="params.orderStatus != null">
  85. and t1.order_status = #{params.orderStatus}
  86. </if>
  87. <if test="params.startDate != null and params.startDate != ''">
  88. and t1.start_time &gt;= #{params.startDate}
  89. </if>
  90. <if test="params.endDate != null and params.endDate != ''">
  91. and t1.end_time &lt;= #{params.endDate}
  92. </if>
  93. </where>
  94. </select>
  95. <select id="listChargeOrders" resultMap="CustomChargeOrderMap"
  96. parameterType="com.kym.entity.admin.queryParams.CustomChargeOrdersQueryParam">
  97. SELECT
  98. t1.user_id,
  99. t2.mobile_phone,
  100. t1.start_charge_seq,
  101. t1.station_id,
  102. t1.connector_id,
  103. t1.start_time,
  104. t1.end_time,
  105. t1.total_power,
  106. t1.total_money,
  107. t1.elec_money,
  108. t1.service_money,
  109. t1.order_status,
  110. t1.charge_status
  111. FROM
  112. t_charge_order t1
  113. LEFT JOIN t_user t2
  114. ON t1.user_id = t2.id
  115. <where>
  116. <if test="params.userId != null">
  117. and t2.user_id = #{params.userId}
  118. </if>
  119. <if test="params.mobilePhone != null and params.mobilePhone != ''">
  120. and t2.mobile_phone = #{params.mobilePhone}
  121. </if>
  122. <if test="params.connectorId != null and params.connectorId != ''">
  123. and t1.connector_id = #{params.connectorId}
  124. </if>
  125. <if test="params.stationId != null and params.stationId != ''">
  126. and t1.station_id = #{params.stationId}
  127. </if>
  128. <if test="params.startChargeSeq != null and params.startChargeSeq != ''">
  129. and t1.start_charge_seq = #{params.startChargeSeq}
  130. </if>
  131. <if test="params.orderStatus != null">
  132. and t1.order_status = #{params.orderStatus}
  133. </if>
  134. <if test="params.startDate != null and params.startDate != ''">
  135. and t1.start_time &gt;= #{params.startDate}
  136. </if>
  137. <if test="params.endDate != null and params.endDate != ''">
  138. and t1.end_time &lt;= #{params.endDate}
  139. </if>
  140. </where>
  141. order by t1.start_time desc
  142. </select>
  143. <select id="stationStat" resultMap="StationStatMap" parameterType="com.kym.entity.admin.queryParams.StatQueryParam">
  144. SELECT
  145. <if test="params.stationId != null and params.stationId != ''">
  146. t1.station_id,
  147. </if>
  148. <if test="params.type == null or params.type == 'day'">
  149. DATE_FORMAT(t1.start_time, '%Y-%m-%d')
  150. </if>
  151. <if test="params.type != null and params.type == 'month'">
  152. DATE_FORMAT(t1.start_time, '%Y-%m')
  153. </if>
  154. stat_time,
  155. count(t1.id) total_orders,
  156. SUM(t1.total_power) total_power,
  157. SUM(t1.total_money) total_money,
  158. SUM(t1.elec_money) elec_money,
  159. SUM(t1.service_money) service_money
  160. FROM
  161. (SELECT
  162. *
  163. FROM
  164. t_charge_order
  165. <where>
  166. <if test="params.stationId != null and params.stationId != ''">
  167. and station_id = #{params.stationId}
  168. </if>
  169. </where>
  170. ) t1
  171. GROUP BY stat_time
  172. <trim prefix="having" suffixOverrides="and">
  173. <if test="params.startTime != null and params.startTime != ''">
  174. stat_time &gt;= #{params.startTime} and
  175. </if>
  176. <if test="params.endTime != null and params.endTime != ''">
  177. stat_time &lt;= #{params.endTime} and
  178. </if>
  179. </trim>
  180. order by stat_time desc
  181. </select>
  182. <select id="stationTodayStat" resultType="java.util.Map" parameterType="String">
  183. SELECT
  184. COUNT(DISTINCT (t1.user_id)) chargeUsers,
  185. COUNT(t1.id) totalOrders,
  186. IFNULL (SUM(t1.total_power),0) totalPower,
  187. IFNULL(SUM(t1.total_money),0) totalMoney,
  188. IFNULL(SUM(t1.elec_money),0) elecMoney,
  189. IFNULL(SUM(t1.service_money),0) serviceMoney
  190. FROM
  191. (SELECT
  192. *
  193. FROM
  194. t_charge_order
  195. <where>
  196. <if test="stationId != null and stationId != ''">
  197. AND station_id = #{stationId}
  198. </if>
  199. AND start_time &gt;= DATE_FORMAT(NOW(), '%Y-%m-%d 00:00:00')
  200. AND start_time &lt;= DATE_FORMAT(NOW(), '%Y-%m-%d 23:59:59')) t1
  201. </where>
  202. </select>
  203. </mapper>