StudentPaymentOrderMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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="com_amount_" property="comAmount"/>
  16. <result column="per_amount_" property="perAmount"/>
  17. <result column="balance_payment_amount_" property="balancePaymentAmount"/>
  18. <result column="trans_no_" property="transNo"/>
  19. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  20. <result column="memo_" property="memo"/>
  21. <result column="create_time_" property="createTime"/>
  22. <result column="update_time_" property="updateTime"/>
  23. <result column="payment_channel_" property="paymentChannel"/>
  24. <result column="payment_business_channel_" property="paymentBusinessChannel"/>
  25. <result column="payment_account_no_" property="paymentAccountNo"/>
  26. <result column="mer_nos_" property="merNos"/>
  27. <result column="order_no_" property="orderNo"/>
  28. <result column="music_group_id_" property="musicGroupId"/>
  29. <result column="class_group_id_" property="classGroupId"/>
  30. <result column="pay_time_" property="payTime"/>
  31. <result column="version_" property="version"/>
  32. </resultMap>
  33. <resultMap type="com.ym.mec.biz.dal.entity.StudentPaymentOrder" extends="StudentPaymentOrder"
  34. id="PaymentOrderAndStudentInfo">
  35. <result column="username_" property="user.username"/>
  36. </resultMap>
  37. <resultMap type="com.ym.mec.biz.dal.entity.Goods" id="Goods">
  38. <result column="id_" property="id"/>
  39. <result column="goods_category_id_" property="goodsCategoryId"/>
  40. <result column="sn_" property="sn"/>
  41. <result column="name_" property="name"/>
  42. <result column="brand_" property="brand"/>
  43. <result column="specification_" property="specification"/>
  44. <result column="image_" property="image"/>
  45. <result column="stock_count_" property="stockCount"/>
  46. <result column="sell_count_" property="sellCount"/>
  47. <result column="market_price_" property="marketPrice"/>
  48. <result column="discount_price_" property="discountPrice"/>
  49. <result column="group_purchase_price_" property="groupPurchasePrice"/>
  50. <result column="brief_" property="brief"/>
  51. <result column="desc_" property="desc"/>
  52. <result column="is_new_" property="isNew" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  53. <result column="is_top_" property="isTop" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  54. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  55. <result column="memo_" property="memo"/>
  56. <result column="publish_time_" property="publishTime"/>
  57. <result column="create_time_" property="createTime"/>
  58. <result column="update_time_" property="updateTime"/>
  59. <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
  60. </resultMap>
  61. <!-- 根据主键查询一条记录 -->
  62. <select id="get" resultMap="StudentPaymentOrder">
  63. SELECT * FROM student_payment_order WHERE id_ = #{id}
  64. </select>
  65. <!-- 全查询 -->
  66. <select id="findAll" resultMap="StudentPaymentOrder">
  67. SELECT *
  68. FROM student_payment_order
  69. ORDER BY id_
  70. </select>
  71. <!-- 向数据库增加一条记录 -->
  72. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder" useGeneratedKeys="true"
  73. keyColumn="id" keyProperty="id">
  74. INSERT INTO student_payment_order
  75. (id_,group_type_,user_id_,type_,expect_amount_,actual_amount_,com_amount_,per_amount_,balance_payment_amount_,trans_no_,
  76. status_,memo_,create_time_,update_time_,payment_channel_,payment_business_channel_,
  77. payment_account_no_,order_no_,music_group_id_,class_group_id_)
  78. VALUES(#{id},#{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  79. #{userId},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  80. #{expectAmount},#{actualAmount},#{comAmount},#{perAmount},#{balancePaymentAmount},#{transNo},
  81. #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{memo},now(),now(),
  82. #{paymentChannel},#{paymentBusinessChannel},#{paymentAccountNo},#{orderNo},#{musicGroupId},#{classGroupId})
  83. </insert>
  84. <!-- 根据主键查询一条记录 -->
  85. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
  86. UPDATE student_payment_order
  87. <set>
  88. <if test="status != null">
  89. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  90. </if>
  91. <if test="groupType != null">
  92. group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  93. </if>
  94. <if test="orderNo != null">
  95. order_no_ = #{orderNo},
  96. </if>
  97. <if test="classGroupId != null">
  98. class_group_id_ = #{classGroupId},
  99. </if>
  100. <if test="expectAmount != null">
  101. expect_amount_ = #{expectAmount},
  102. </if>
  103. <if test="memo != null">
  104. memo_ = #{memo},
  105. </if>
  106. <if test="paymentChannel != null">
  107. payment_channel_ = #{paymentChannel},
  108. </if>
  109. <if test="userId != null">
  110. user_id_ = #{userId},
  111. </if>
  112. <if test="paymentAccountNo != null">
  113. payment_account_no_ = #{paymentAccountNo},
  114. </if>
  115. <if test="merNos != null">
  116. mer_nos_ = #{merNos},
  117. </if>
  118. <if test="updateTime != null">
  119. update_time_ = NOW(),
  120. </if>
  121. <if test="paymentBusinessChannel != null">
  122. payment_business_channel_ = #{paymentBusinessChannel},
  123. </if>
  124. <if test="transNo != null">
  125. trans_no_ = #{transNo},
  126. </if>
  127. <if test="actualAmount != null">
  128. actual_amount_ = #{actualAmount},
  129. </if>
  130. <if test="comAmount != null">
  131. com_amount_ = #{comAmount},
  132. </if>
  133. <if test="perAmount != null">
  134. per_amount_ = #{perAmount},
  135. </if>
  136. <if test="balancePaymentAmount != null">
  137. balance_payment_amount_ = #{balancePaymentAmount},
  138. </if>
  139. <if test="type != null">
  140. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  141. </if>
  142. <if test="musicGroupId != null">
  143. music_group_id_ = #{musicGroupId},
  144. </if>
  145. <if test="payTime != null">
  146. pay_time_ = #{payTime},
  147. </if>
  148. <if test="version != null">
  149. version_ = version_+1,
  150. </if>
  151. </set>
  152. WHERE id_ = #{id} AND version_ = #{version}
  153. </update>
  154. <!-- 根据主键删除一条记录 -->
  155. <delete id="delete">
  156. DELETE FROM student_payment_order WHERE id_ = #{id}
  157. </delete>
  158. <!-- 分页查询 -->
  159. <select id="queryPage" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  160. SELECT spo.*,u.username_ FROM student_payment_order spo
  161. left join sys_user u on spo.user_id_ = u.id_
  162. <include refid="queryPaymentOrder"/>
  163. ORDER BY spo.id_ DESC
  164. <include refid="global.limit"/>
  165. </select>
  166. <!-- 查询当前表的总记录数 -->
  167. <select id="queryCount" resultType="int" parameterType="map">
  168. SELECT COUNT(spo.id_) FROM student_payment_order spo
  169. left join sys_user u on spo.user_id_ = u.id_
  170. <include refid="queryPaymentOrder"/>
  171. </select>
  172. <sql id="queryPaymentOrder">
  173. <where>
  174. <if test="organId != null">
  175. AND FIND_IN_SET(u.organ_id_,#{organId})
  176. </if>
  177. <if test="orderStartDate != null">
  178. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &gt;= #{orderStartDate}
  179. </if>
  180. <if test="orderEndDate != null">
  181. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &lt;= #{orderEndDate}
  182. </if>
  183. <if test="paymentType != null">
  184. AND spo.type_ = #{paymentType}
  185. </if>
  186. <if test="remark != null">
  187. AND spo.memo_ LIKE CONCAT('%',#{remark},'%')
  188. </if>
  189. <if test="studentId != null">
  190. AND spo.user_id_ = #{studentId}
  191. </if>
  192. <if test="paymentStatus != null">
  193. AND spo.status_ = #{paymentStatus}
  194. </if>
  195. <if test="paymentChannel != null">
  196. AND spo.payment_channel_ NOT IN (#{paymentChannel})
  197. </if>
  198. <if test='orderType != null and orderType.toString()=="1".toString()'>
  199. AND spo.com_amount_ > 0
  200. </if>
  201. <if test='orderType != null and orderType.toString()=="2".toString()'>
  202. AND spo.per_amount_ > 0
  203. </if>
  204. </where>
  205. </sql>
  206. <select id="queryApplyGoodsList" resultMap="Goods" parameterType="map">
  207. select g.* from goods g where g.id_ in (SELECT spod.goods_id_list_ FROM student_payment_order spo left join
  208. student_payment_order_detail spod on spo.id_ = spod.payment_order_id_ where spo.music_group_id_ =
  209. #{musicGroupId} and spo.type_ = 'APPLY' and spod.type_ =
  210. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  211. </select>
  212. <select id="findByStudentVipGroup" resultMap="StudentPaymentOrder">
  213. SELECT
  214. spo.*
  215. FROM
  216. student_payment_order spo
  217. WHERE spo.user_id_=#{userId}
  218. AND spo.music_group_id_=#{vipGroupId}
  219. <if test="status!=null and status!=''">
  220. AND spo.status_=#{status}
  221. </if>
  222. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  223. </select>
  224. <select id="sumSurplusCourseFee" resultType="java.math.BigDecimal">
  225. SELECT
  226. SUM(cssp.expect_price_)
  227. FROM
  228. course_schedule_student_payment cssp
  229. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
  230. WHERE
  231. cssp.user_id_ = #{userId}
  232. AND cssp.music_group_id_ = #{vipGroupId}
  233. AND CONCAT(cs.class_date_ ,' ',cs.start_class_time_) &gt; NOW()
  234. </select>
  235. <select id="findNotFailedOrderByStudentVipGroup" resultMap="StudentPaymentOrder">
  236. SELECT
  237. spo.*
  238. FROM
  239. student_payment_order spo
  240. WHERE spo.user_id_=#{userId}
  241. AND spo.music_group_id_=#{vipGroupId}
  242. AND spo.status_!='FAILED'
  243. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  244. </select>
  245. <!-- 查询报名订单 -->
  246. <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
  247. SELECT * FROM student_payment_order WHERE music_group_id_= #{musicGroupId} AND user_id_=#{userId} AND type_ =
  248. 'APPLY' AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  249. ORDER BY id_ DESC LIMIT 1
  250. </select>
  251. <!-- 根据订单号查询订单 -->
  252. <select id="findOrderByOrderNo" resultMap="StudentPaymentOrder">
  253. SELECT * FROM student_payment_order WHERE order_no_ = #{orderNo}
  254. </select>
  255. <select id="queryByDealStatus" resultMap="StudentPaymentOrder" parameterType="map">
  256. SELECT * FROM student_payment_order WHERE music_group_id_= #{musicGroupId} AND type_ =
  257. #{type} AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  258. </select>
  259. <!-- 查找支付成功和支付中订单 -->
  260. <select id="findPayOrderNum" resultType="int">
  261. <![CDATA[
  262. SELECT COUNT(*)
  263. FROM student_payment_order
  264. WHERE FIND_IN_SET(status_,'SUCCESS,ING,WAIT_PAY')
  265. ]]>
  266. </select>
  267. <resultMap type="com.ym.mec.biz.dal.dto.UserGoodsDto" id="userGoodsDto">
  268. <result column="goods_id_" property="goodsId"/>
  269. <collection property="goodsName" ofType="string">
  270. <result column="goods_name_"/>
  271. </collection>
  272. </resultMap>
  273. <select id="findGoodsIds" resultMap="userGoodsDto">
  274. SELECT g.id_ goods_id_,g.name_ goods_name_ FROM student_payment_order spo
  275. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  276. LEFT JOIN goods g ON FIND_IN_SET(g.id_,spod.goods_id_list_)
  277. WHERE spo.type_ = 'APPLY' AND spo.status_ = 'SUCCESS' AND spod.goods_id_list_ IS NOT NULL
  278. AND spo.music_group_id_ = #{musicGroupId} AND spo.user_id_ = #{userId}
  279. </select>
  280. <select id="findOrdersByStatus" resultMap="StudentPaymentOrder">
  281. SELECT * FROM student_payment_order
  282. WHERE status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} AND payment_channel_ =
  283. #{paymentChannel} LIMIT 100
  284. </select>
  285. <!-- 查询支付中超时订单 -->
  286. <select id="findOrdersOverTime" resultMap="StudentPaymentOrder">
  287. SELECT * FROM student_payment_order WHERE order_no_ IN
  288. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  289. #{orderNo}
  290. </foreach>
  291. AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  292. <![CDATA[ AND create_time_ <= ]]> #{beforeTime}
  293. </select>
  294. <select id="countStudentPaymentNum" resultType="int">
  295. select count(1) from student_payment_order
  296. where music_group_id_=#{musicGroupId}
  297. AND status_ = 'SUCCESS' AND type_='SMALL_CLASS_TO_BUY'
  298. </select>
  299. <select id="countSurplusCourseByMusicGroupAndUser" resultType="int">
  300. SELECT
  301. COUNT(*)
  302. FROM
  303. course_schedule_student_payment cssp
  304. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_=cs.id_
  305. WHERE
  306. cssp.user_id_ = #{userId}
  307. AND cssp.music_group_id_ = #{musicGroupId}
  308. AND CONCAT(cs.class_date_ ,' ',cs.start_class_time_) &gt; NOW()
  309. </select>
  310. <select id="sumGroupIncomeFee" resultType="java.math.BigDecimal">
  311. SELECT
  312. SUM(expect_amount_)
  313. FROM
  314. student_payment_order
  315. WHERE
  316. group_type_ = #{groupType}
  317. AND music_group_id_ = #{musicGroupId}
  318. </select>
  319. <select id="findStudentPaymentOrder" resultMap="StudentPaymentOrder">
  320. SELECT * FROM student_payment_order WHERE id_ IN (SELECT MAX(sp.id_) FROM (SELECT * FROM student_payment_order
  321. WHERE group_type_ = #{groupType} AND type_ = 'APPLY' AND music_group_id_ = #{musicGroupId} AND status_ = 'SUCCESS'
  322. ORDER BY id_ DESC) sp GROUP BY sp.user_id_)
  323. </select>
  324. <select id="findOrderByGroupType" resultType="int">
  325. SELECT COUNT(id_) FROM student_payment_order
  326. WHERE group_type_ = #{groupType}
  327. AND user_id_ = #{userId}
  328. AND music_group_id_ = #{sporadicId}
  329. <if test="status != null">
  330. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  331. </if>
  332. </select>
  333. <select id="queryActualAmount" resultType="java.util.Map">
  334. SELECT spo.actual_amount_ 'value',spo.id_ 'key'
  335. FROM student_payment_order spo
  336. WHERE spo.id_ IN
  337. <foreach collection="paymentOrderNo" open="(" close=")" separator="," item="item">
  338. #{item}
  339. </foreach>
  340. </select>
  341. <select id="findFixOrder" resultMap="StudentPaymentOrder">
  342. SELECT * FROM student_payment_order
  343. WHERE status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} AND payment_channel_ =
  344. #{paymentChannel} AND com_amount_ IS NULL LIMIT 100
  345. </select>
  346. </mapper>