PayOrderMapper.xml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="org.dromara.business.mapper.PayOrderMapper">
  6. <!-- 动态插入(非空字段) -->
  7. <insert id="insertPayOrder" useGeneratedKeys="true" keyProperty="id">
  8. INSERT INTO pay_order
  9. <trim prefix="(" suffix=")" suffixOverrides=",">
  10. <if test="outTradeNo != null">out_trade_no,</if>
  11. <if test="subject != null">subject,</if>
  12. <if test="body != null">body,</if>
  13. <if test="totalAmount != null">total_amount,</if>
  14. <if test="currency != null">currency,</if>
  15. <if test="userId != null">user_id,</if>
  16. <if test="bizType != null">biz_type,</if>
  17. <if test="bizId != null">biz_id,</if>
  18. <if test="tradeNo != null">trade_no,</if>
  19. <if test="appId != null">app_id,</if>
  20. <if test="sellerId != null">seller_id,</if>
  21. <if test="status != null">status,</if>
  22. <if test="payTime != null">pay_time,</if>
  23. <if test="notifyTime != null">notify_time,</if>
  24. <if test="notifyType != null">notify_type,</if>
  25. <if test="tradeStatus != null">trade_status,</if>
  26. <if test="createTime != null">create_time,</if>
  27. <if test="updateTime != null">update_time,</if>
  28. <if test="productId != null">product_id,</if>
  29. <if test="relatedItemId != null">related_item_id,</if>
  30. <if test="payUrl != null">pay_url,</if>
  31. </trim>
  32. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  33. <if test="outTradeNo != null">#{outTradeNo},</if>
  34. <if test="subject != null">#{subject},</if>
  35. <if test="body != null">#{body},</if>
  36. <if test="totalAmount != null">#{totalAmount},</if>
  37. <if test="currency != null">#{currency},</if>
  38. <if test="userId != null">#{userId},</if>
  39. <if test="bizType != null">#{bizType},</if>
  40. <if test="bizId != null">#{bizId},</if>
  41. <if test="tradeNo != null">#{tradeNo},</if>
  42. <if test="appId != null">#{appId},</if>
  43. <if test="sellerId != null">#{sellerId},</if>
  44. <if test="status != null">#{status},</if>
  45. <if test="payTime != null">#{payTime},</if>
  46. <if test="notifyTime != null">#{notifyTime},</if>
  47. <if test="notifyType != null">#{notifyType},</if>
  48. <if test="tradeStatus != null">#{tradeStatus},</if>
  49. <if test="createTime != null">#{createTime},</if>
  50. <if test="updateTime != null">#{updateTime},</if>
  51. <if test="productId != null">#{productId},</if>
  52. <if test="relatedItemId != null">#{relatedItemId},</if>
  53. <if test="payUrl != null">#{payUrl},</if>
  54. </trim>
  55. </insert>
  56. <!-- 根据主键更新(仅非空字段) -->
  57. <update id="updatePayOrder">
  58. UPDATE pay_order
  59. <set>
  60. <if test="outTradeNo != null">out_trade_no = #{outTradeNo},</if>
  61. <if test="subject != null">subject = #{subject},</if>
  62. <if test="body != null">body = #{body},</if>
  63. <if test="totalAmount != null">total_amount = #{totalAmount},</if>
  64. <if test="currency != null">currency = #{currency},</if>
  65. <if test="userId != null">user_id = #{userId},</if>
  66. <if test="bizType != null">biz_type = #{bizType},</if>
  67. <if test="bizId != null">biz_id = #{bizId},</if>
  68. <if test="tradeNo != null">trade_no = #{tradeNo},</if>
  69. <if test="appId != null">app_id = #{appId},</if>
  70. <if test="sellerId != null">seller_id = #{sellerId},</if>
  71. <if test="status != null">status = #{status},</if>
  72. <if test="payTime != null">pay_time = #{payTime},</if>
  73. <if test="notifyTime != null">notify_time = #{notifyTime},</if>
  74. <if test="notifyType != null">notify_type = #{notifyType},</if>
  75. <if test="tradeStatus != null">trade_status = #{tradeStatus},</if>
  76. <if test="createTime != null">create_time = #{createTime},</if>
  77. <if test="updateTime != null">update_time = #{updateTime},</if>
  78. <if test="productId != null">product_id = #{productId},</if>
  79. <if test="relatedItemId != null">related_item_id = #{relatedItemId},</if>
  80. <if test="payUrl != null">pay_url = #{payUrl},</if>
  81. </set>
  82. WHERE id = #{id}
  83. </update>
  84. <!-- 根据 out_trade_no 更新 -->
  85. <update id="updatePayOrderByOutTradeNo">
  86. UPDATE pay_order
  87. <set>
  88. <if test="subject != null">subject = #{subject},</if>
  89. <if test="body != null">body = #{body},</if>
  90. <if test="totalAmount != null">total_amount = #{totalAmount},</if>
  91. <if test="currency != null">currency = #{currency},</if>
  92. <if test="userId != null">user_id = #{userId},</if>
  93. <if test="bizType != null">biz_type = #{bizType},</if>
  94. <if test="bizId != null">biz_id = #{bizId},</if>
  95. <if test="tradeNo != null">trade_no = #{tradeNo},</if>
  96. <if test="appId != null">app_id = #{appId},</if>
  97. <if test="sellerId != null">seller_id = #{sellerId},</if>
  98. <if test="status != null">status = #{status},</if>
  99. <if test="payTime != null">pay_time = #{payTime},</if>
  100. <if test="notifyTime != null">notify_time = #{notifyTime},</if>
  101. <if test="notifyType != null">notify_type = #{notifyType},</if>
  102. <if test="tradeStatus != null">trade_status = #{tradeStatus},</if>
  103. <if test="updateTime != null">update_time = #{updateTime},</if>
  104. <if test="productId != null">product_id = #{productId},</if>
  105. <if test="relatedItemId != null">related_item_id = #{relatedItemId},</if>
  106. <if test="payUrl != null">pay_url = #{payUrl},</if>
  107. </set>
  108. WHERE out_trade_no = #{outTradeNo}
  109. </update>
  110. <!-- 根据主键查询 -->
  111. <select id="selectPayOrderById" parameterType="java.lang.Long" resultType="org.dromara.business.domain.vo.PayOrderVo">
  112. SELECT
  113. id, out_trade_no, subject, body, total_amount, currency,
  114. user_id, biz_type, biz_id, trade_no, app_id, seller_id,
  115. status, pay_time, notify_time, notify_type, trade_status,
  116. create_time, update_time, product_id, related_item_id, pay_url
  117. FROM pay_order
  118. WHERE id = #{id}
  119. </select>
  120. <!-- 根据商户订单号查询 -->
  121. <select id="selectPayOrderByOutTradeNo" parameterType="java.lang.String" resultType="org.dromara.business.domain.vo.PayOrderVo">
  122. SELECT
  123. id, out_trade_no, subject, body, total_amount, currency,
  124. user_id, biz_type, biz_id, trade_no, app_id, seller_id,
  125. status, pay_time, notify_time, notify_type, trade_status,
  126. create_time, update_time, product_id, related_item_id, pay_url
  127. FROM pay_order
  128. WHERE out_trade_no = #{outTradeNo}
  129. </select>
  130. <!-- 查询所有(支持条件扩展) -->
  131. <select id="selectPayOrderAll" resultType="org.dromara.business.domain.vo.PayOrderVo">
  132. SELECT
  133. a.id, a.out_trade_no, a.subject, a.body, a.total_amount, a.currency,
  134. a.user_id, a.biz_type, a.biz_id, a.trade_no, a.app_id, a.seller_id,
  135. a.status, a.pay_time, a.notify_time, a.notify_type, a.trade_status,
  136. a.create_time, a.update_time, a.product_id, a.related_item_id, a.pay_url,b.phone,b.nick_name
  137. FROM pay_order a left join user b on a.user_id=b.id
  138. ${ew.customSqlSegment}
  139. </select>
  140. <delete id="deletePayOrderById">
  141. DELETE FROM pay_order
  142. <where>
  143. id IN
  144. <foreach item="id" collection="ids" open="(" separator="," close=")">
  145. <if test="id > 0">
  146. #{id}
  147. </if>
  148. </foreach>
  149. </where>
  150. </delete>
  151. <select id="selectPayOrderList" resultType="org.dromara.business.domain.vo.PayOrderVo">
  152. SELECT
  153. id, out_trade_no, subject, body, total_amount, currency,
  154. user_id, biz_type, biz_id, trade_no, app_id, seller_id,
  155. status, pay_time, notify_time, notify_type, trade_status,
  156. create_time, update_time, product_id, related_item_id, pay_url
  157. FROM pay_order
  158. </select>
  159. <select id="selectPayOrderCountByTime" resultType="org.dromara.business.domain.vo.PayOrderVo">
  160. SELECT
  161. ifnull(count(distinct trade_no),0) as payOrderCount,
  162. ifnull(sum(total_amount),0) as payOrderAmount
  163. FROM pay_order where status= 'success' and pay_time >= #{beginTime} and pay_time &lt; #{endTime}
  164. </select>
  165. <select id="selectPayOrderGraphByTime" resultType="org.dromara.business.domain.vo.PayOrderVo">
  166. SELECT
  167. DATE(pay_time) as dates,
  168. COUNT(DISTINCT trade_no) as payOrderCount,
  169. IFNULL(SUM(total_amount), 0) as payOrderAmount
  170. FROM pay_order
  171. WHERE status = 'success'
  172. AND pay_time >= #{beginTime}
  173. AND pay_time &lt; #{endTime}
  174. GROUP BY DATE(pay_time)
  175. ORDER BY dates
  176. </select>
  177. </mapper>