StudentPaymentOrderMapper.xml 18 KB

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