StudentPaymentOrderMapper.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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="remit_fee_" property="remitFee"/>
  20. <result column="course_remit_fee_" property="courseRemitFee"/>
  21. <result column="trans_no_" property="transNo"/>
  22. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  23. <result column="memo_" property="memo"/>
  24. <result column="create_time_" property="createTime"/>
  25. <result column="update_time_" property="updateTime"/>
  26. <result column="payment_channel_" property="paymentChannel"/>
  27. <result column="payment_business_channel_" property="paymentBusinessChannel"/>
  28. <result column="payment_account_no_" property="paymentAccountNo"/>
  29. <result column="mer_nos_" property="merNos"/>
  30. <result column="order_no_" property="orderNo"/>
  31. <result column="music_group_id_" property="musicGroupId"/>
  32. <result column="class_group_id_" property="classGroupId"/>
  33. <result column="pay_time_" property="payTime"/>
  34. <result column="version_" property="version"/>
  35. <result column="receive_status_" property="receiveStatus"/>
  36. </resultMap>
  37. <resultMap type="com.ym.mec.biz.dal.entity.StudentPaymentOrder" extends="StudentPaymentOrder"
  38. id="PaymentOrderAndStudentInfo">
  39. <result column="username_" property="user.username"/>
  40. <result column="phone_" property="user.phone"/>
  41. </resultMap>
  42. <resultMap type="com.ym.mec.biz.dal.entity.Goods" id="Goods">
  43. <result column="id_" property="id"/>
  44. <result column="goods_category_id_" property="goodsCategoryId"/>
  45. <result column="sn_" property="sn"/>
  46. <result column="name_" property="name"/>
  47. <result column="brand_" property="brand"/>
  48. <result column="specification_" property="specification"/>
  49. <result column="image_" property="image"/>
  50. <result column="stock_count_" property="stockCount"/>
  51. <result column="sell_count_" property="sellCount"/>
  52. <result column="market_price_" property="marketPrice"/>
  53. <result column="discount_price_" property="discountPrice"/>
  54. <result column="group_purchase_price_" property="groupPurchasePrice"/>
  55. <result column="brief_" property="brief"/>
  56. <result column="desc_" property="desc"/>
  57. <result column="is_new_" property="isNew" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  58. <result column="is_top_" property="isTop" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  59. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  60. <result column="memo_" property="memo"/>
  61. <result column="publish_time_" property="publishTime"/>
  62. <result column="create_time_" property="createTime"/>
  63. <result column="update_time_" property="updateTime"/>
  64. <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
  65. </resultMap>
  66. <!-- 根据主键查询一条记录 -->
  67. <select id="get" resultMap="StudentPaymentOrder">
  68. SELECT *
  69. FROM student_payment_order
  70. WHERE id_ = #{id}
  71. </select>
  72. <!-- 全查询 -->
  73. <select id="findAll" resultMap="StudentPaymentOrder">
  74. SELECT *
  75. FROM student_payment_order
  76. ORDER BY id_
  77. </select>
  78. <!-- 向数据库增加一条记录 -->
  79. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder" useGeneratedKeys="true"
  80. keyColumn="id" keyProperty="id">
  81. INSERT INTO student_payment_order
  82. (id_, group_type_, user_id_, organ_id_, routing_organ_id_, type_, expect_amount_, actual_amount_, com_amount_,
  83. per_amount_,
  84. balance_payment_amount_, remit_fee_, course_remit_fee_, trans_no_,
  85. status_, memo_, create_time_, update_time_, payment_channel_, payment_business_channel_,
  86. payment_account_no_, mer_nos_, order_no_, music_group_id_, class_group_id_, pay_time_)
  87. VALUES (#{id}, #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  88. #{userId}, #{organId}, #{routingOrganId},
  89. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  90. #{expectAmount}, #{actualAmount}, #{comAmount}, #{perAmount}, #{balancePaymentAmount},
  91. #{remitFee}, #{courseRemitFee}, #{transNo},
  92. #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, #{memo}, now(), now(),
  93. #{paymentChannel}, #{paymentBusinessChannel}, #{paymentAccountNo}, #{merNos}, #{orderNo},
  94. #{musicGroupId},
  95. #{classGroupId}, #{payTime})
  96. </insert>
  97. <!-- 根据主键查询一条记录 -->
  98. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
  99. UPDATE student_payment_order
  100. <set>
  101. <if test="receiveStatus != null and receiveStatus != ''">
  102. receive_status_ = #{receiveStatus},
  103. </if>
  104. <if test="status != null">
  105. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  106. </if>
  107. <if test="groupType != null">
  108. group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  109. </if>
  110. <if test="orderNo != null">
  111. order_no_ = #{orderNo},
  112. </if>
  113. <if test="classGroupId != null">
  114. class_group_id_ = #{classGroupId},
  115. </if>
  116. <if test="expectAmount != null">
  117. expect_amount_ = #{expectAmount},
  118. </if>
  119. <if test="memo != null">
  120. memo_ = #{memo},
  121. </if>
  122. <if test="paymentChannel != null">
  123. payment_channel_ = #{paymentChannel},
  124. </if>
  125. <if test="userId != null">
  126. user_id_ = #{userId},
  127. </if>
  128. <if test="paymentAccountNo != null">
  129. payment_account_no_ = #{paymentAccountNo},
  130. </if>
  131. <if test="merNos != null">
  132. mer_nos_ = #{merNos},
  133. </if>
  134. <if test="paymentBusinessChannel != null">
  135. payment_business_channel_ = #{paymentBusinessChannel},
  136. </if>
  137. <if test="transNo != null">
  138. trans_no_ = #{transNo},
  139. </if>
  140. <if test="actualAmount != null">
  141. actual_amount_ = #{actualAmount},
  142. </if>
  143. <if test="comAmount != null">
  144. com_amount_ = #{comAmount},
  145. </if>
  146. <if test="perAmount != null">
  147. per_amount_ = #{perAmount},
  148. </if>
  149. <if test="balancePaymentAmount != null">
  150. balance_payment_amount_ = #{balancePaymentAmount},
  151. </if>
  152. <if test="remitFee != null">
  153. remit_fee_ = #{remitFee},
  154. </if>
  155. <if test="courseRemitFee != null">
  156. course_remit_fee_ = #{courseRemitFee},
  157. </if>
  158. <if test="type != null">
  159. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  160. </if>
  161. <if test="musicGroupId != null">
  162. music_group_id_ = #{musicGroupId},
  163. </if>
  164. <if test="organId != null">
  165. organ_id_ = #{organId},
  166. </if>
  167. <if test="routingOrganId != null">
  168. routing_organ_id_ = #{routingOrganId},
  169. </if>
  170. <if test="payTime != null">
  171. pay_time_ = #{payTime},
  172. </if>
  173. <if test="version != null">
  174. version_ = version_+1,
  175. </if>
  176. update_time_ = NOW()
  177. </set>
  178. WHERE id_ = #{id} AND version_ = #{version}
  179. </update>
  180. <!-- 根据主键删除一条记录 -->
  181. <delete id="delete">
  182. DELETE
  183. FROM student_payment_order
  184. WHERE id_ = #{id}
  185. </delete>
  186. <!-- 分页查询 -->
  187. <select id="queryPage" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  188. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  189. left join sys_user u on spo.user_id_ = u.id_
  190. <include refid="queryPaymentOrder"/>
  191. ORDER BY spo.id_ DESC
  192. <include refid="global.limit"/>
  193. </select>
  194. <!-- 查询当前表的总记录数 -->
  195. <select id="queryCount" resultType="int" parameterType="map">
  196. SELECT COUNT(spo.id_) FROM student_payment_order spo
  197. left join sys_user u on spo.user_id_ = u.id_
  198. <include refid="queryPaymentOrder"/>
  199. </select>
  200. <sql id="queryPaymentOrder">
  201. <where>
  202. <if test="userIds != null">
  203. AND spo.user_id_ IN
  204. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  205. #{userId}
  206. </foreach>
  207. </if>
  208. <if test="organId != null">
  209. AND FIND_IN_SET(spo.organ_id_,#{organId})
  210. </if>
  211. <if test="orderStartDate != null">
  212. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &gt;= #{orderStartDate}
  213. </if>
  214. <if test="orderEndDate != null">
  215. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &lt;= #{orderEndDate}
  216. </if>
  217. <if test="paymentType != null">
  218. AND spo.type_ = #{paymentType}
  219. </if>
  220. <if test="remark != null">
  221. AND spo.memo_ LIKE CONCAT('%',#{remark},'%')
  222. </if>
  223. <if test="studentId != null">
  224. AND spo.user_id_ = #{studentId}
  225. </if>
  226. <if test="paymentStatus != null">
  227. AND spo.status_ = #{paymentStatus}
  228. </if>
  229. <if test="paymentChannel != null">
  230. AND spo.payment_channel_ NOT IN (#{paymentChannel})
  231. </if>
  232. <if test='orderType != null and orderType.toString()=="1".toString()'>
  233. AND spo.com_amount_ > 0
  234. </if>
  235. <if test='orderType != null and orderType.toString()=="2".toString()'>
  236. AND spo.per_amount_ > 0
  237. </if>
  238. <if test="routingOrganId != null">
  239. AND FIND_IN_SET(spo.routing_organ_id_,#{routingOrganId})
  240. </if>
  241. <if test="actualAmount != null">
  242. AND spo.actual_amount_ >= #{actualAmount}
  243. </if>
  244. <if test="balancePaymentAmount != null">
  245. AND spo.balance_payment_amount_ >= #{balancePaymentAmount}
  246. </if>
  247. <if test="lessActualAmount != null">
  248. <![CDATA[ AND spo.actual_amount_ <= #{lessActualAmount}]]>
  249. </if>
  250. <if test="lessBalancePaymentAmount != null">
  251. <![CDATA[AND spo.balance_payment_amount_ <= #{lessBalancePaymentAmount}]]>
  252. </if>
  253. <if test="orderNo != null">
  254. AND spo.order_no_ = #{orderNo}
  255. </if>
  256. <if test="merNos != null">
  257. AND FIND_IN_SET(#{merNos},spo.mer_nos_)
  258. </if>
  259. <if test="transNo != null">
  260. AND spo.trans_no_ = #{transNo}
  261. </if>
  262. <if test="chargeType != null">
  263. AND spo.group_type_='SPORADIC'
  264. AND sci.charge_type_ = #{chargeType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  265. </if>
  266. </where>
  267. </sql>
  268. <select id="queryApplyGoodsList" resultMap="Goods" parameterType="map">
  269. select g.*
  270. from goods g
  271. where g.id_ in (SELECT spod.goods_id_list_
  272. FROM student_payment_order spo
  273. left join
  274. student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  275. where spo.music_group_id_ =
  276. #{musicGroupId}
  277. and spo.type_ = 'APPLY'
  278. and spod.type_ =
  279. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  280. </select>
  281. <select id="queryByCondition" resultMap="StudentPaymentOrder" parameterType="map">
  282. SELECT spo.*
  283. FROM student_payment_order spo
  284. WHERE spo.user_id_ = #{userId}
  285. AND spo.music_group_id_ = #{musicGroupId}
  286. AND spo.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  287. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  288. and spo.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  289. </select>
  290. <select id="findByStudentVipGroup" resultMap="StudentPaymentOrder">
  291. SELECT
  292. spo.*
  293. FROM
  294. student_payment_order spo
  295. WHERE spo.user_id_=#{userId}
  296. AND spo.music_group_id_=#{vipGroupId}
  297. <if test="status!=null and status!=''">
  298. AND spo.status_=#{status}
  299. </if>
  300. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  301. </select>
  302. <select id="sumSurplusCourseFee" resultType="java.math.BigDecimal">
  303. SELECT SUM(cssp.expect_price_)
  304. FROM course_schedule_student_payment cssp
  305. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  306. WHERE cssp.user_id_ = #{userId}
  307. AND cssp.music_group_id_ = #{vipGroupId}
  308. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  309. </select>
  310. <select id="findNotFailedOrderByStudentVipGroup" resultMap="StudentPaymentOrder">
  311. SELECT spo.*
  312. FROM student_payment_order spo
  313. WHERE spo.user_id_ = #{userId}
  314. AND spo.music_group_id_ = #{vipGroupId}
  315. AND spo.status_ != 'FAILED'
  316. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  317. </select>
  318. <!-- 查询报名订单 -->
  319. <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
  320. SELECT *
  321. FROM student_payment_order
  322. WHERE music_group_id_ = #{musicGroupId}
  323. AND user_id_ = #{userId}
  324. AND type_ = 'APPLY'
  325. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  326. ORDER BY id_ DESC
  327. LIMIT 1
  328. </select>
  329. <!-- 根据订单号查询订单 -->
  330. <select id="findOrderByOrderNo" resultMap="StudentPaymentOrder">
  331. SELECT *
  332. FROM student_payment_order
  333. WHERE order_no_ = #{orderNo}
  334. </select>
  335. <select id="queryByDealStatus" resultMap="StudentPaymentOrder" parameterType="map">
  336. SELECT *
  337. FROM student_payment_order
  338. WHERE music_group_id_ = #{musicGroupId}
  339. AND type_ =
  340. #{type}
  341. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  342. </select>
  343. <!-- 查找支付成功和支付中订单 -->
  344. <select id="findPayOrderNum" resultType="int">
  345. <![CDATA[
  346. SELECT COUNT(*)
  347. FROM student_payment_order
  348. WHERE FIND_IN_SET(status_, 'SUCCESS,ING,WAIT_PAY')
  349. ]]>
  350. </select>
  351. <resultMap type="com.ym.mec.biz.dal.dto.UserGoodsDto" id="userGoodsDto">
  352. <result column="goods_id_" property="goodsId"/>
  353. <collection property="goodsName" ofType="string">
  354. <result column="goods_name_"/>
  355. </collection>
  356. </resultMap>
  357. <select id="findGoodsIds" resultMap="userGoodsDto">
  358. SELECT g.id_ goods_id_, g.name_ goods_name_
  359. FROM student_payment_order spo
  360. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  361. LEFT JOIN goods g ON FIND_IN_SET(g.id_, spod.goods_id_list_)
  362. WHERE spo.type_ = 'APPLY'
  363. AND spo.status_ = 'SUCCESS'
  364. AND spod.goods_id_list_ IS NOT NULL
  365. AND spo.music_group_id_ = #{musicGroupId}
  366. AND spo.user_id_ = #{userId}
  367. </select>
  368. <select id="findOrdersByStatus" resultMap="StudentPaymentOrder">
  369. SELECT *
  370. FROM student_payment_order
  371. WHERE status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  372. AND payment_channel_ = #{paymentChannel}
  373. LIMIT 100
  374. </select>
  375. <!-- 查询支付中超时订单 -->
  376. <select id="findOrdersOverTime" resultMap="StudentPaymentOrder">
  377. SELECT * FROM student_payment_order WHERE order_no_ IN
  378. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  379. #{orderNo}
  380. </foreach>
  381. AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  382. <![CDATA[ AND create_time_ <= ]]> #{beforeTime}
  383. </select>
  384. <select id="countStudentPaymentNum" resultType="int">
  385. select count(1)
  386. from student_payment_order
  387. where music_group_id_ = #{musicGroupId}
  388. AND status_ = 'SUCCESS'
  389. AND type_ = 'SMALL_CLASS_TO_BUY'
  390. </select>
  391. <select id="countSurplusCourseByMusicGroupAndUser" resultType="int">
  392. SELECT COUNT(*)
  393. FROM course_schedule_student_payment cssp
  394. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  395. WHERE cssp.user_id_ = #{userId}
  396. AND cssp.music_group_id_ = #{musicGroupId}
  397. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  398. </select>
  399. <select id="sumGroupIncomeFee" resultType="java.math.BigDecimal">
  400. SELECT SUM(expect_amount_)
  401. FROM student_payment_order
  402. WHERE group_type_ = #{groupType}
  403. AND music_group_id_ = #{musicGroupId}
  404. AND status_ = 'SUCCESS'
  405. </select>
  406. <select id="findStudentPaymentOrder" resultMap="StudentPaymentOrder">
  407. SELECT *
  408. FROM student_payment_order
  409. WHERE id_ IN (SELECT MAX(sp.id_)
  410. FROM (SELECT *
  411. FROM student_payment_order
  412. WHERE group_type_ = #{groupType}
  413. AND type_ = 'APPLY'
  414. AND music_group_id_ = #{musicGroupId}
  415. AND status_ = 'SUCCESS'
  416. ORDER BY id_ DESC) sp
  417. GROUP BY sp.user_id_)
  418. </select>
  419. <select id="findOrderByGroupType" resultType="int">
  420. SELECT COUNT(id_) FROM student_payment_order
  421. WHERE group_type_ = #{groupType}
  422. AND user_id_ = #{userId}
  423. AND music_group_id_ = #{sporadicId}
  424. <if test="status != null">
  425. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  426. </if>
  427. </select>
  428. <select id="queryExpectAmount" resultType="java.util.Map">
  429. SELECT spo.expect_amount_ 'value',spo.id_ 'key'
  430. FROM student_payment_order spo
  431. WHERE spo.id_ IN
  432. <foreach collection="paymentOrderNo" open="(" close=")" separator="," item="item">
  433. #{item}
  434. </foreach>
  435. </select>
  436. <select id="findFixOrder" resultMap="StudentPaymentOrder">
  437. SELECT *
  438. FROM student_payment_order
  439. where status_ = 'SUCCESS'
  440. AND type_ = 'APPLY'
  441. AND actual_amount_ > 0
  442. and mer_nos_ IS NULL
  443. LIMIT 100
  444. </select>
  445. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="orderAndDetail"
  446. extends="StudentPaymentOrder">
  447. <result column="organ_name" property="organName"/>
  448. <result column="username_" property="user.username"/>
  449. <result column="charge_type_" property="chargeType"/>
  450. <result column="routeMerNo" property="routeMerNo"/>
  451. <result column="routeAmount" property="routeAmount"/>
  452. <result column="routeBalance" property="routeBalance"/>
  453. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  454. <result column="detail_id_" property="id"/>
  455. <result column="detail_type_" property="type"/>
  456. <result column="detail_price_" property="price"/>
  457. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  458. </collection>
  459. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  460. <result column="goods_id" property="id"/>
  461. <result column="goods_name" property="name"/>
  462. </collection>
  463. </resultMap>
  464. <!-- 分页查询 -->
  465. <select id="ExportQueryPage" resultMap="orderAndDetail" parameterType="map">
  466. SELECT spo.*,u.username_,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  467. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  468. sci.charge_type_,g.id_ goods_id, g.name_ goods_name,o.name_ organ_name
  469. FROM student_payment_order spo
  470. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  471. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  472. <if test='orderType != null and orderType.toString()=="0".toString()'>
  473. LEFT JOIN organization o on spo.organ_id_ = o.id_
  474. </if>
  475. <if test='orderType != null and orderType.toString()=="1".toString()'>
  476. LEFT JOIN organization o on spo.organ_id_ = o.id_
  477. </if>
  478. <if test='orderType != null and orderType.toString()=="2".toString()'>
  479. LEFT JOIN organization o on spo.organ_id_ = o.id_
  480. </if>
  481. <if test='orderType != null and orderType.toString()=="3".toString()'>
  482. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  483. </if>
  484. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  485. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  486. <include refid="queryPaymentOrder"/>
  487. ORDER BY spo.id_ ASC
  488. </select>
  489. <resultMap id="SporadicChargeInfoDtoMap" type="com.ym.mec.biz.dal.dto.SporadicChargeInfoDto">
  490. <result property="organName" column="organ_name_"/>
  491. <result property="title" column="title_"/>
  492. <result property="type" column="type_"/>
  493. <result property="amount" column="amount_"/>
  494. <result property="createTime" column="create_time_"/>
  495. <result property="payTime" column="pay_time_"/>
  496. <result property="username" column="username_"/>
  497. <result property="payStatus" column="pay_status_"/>
  498. </resultMap>
  499. <select id="sporadicQueryPage" resultMap="SporadicChargeInfoDtoMap">
  500. SELECT o.name_ organ_name_,sci.title_,sci.charge_type_ type_,
  501. spo.actual_amount_ amount_,spo.create_time_,spo.pay_time_,su.username_,spo.status_ pay_status_
  502. FROM student_payment_order spo
  503. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  504. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  505. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  506. WHERE spo.type_ = 'SPORADIC'
  507. <include refid="sporadicQueryPageSql"/>
  508. ORDER BY spo.id_ DESC
  509. <include refid="global.limit"/>
  510. </select>
  511. <select id="countSporadicPage" resultType="java.lang.Integer">
  512. SELECT COUNT(spo.id_)
  513. FROM student_payment_order spo
  514. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  515. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  516. WHERE spo.type_ = 'SPORADIC'
  517. <include refid="sporadicQueryPageSql"/>
  518. </select>
  519. <sql id="sporadicQueryPageSql">
  520. <if test="organId != null">
  521. AND FIND_IN_SET(spo.organ_id_,#{organId})
  522. </if>
  523. <if test="search != null">
  524. AND (sci.title_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  525. </if>
  526. <if test="chargeType != null">
  527. AND sci.charge_type_ = #{chargeType}
  528. </if>
  529. <if test="payStatus != null">
  530. AND spo.status_ = #{payStatus}
  531. </if>
  532. </sql>
  533. <resultMap id="luckStatis" type="com.ym.mec.biz.dal.dto.OrderStatisDto">
  534. <result property="organName" column="organName"/>
  535. <result property="nums" column="nums"/>
  536. <result property="money" column="money"/>
  537. </resultMap>
  538. <select id="getLuckStatis" resultMap="luckStatis">
  539. SELECT o.name_ organName, SUM(spo.actual_amount_) money, COUNT(spo.id_) nums
  540. FROM student_payment_order spo
  541. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  542. WHERE spo.type_ = 'LUCK'
  543. AND spo.status_ = 'SUCCESS'
  544. GROUP BY spo.organ_id_
  545. ORDER BY nums DESC;
  546. </select>
  547. <select id="queryIncomeStatisticsWithCurrentMonth" resultType="map">
  548. select count(*) total,sum(actual_amount_) total_num_ from student_payment_order
  549. where actual_amount_ &gt; 0 and DATE_FORMAT(create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) AND
  550. status_ = 'SUCCESS' and organ_id_ not in (36,38)
  551. <if test="organId != null">
  552. and FIND_IN_SET(organ_id_,#{organId})
  553. </if>
  554. </select>
  555. <select id="countUserBuyVipGroupSuccessOrder" resultType="int">
  556. select count(*)
  557. from student_payment_order
  558. where user_id_ = #{userId}
  559. and music_group_id_ = #{vipGroupId}
  560. and group_type_ = 'VIP'
  561. and status_ = 'SUCCESS'
  562. </select>
  563. <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
  564. select *
  565. from student_payment_order
  566. where user_id_ = #{userId}
  567. and music_group_id_ = #{vipGroupId}
  568. and group_type_ = 'VIP'
  569. </select>
  570. <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
  571. select * from student_payment_order
  572. where user_id_=#{userId}
  573. and music_group_id_=#{groupId}
  574. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  575. <if test="status!=null">
  576. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  577. </if>
  578. </select>
  579. <select id="getOrderMoneyAmount" parameterType="map" resultMap="StudentPaymentOrder">
  580. SELECT SUM(spo.expect_amount_) expect_amount_,SUM(actual_amount_) actual_amount_,SUM(balance_payment_amount_)
  581. balance_payment_amount_ FROM student_payment_order spo
  582. <include refid="queryPaymentOrder"/>
  583. </select>
  584. <!-- 分页查询 -->
  585. <select id="queryPageOrder" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  586. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  587. left join sys_user u on spo.user_id_ = u.id_
  588. <include refid="queryPaymentOrder"/>
  589. ORDER BY spo.id_ DESC
  590. <include refid="global.limit"/>
  591. </select>
  592. <select id="findOrderByGroup" resultMap="StudentPaymentOrder">
  593. SELECT * FROM student_payment_order
  594. WHERE music_group_id_=#{groupId}
  595. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  596. <if test="status!=null">
  597. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  598. </if>
  599. </select>
  600. <select id="sumPerAccountAmount" resultType="java.math.BigDecimal"><![CDATA[
  601. SELECT SUM(per_amount_)
  602. FROM student_payment_order
  603. WHERE FIND_IN_SET(status_, 'SUCCESS,ING')
  604. AND create_time_ >= #{firstDate}
  605. AND create_time_ <= NOW()
  606. AND FIND_IN_SET(#{merNo}, mer_nos_)
  607. ]]>
  608. </select>
  609. <select id="getChargeAmount" parameterType="map" resultType="java.math.BigDecimal">
  610. SELECT SUM(actual_amount_) FROM student_payment_order spo
  611. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
  612. <include refid="queryPaymentOrder"/>
  613. </select>
  614. <select id="sumAccountAmount" resultType="java.math.BigDecimal">
  615. <![CDATA[
  616. SELECT SUM(actual_amount_)
  617. FROM student_payment_order
  618. WHERE status_ IN ('SUCCESS', 'ING')
  619. AND create_time_ >= #{firstDate}
  620. AND create_time_ <= NOW()
  621. AND mer_nos_ = #{merNo}
  622. ]]></select>
  623. <select id="countGroupOrderWithoutFailed" resultType="int">
  624. SELECT COUNT(*)
  625. FROM student_payment_order spo
  626. LEFT JOIN class_group_student_mapper cgsm
  627. ON spo.music_group_id_ = cgsm.music_group_id_ AND spo.user_id_ = cgsm.user_id_
  628. WHERE spo.music_group_id_ = #{groupId}
  629. AND spo.status_ != 'FAILED'
  630. AND cgsm.status_ != 'QUIT'
  631. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  632. AND cgsm.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  633. </select>
  634. <select id="countSporadicOrder" resultType="java.lang.Integer">
  635. SELECT COUNT(id_)
  636. FROM student_payment_order spo
  637. WHERE spo.group_type_ = 'SPORADIC'
  638. AND spo.music_group_id_ = #{sporadicId}
  639. </select>
  640. <!-- 查找支付成功和支付中订单 -->
  641. <select id="findOrganPayOrderNum" resultType="int">
  642. SELECT COUNT(*)
  643. FROM student_payment_order
  644. WHERE organ_id_ = #{organId}
  645. AND status_ IN ('SUCCESS', 'ING')
  646. </select>
  647. <!-- 获取每月用户的对应类型订单订单 -->
  648. <select id="getOrderByMonthAndType" resultType="com.ym.mec.biz.dal.dto.OrderByTypeExportDto">
  649. SELECT o.name_ organName, spo.user_id_ studentId,su.username_ studentName,spo.type_ orderType,
  650. spo.actual_amount_ actualAmount,spo.music_group_id_ musicGroupId,spo.group_type_ groupType,spo.create_time_
  651. createTime
  652. FROM student_payment_order spo
  653. LEFT JOIN sys_user su on spo.user_id_ = su.id_
  654. LEFT JOIN organization o ON o.id_ = spo.id_
  655. WHERE spo.status_ = 'SUCCESS'
  656. <if test="organIds != null">
  657. AND FIND_IN_SET (spo.organ_id_,#{organIds})
  658. </if>
  659. <if test="orderTypeList != null">
  660. AND spo.type_ IN
  661. <foreach collection="orderTypeList" item="orderType" open="(" close=")"
  662. separator=",">
  663. #{orderType}
  664. </foreach>
  665. </if>
  666. <if test="startTime != null">
  667. AND spo.create_time_ >= #{startTime}
  668. </if>
  669. <if test="endTime != null"><![CDATA[
  670. AND spo.create_time_ <= #{endTime}
  671. ]]></if>
  672. AND spo.actual_amount_ > 0
  673. </select>
  674. <select id="getUsers" resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  675. SELECT username_ name, id_ userId, phone_ phone
  676. FROM sys_user
  677. WHERE id_ = #{search}
  678. OR username_ LIKE CONCAT('%', #{search}, '%')
  679. OR phone_ LIKE CONCAT('%', #{search}, '%')
  680. </select>
  681. <select id="lockOrder" resultMap="StudentPaymentOrder">
  682. SELECT *
  683. FROM student_payment_order
  684. WHERE id_ = #{id} FOR
  685. UPDATE
  686. </select>
  687. </mapper>