StudentPaymentOrderMapper.xml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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="getUserGoods" resultMap="userGoodsDto">
  369. SELECT id_ goods_id_, name_ goods_name_ FROM goods WHERE FIND_IN_SET(id_,#{ids})
  370. </select>
  371. <select id="findOrdersByStatus" resultMap="StudentPaymentOrder">
  372. SELECT *
  373. FROM student_payment_order
  374. WHERE status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  375. AND payment_channel_ = #{paymentChannel}
  376. LIMIT 100
  377. </select>
  378. <!-- 查询支付中超时订单 -->
  379. <select id="findOrdersOverTime" resultMap="StudentPaymentOrder">
  380. SELECT * FROM student_payment_order WHERE order_no_ IN
  381. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  382. #{orderNo}
  383. </foreach>
  384. AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  385. <![CDATA[ AND create_time_ <= ]]> #{beforeTime}
  386. </select>
  387. <select id="countStudentPaymentNum" resultType="int">
  388. select count(1)
  389. from student_payment_order
  390. where music_group_id_ = #{musicGroupId}
  391. AND status_ = 'SUCCESS'
  392. AND type_ = 'SMALL_CLASS_TO_BUY'
  393. </select>
  394. <select id="countSurplusCourseByMusicGroupAndUser" resultType="int">
  395. SELECT COUNT(*)
  396. FROM course_schedule_student_payment cssp
  397. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  398. WHERE cssp.user_id_ = #{userId}
  399. AND cssp.music_group_id_ = #{musicGroupId}
  400. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  401. </select>
  402. <select id="sumGroupIncomeFee" resultType="java.math.BigDecimal">
  403. SELECT SUM(expect_amount_)
  404. FROM student_payment_order
  405. WHERE group_type_ = #{groupType}
  406. AND music_group_id_ = #{musicGroupId}
  407. AND status_ = 'SUCCESS'
  408. </select>
  409. <select id="findStudentPaymentOrder" resultMap="StudentPaymentOrder">
  410. SELECT *
  411. FROM student_payment_order
  412. WHERE id_ IN (SELECT MAX(sp.id_)
  413. FROM (SELECT *
  414. FROM student_payment_order
  415. WHERE group_type_ = #{groupType}
  416. AND type_ = 'APPLY'
  417. AND music_group_id_ = #{musicGroupId}
  418. AND status_ = 'SUCCESS'
  419. ORDER BY id_ DESC) sp
  420. GROUP BY sp.user_id_)
  421. </select>
  422. <select id="findOrderByGroupType" resultType="int">
  423. SELECT COUNT(id_) FROM student_payment_order
  424. WHERE group_type_ = #{groupType}
  425. AND user_id_ = #{userId}
  426. AND music_group_id_ = #{sporadicId}
  427. <if test="status != null">
  428. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  429. </if>
  430. </select>
  431. <select id="queryExpectAmount" resultType="java.util.Map">
  432. SELECT spo.expect_amount_ 'value',spo.id_ 'key'
  433. FROM student_payment_order spo
  434. WHERE spo.id_ IN
  435. <foreach collection="paymentOrderNo" open="(" close=")" separator="," item="item">
  436. #{item}
  437. </foreach>
  438. </select>
  439. <select id="findFixOrder" resultMap="StudentPaymentOrder">
  440. SELECT *
  441. FROM student_payment_order
  442. where status_ = 'SUCCESS'
  443. AND type_ = 'APPLY'
  444. AND actual_amount_ > 0
  445. and mer_nos_ IS NULL
  446. LIMIT 100
  447. </select>
  448. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="orderAndDetail"
  449. extends="StudentPaymentOrder">
  450. <result column="organ_name" property="organName"/>
  451. <result column="username_" property="user.username"/>
  452. <result column="charge_type_" property="chargeType"/>
  453. <result column="routeMerNo" property="routeMerNo"/>
  454. <result column="routeAmount" property="routeAmount"/>
  455. <result column="routeBalance" property="routeBalance"/>
  456. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  457. <result column="detail_id_" property="id"/>
  458. <result column="detail_type_" property="type"/>
  459. <result column="detail_price_" property="price"/>
  460. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  461. </collection>
  462. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  463. <result column="goods_id" property="id"/>
  464. <result column="goods_name" property="name"/>
  465. </collection>
  466. </resultMap>
  467. <!-- 分页查询 -->
  468. <select id="ExportQueryPage" resultMap="orderAndDetail" parameterType="map">
  469. SELECT spo.*,u.username_,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  470. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  471. sci.charge_type_,g.id_ goods_id, g.name_ goods_name,o.name_ organ_name
  472. FROM student_payment_order spo
  473. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  474. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  475. <if test='orderType != null and orderType.toString()=="0".toString()'>
  476. LEFT JOIN organization o on spo.organ_id_ = o.id_
  477. </if>
  478. <if test='orderType != null and orderType.toString()=="1".toString()'>
  479. LEFT JOIN organization o on spo.organ_id_ = o.id_
  480. </if>
  481. <if test='orderType != null and orderType.toString()=="2".toString()'>
  482. LEFT JOIN organization o on spo.organ_id_ = o.id_
  483. </if>
  484. <if test='orderType != null and orderType.toString()=="3".toString()'>
  485. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  486. </if>
  487. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  488. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  489. <include refid="queryPaymentOrder"/>
  490. ORDER BY spo.id_ ASC
  491. </select>
  492. <resultMap id="SporadicChargeInfoDtoMap" type="com.ym.mec.biz.dal.dto.SporadicChargeInfoDto">
  493. <result property="organName" column="organ_name_"/>
  494. <result property="title" column="title_"/>
  495. <result property="type" column="type_"/>
  496. <result property="amount" column="amount_"/>
  497. <result property="createTime" column="create_time_"/>
  498. <result property="payTime" column="pay_time_"/>
  499. <result property="username" column="username_"/>
  500. <result property="payStatus" column="pay_status_"/>
  501. </resultMap>
  502. <select id="sporadicQueryPage" resultMap="SporadicChargeInfoDtoMap">
  503. SELECT o.name_ organ_name_,sci.title_,sci.charge_type_ type_,
  504. spo.actual_amount_ amount_,spo.create_time_,spo.pay_time_,su.username_,spo.status_ pay_status_
  505. FROM student_payment_order spo
  506. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  507. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  508. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  509. WHERE spo.type_ = 'SPORADIC'
  510. <include refid="sporadicQueryPageSql"/>
  511. ORDER BY spo.id_ DESC
  512. <include refid="global.limit"/>
  513. </select>
  514. <select id="countSporadicPage" resultType="java.lang.Integer">
  515. SELECT COUNT(spo.id_)
  516. FROM student_payment_order spo
  517. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  518. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  519. WHERE spo.type_ = 'SPORADIC'
  520. <include refid="sporadicQueryPageSql"/>
  521. </select>
  522. <sql id="sporadicQueryPageSql">
  523. <if test="organId != null">
  524. AND FIND_IN_SET(spo.organ_id_,#{organId})
  525. </if>
  526. <if test="search != null">
  527. AND (sci.title_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  528. </if>
  529. <if test="chargeType != null">
  530. AND sci.charge_type_ = #{chargeType}
  531. </if>
  532. <if test="payStatus != null">
  533. AND spo.status_ = #{payStatus}
  534. </if>
  535. </sql>
  536. <resultMap id="luckStatis" type="com.ym.mec.biz.dal.dto.OrderStatisDto">
  537. <result property="organId" column="organId"/>
  538. <result property="organName" column="organName"/>
  539. <result property="estimatedNums" column="estimatedNums"/>
  540. <result property="nums" column="nums"/>
  541. <result property="times" column="times"/>
  542. <result property="scale" column="scale"/>
  543. <result property="money" column="money"/>
  544. </resultMap>
  545. <select id="getLuckStatis" resultMap="luckStatis">
  546. SELECT o.name_ organName, SUM(spo.actual_amount_) money, COUNT(spo.id_) nums
  547. FROM student_payment_order spo
  548. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  549. WHERE spo.type_ = 'LUCK'
  550. AND spo.status_ = 'SUCCESS'
  551. GROUP BY spo.organ_id_
  552. ORDER BY nums DESC;
  553. </select>
  554. <select id="queryIncomeStatisticsWithCurrentMonth" resultType="map">
  555. select count(*) total,sum(actual_amount_) total_num_ from student_payment_order
  556. where actual_amount_ &gt; 0 and DATE_FORMAT(create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) AND
  557. status_ = 'SUCCESS' and organ_id_ not in (36,38)
  558. <if test="organId != null">
  559. and FIND_IN_SET(organ_id_,#{organId})
  560. </if>
  561. </select>
  562. <select id="countUserBuyVipGroupSuccessOrder" resultType="int">
  563. select count(*)
  564. from student_payment_order
  565. where user_id_ = #{userId}
  566. and music_group_id_ = #{vipGroupId}
  567. and group_type_ = 'VIP'
  568. and status_ = 'SUCCESS'
  569. </select>
  570. <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
  571. select *
  572. from student_payment_order
  573. where user_id_ = #{userId}
  574. and music_group_id_ = #{vipGroupId}
  575. and group_type_ = 'VIP'
  576. </select>
  577. <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
  578. select * from student_payment_order
  579. where user_id_=#{userId}
  580. and music_group_id_=#{groupId}
  581. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  582. <if test="status!=null">
  583. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  584. </if>
  585. </select>
  586. <select id="getOrderMoneyAmount" parameterType="map" resultMap="StudentPaymentOrder">
  587. SELECT SUM(spo.expect_amount_) expect_amount_,SUM(actual_amount_) actual_amount_,SUM(balance_payment_amount_)
  588. balance_payment_amount_ FROM student_payment_order spo
  589. <include refid="queryPaymentOrder"/>
  590. </select>
  591. <!-- 分页查询 -->
  592. <select id="queryPageOrder" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  593. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  594. left join sys_user u on spo.user_id_ = u.id_
  595. <include refid="queryPaymentOrder"/>
  596. ORDER BY spo.id_ DESC
  597. <include refid="global.limit"/>
  598. </select>
  599. <select id="findOrderByGroup" resultMap="StudentPaymentOrder">
  600. SELECT * FROM student_payment_order
  601. WHERE music_group_id_=#{groupId}
  602. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  603. <if test="status!=null">
  604. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  605. </if>
  606. </select>
  607. <select id="sumPerAccountAmount" resultType="java.math.BigDecimal"><![CDATA[
  608. SELECT SUM(per_amount_)
  609. FROM student_payment_order
  610. WHERE FIND_IN_SET(status_, 'SUCCESS,ING')
  611. AND create_time_ >= #{firstDate}
  612. AND create_time_ <= NOW()
  613. AND FIND_IN_SET(#{merNo}, mer_nos_)
  614. ]]>
  615. </select>
  616. <select id="getChargeAmount" parameterType="map" resultType="java.math.BigDecimal">
  617. SELECT SUM(actual_amount_) FROM student_payment_order spo
  618. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
  619. <include refid="queryPaymentOrder"/>
  620. </select>
  621. <select id="sumAccountAmount" resultType="java.math.BigDecimal">
  622. <![CDATA[
  623. SELECT SUM(actual_amount_)
  624. FROM student_payment_order
  625. WHERE status_ IN ('SUCCESS', 'ING')
  626. AND create_time_ >= #{firstDate}
  627. AND create_time_ <= NOW()
  628. AND mer_nos_ = #{merNo}
  629. ]]></select>
  630. <select id="countGroupOrderWithoutFailed" resultType="int">
  631. SELECT COUNT(*)
  632. FROM student_payment_order spo
  633. LEFT JOIN class_group_student_mapper cgsm
  634. ON spo.music_group_id_ = cgsm.music_group_id_ AND spo.user_id_ = cgsm.user_id_
  635. WHERE spo.music_group_id_ = #{groupId}
  636. AND spo.status_ != 'FAILED'
  637. AND cgsm.status_ != 'QUIT'
  638. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  639. AND cgsm.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  640. </select>
  641. <select id="countSporadicOrder" resultType="java.lang.Integer">
  642. SELECT COUNT(id_)
  643. FROM student_payment_order spo
  644. WHERE spo.group_type_ = 'SPORADIC'
  645. AND spo.music_group_id_ = #{sporadicId}
  646. </select>
  647. <!-- 查找支付成功和支付中订单 -->
  648. <select id="findOrganPayOrderNum" resultType="int">
  649. SELECT COUNT(*)
  650. FROM student_payment_order
  651. WHERE organ_id_ = #{organId}
  652. AND status_ IN ('SUCCESS', 'ING')
  653. </select>
  654. <!-- 获取每月用户的对应类型订单订单 -->
  655. <select id="getOrderByMonthAndType" resultType="com.ym.mec.biz.dal.dto.OrderByTypeExportDto">
  656. SELECT o.name_ organName, spo.user_id_ studentId,su.username_ studentName,spo.type_ orderType,
  657. spo.actual_amount_ actualAmount,spo.music_group_id_ musicGroupId,spo.group_type_ groupType,spo.create_time_
  658. createTime
  659. FROM student_payment_order spo
  660. LEFT JOIN sys_user su on spo.user_id_ = su.id_
  661. LEFT JOIN organization o ON o.id_ = spo.id_
  662. WHERE spo.status_ = 'SUCCESS'
  663. <if test="organIds != null">
  664. AND FIND_IN_SET (spo.organ_id_,#{organIds})
  665. </if>
  666. <if test="orderTypeList != null">
  667. AND spo.type_ IN
  668. <foreach collection="orderTypeList" item="orderType" open="(" close=")"
  669. separator=",">
  670. #{orderType}
  671. </foreach>
  672. </if>
  673. <if test="startTime != null">
  674. AND spo.create_time_ >= #{startTime}
  675. </if>
  676. <if test="endTime != null"><![CDATA[
  677. AND spo.create_time_ <= #{endTime}
  678. ]]></if>
  679. AND spo.actual_amount_ > 0
  680. </select>
  681. <select id="getUsers" resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  682. SELECT username_ name, id_ userId, phone_ phone
  683. FROM sys_user
  684. WHERE id_ = #{search}
  685. OR username_ LIKE CONCAT('%', #{search}, '%')
  686. OR phone_ LIKE CONCAT('%', #{search}, '%')
  687. </select>
  688. <select id="lockOrder" resultMap="StudentPaymentOrder">
  689. SELECT *
  690. FROM student_payment_order
  691. WHERE id_ = #{id} FOR
  692. UPDATE
  693. </select>
  694. <select id="doubleEleven2020Statis" resultMap="luckStatis">
  695. SELECT o.id_ organId, o.name_ organName, SUM(spo.actual_amount_) money, COUNT(DISTINCT spo.user_id_) nums,
  696. SUM(IF(spo.class_group_id_ is null ,1,spo.class_group_id_)) times FROM student_payment_order spo
  697. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  698. WHERE spo.type_ = 'DOUBLE_ELEVEN2020'
  699. AND spo.status_ = 'SUCCESS'
  700. AND spo.organ_id_ IN
  701. <foreach collection="organs" item="organ" open="(" close=")" separator=",">
  702. #{organ.id}
  703. </foreach>
  704. GROUP BY spo.organ_id_
  705. </select>
  706. <select id="getUserOrderNumByType" resultType="int">
  707. SELECT COUNT(*)
  708. FROM student_payment_order
  709. WHERE user_id_ = #{userId}
  710. AND status_ = 'SUCCESS'
  711. AND type_ = #{orderType}
  712. </select>
  713. <select id="getUserOrderByType" resultMap="StudentPaymentOrder">
  714. SELECT * FROM student_payment_order WHERE user_id_=#{userId} AND type_=#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  715. </select>
  716. </mapper>