StudentPaymentOrderMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.StudentPaymentOrderDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.StudentPaymentOrder" id="StudentPaymentOrder">
  9. <result column="id_" property="id"/>
  10. <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  11. <result column="user_id_" property="userId"/>
  12. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  13. <result column="expect_amount_" property="expectAmount"/>
  14. <result column="actual_amount_" property="actualAmount"/>
  15. <result column="balance_payment_amount_" property="balancePaymentAmount"/>
  16. <result column="trans_no_" property="transNo"/>
  17. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  18. <result column="memo_" property="memo"/>
  19. <result column="create_time_" property="createTime"/>
  20. <result column="update_time_" property="updateTime"/>
  21. <result column="payment_channel_" property="paymentChannel"/>
  22. <result column="payment_business_channel_" property="paymentBusinessChannel"/>
  23. <result column="payment_account_no_" property="paymentAccountNo"/>
  24. <result column="order_no_" property="orderNo"/>
  25. <result column="music_group_id_" property="musicGroupId"/>
  26. <result column="class_group_id_" property="classGroupId"/>
  27. <result column="pay_time_" property="payTime"/>
  28. <result column="version_" property="version"/>
  29. </resultMap>
  30. <resultMap type="com.ym.mec.biz.dal.entity.StudentPaymentOrder" extends="StudentPaymentOrder"
  31. id="PaymentOrderAndStudentInfo">
  32. <result column="username_" property="user.username"/>
  33. </resultMap>
  34. <resultMap type="com.ym.mec.biz.dal.entity.Goods" id="Goods">
  35. <result column="id_" property="id"/>
  36. <result column="goods_category_id_" property="goodsCategoryId"/>
  37. <result column="sn_" property="sn"/>
  38. <result column="name_" property="name"/>
  39. <result column="brand_" property="brand"/>
  40. <result column="specification_" property="specification"/>
  41. <result column="image_" property="image"/>
  42. <result column="stock_count_" property="stockCount"/>
  43. <result column="sell_count_" property="sellCount"/>
  44. <result column="market_price_" property="marketPrice"/>
  45. <result column="discount_price_" property="discountPrice"/>
  46. <result column="group_purchase_price_" property="groupPurchasePrice"/>
  47. <result column="brief_" property="brief"/>
  48. <result column="desc_" property="desc"/>
  49. <result column="is_new_" property="isNew" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  50. <result column="is_top_" property="isTop" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  51. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  52. <result column="memo_" property="memo"/>
  53. <result column="publish_time_" property="publishTime"/>
  54. <result column="create_time_" property="createTime"/>
  55. <result column="update_time_" property="updateTime"/>
  56. <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
  57. </resultMap>
  58. <!-- 根据主键查询一条记录 -->
  59. <select id="get" resultMap="StudentPaymentOrder">
  60. SELECT * FROM student_payment_order WHERE id_ = #{id}
  61. </select>
  62. <!-- 全查询 -->
  63. <select id="findAll" resultMap="StudentPaymentOrder">
  64. SELECT *
  65. FROM student_payment_order
  66. ORDER BY id_
  67. </select>
  68. <!-- 向数据库增加一条记录 -->
  69. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder" useGeneratedKeys="true"
  70. keyColumn="id" keyProperty="id">
  71. INSERT INTO student_payment_order
  72. (id_,group_type_,user_id_,type_,expect_amount_,actual_amount_,balance_payment_amount_,trans_no_,
  73. status_,memo_,create_time_,update_time_,payment_channel_,payment_business_channel_,
  74. payment_account_no_,order_no_,music_group_id_,class_group_id_)
  75. VALUES(#{id},#{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  76. #{userId},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  77. #{expectAmount},#{actualAmount},#{balancePaymentAmount},#{transNo},
  78. #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{memo},now(),now(),
  79. #{paymentChannel},#{paymentBusinessChannel},#{paymentAccountNo},#{orderNo},#{musicGroupId},#{classGroupId})
  80. </insert>
  81. <!-- 根据主键查询一条记录 -->
  82. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
  83. UPDATE student_payment_order
  84. <set>
  85. <if test="status != null">
  86. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  87. </if>
  88. <if test="groupType != null">
  89. group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  90. </if>
  91. <if test="orderNo != null">
  92. order_no_ = #{orderNo},
  93. </if>
  94. <if test="classGroupId != null">
  95. class_group_id_ = #{classGroupId},
  96. </if>
  97. <if test="expectAmount != null">
  98. expect_amount_ = #{expectAmount},
  99. </if>
  100. <if test="memo != null">
  101. memo_ = #{memo},
  102. </if>
  103. <if test="paymentChannel != null">
  104. payment_channel_ = #{paymentChannel},
  105. </if>
  106. <if test="userId != null">
  107. user_id_ = #{userId},
  108. </if>
  109. <if test="paymentAccountNo != null">
  110. payment_account_no_ = #{paymentAccountNo},
  111. </if>
  112. <if test="updateTime != null">
  113. update_time_ = NOW(),
  114. </if>
  115. <if test="paymentBusinessChannel != null">
  116. payment_business_channel_ = #{paymentBusinessChannel},
  117. </if>
  118. <if test="transNo != null">
  119. trans_no_ = #{transNo},
  120. </if>
  121. <if test="actualAmount != null">
  122. actual_amount_ = #{actualAmount},
  123. </if>
  124. <if test="balancePaymentAmount != null">
  125. balance_payment_amount_ = #{balancePaymentAmount},
  126. </if>
  127. <if test="type != null">
  128. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  129. </if>
  130. <if test="musicGroupId != null">
  131. music_group_id_ = #{musicGroupId},
  132. </if>
  133. <if test="payTime != null">
  134. pay_time_ = #{payTime},
  135. </if>
  136. <if test="version != null">
  137. version_ = version_+1,
  138. </if>
  139. </set>
  140. WHERE id_ = #{id} AND version_ = #{version}
  141. </update>
  142. <!-- 根据主键删除一条记录 -->
  143. <delete id="delete">
  144. DELETE FROM student_payment_order WHERE id_ = #{id}
  145. </delete>
  146. <!-- 分页查询 -->
  147. <select id="queryPage" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  148. SELECT spo.*,u.username_ FROM student_payment_order spo
  149. left join sys_user u on spo.user_id_ = u.id_
  150. <include refid="queryPaymentOrder"/>
  151. ORDER BY spo.id_
  152. <include refid="global.limit"/>
  153. </select>
  154. <!-- 查询当前表的总记录数 -->
  155. <select id="queryCount" resultType="int" parameterType="map">
  156. SELECT COUNT(spo.id_) FROM student_payment_order spo
  157. left join sys_user u on spo.user_id_ = u.id_
  158. <include refid="queryPaymentOrder"/>
  159. </select>
  160. <sql id="queryPaymentOrder">
  161. <where>
  162. <if test="organId != null">
  163. AND FIND_IN_SET(u.organ_id_,#{organId})
  164. </if>
  165. <if test="orderStartDate != null">
  166. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &gt;= #{orderStartDate}
  167. </if>
  168. <if test="orderEndDate != null">
  169. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &lt;= #{orderEndDate}
  170. </if>
  171. <if test="paymentType != null">
  172. AND spo.type_ = #{paymentType}
  173. </if>
  174. <if test="remark != null">
  175. AND spo.memo_ LIKE CONCAT('%',#{remark},'%')
  176. </if>
  177. <if test="studentId != null">
  178. AND spo.user_id_ = #{studentId}
  179. </if>
  180. <if test="paymentStatus != null">
  181. AND spo.status_ = #{paymentStatus}
  182. </if>
  183. <if test="paymentChannel != null">
  184. AND spo.payment_channel_ NOT IN (#{paymentChannel})
  185. </if>
  186. </where>
  187. </sql>
  188. <select id="queryApplyGoodsList" resultMap="Goods" parameterType="map">
  189. select g.* from goods g where g.id_ in (SELECT spod.goods_id_list_ FROM student_payment_order spo left join
  190. student_payment_order_detail spod on spo.id_ = spod.payment_order_id_ where spo.music_group_id_ =
  191. #{musicGroupId} and spo.type_ = 'APPLY' and spod.type_ =
  192. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  193. </select>
  194. <select id="findByStudentVipGroup" resultMap="StudentPaymentOrder">
  195. SELECT
  196. spo.*
  197. FROM
  198. student_payment_order spo
  199. WHERE spo.user_id_=#{userId}
  200. AND spo.music_group_id_=#{vipGroupId}
  201. <if test="status!=null and status!=''">
  202. AND spo.status_=#{status}
  203. </if>
  204. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  205. </select>
  206. <select id="findNotFailedOrderByStudentVipGroup" resultMap="StudentPaymentOrder">
  207. SELECT
  208. spo.*
  209. FROM
  210. student_payment_order spo
  211. WHERE spo.user_id_=#{userId}
  212. AND spo.music_group_id_=#{vipGroupId}
  213. AND spo.status_!='FAILED'
  214. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  215. </select>
  216. <!-- 查询报名订单 -->
  217. <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
  218. SELECT * FROM student_payment_order WHERE music_group_id_= #{musicGroupId} AND user_id_=#{userId} AND type_ =
  219. 'APPLY' AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  220. </select>
  221. <!-- 根据订单号查询订单 -->
  222. <select id="findOrderByOrderNo" resultMap="StudentPaymentOrder">
  223. SELECT * FROM student_payment_order WHERE order_no_ = #{orderNo}
  224. </select>
  225. <select id="queryByDealStatus" resultMap="StudentPaymentOrder" parameterType="map">
  226. SELECT * FROM student_payment_order WHERE music_group_id_= #{musicGroupId} AND type_ =
  227. #{type} AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  228. </select>
  229. <!-- 查找支付成功和支付中订单 -->
  230. <select id="findPayOrderNum" resultType="int">
  231. <![CDATA[
  232. SELECT COUNT(*)
  233. FROM student_payment_order
  234. WHERE status_ <= 2
  235. ]]>
  236. </select>
  237. <resultMap type="com.ym.mec.biz.dal.dto.UserGoodsDto" id="userGoodsDto">
  238. <result column="goods_id_" property="goodsId"/>
  239. <collection property="goodsName" ofType="string">
  240. <result column="goods_name_"/>
  241. </collection>
  242. </resultMap>
  243. <select id="findGoodsIds" resultMap="userGoodsDto">
  244. SELECT g.id_ goods_id_,g.name_ goods_name_ FROM student_payment_order spo
  245. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  246. LEFT JOIN goods g ON FIND_IN_SET(g.id_,spod.goods_id_list_)
  247. WHERE spo.type_ = 'APPLY' AND spo.status_ = 'SUCCESS' AND spod.goods_id_list_ IS NOT NULL
  248. AND spo.music_group_id_ = #{musicGroupId} AND spo.user_id_ = #{userId}
  249. </select>
  250. <select id="findOrdersByStatus" resultMap="StudentPaymentOrder">
  251. SELECT * FROM student_payment_order
  252. WHERE status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} AND payment_channel_ =
  253. #{paymentChannel}
  254. </select>
  255. <!-- 查询支付中超时订单 -->
  256. <select id="findOrdersOverTime" resultMap="StudentPaymentOrder">
  257. SELECT * FROM student_payment_order WHERE order_no_ IN
  258. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  259. #{orderNo}
  260. </foreach>
  261. AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  262. <![CDATA[ AND create_time_ <= ]]> #{beforeTime}
  263. </select>
  264. <select id="countStudentPaymentNum" resultType="int">
  265. select count(1) from student_payment_order where music_group_id_=#{musicGroupId} AND status_ = 'SUCCESS' AND type_='SMALL_CLASS_TO_BUY'
  266. </select>
  267. </mapper>