UserAccountMapper.xml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. <mapper namespace="com.yonge.cooleshow.biz.dal.dao.UserAccountDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.UserAccount">
  5. <result column="user_id_" property="userId"/>
  6. <result column="amount_total_" property="amountTotal"/>
  7. <result column="amount_usable_" property="amountUsable"/>
  8. <result column="amount_frozen_" property="amountFrozen"/>
  9. <result column="status_" property="status"/>
  10. <result column="create_time_" property="createTime"/>
  11. <result column="update_time_" property="updateTime"/>
  12. </resultMap>
  13. <!-- 表字段 -->
  14. <sql id="baseColumns">
  15. t.user_id_ as userId
  16. , t.amount_total_ as amountTotal
  17. , t.amount_usable_ as amountUsable
  18. , t.amount_frozen_ as amountFrozen
  19. , t.status_ as status
  20. , t.create_time_ as createTime
  21. , t.update_time_ as updateTime
  22. </sql>
  23. <update id="frozenChangeAccount">
  24. update user_cash_account
  25. <choose>
  26. <when test="null != inOrOut and inOrOut == 'IN'">
  27. set amount_total_ = (amount_total_ + #{transAmount}),amount_frozen_ = (amount_frozen_ + #{transAmount}),
  28. </when>
  29. <otherwise>
  30. set amount_usable_ = (amount_usable_ - #{transAmount}),amount_frozen_ = (amount_frozen_ + #{transAmount}),
  31. </otherwise>
  32. </choose>
  33. update_time_ = now()
  34. where user_id_ = #{userId}
  35. </update>
  36. <update id="frozenDeductChangeAccount">
  37. update user_cash_account
  38. <choose>
  39. <when test="null != inOrOut and inOrOut == 'IN'">
  40. set amount_usable_ = (amount_usable_ + #{transAmount}),amount_frozen_ = (amount_frozen_ - #{transAmount}),
  41. </when>
  42. <otherwise>
  43. set amount_total_ = (amount_total_ - #{transAmount}),amount_frozen_ = (amount_frozen_ - #{transAmount}),
  44. </otherwise>
  45. </choose>
  46. update_time_ = now()
  47. where user_id_ = #{userId}
  48. </update>
  49. <update id="frozenBackChangeAccount">
  50. update user_cash_account
  51. <choose>
  52. <when test="null != inOrOut and inOrOut == 'IN'">
  53. set amount_total_ = (amount_total_ - #{transAmount}),amount_frozen_ = (amount_frozen_ - #{transAmount}),
  54. </when>
  55. <otherwise>
  56. set amount_usable_ = (amount_usable_ + #{transAmount}),amount_frozen_ = (amount_frozen_ - #{transAmount}),
  57. </otherwise>
  58. </choose>
  59. update_time_ = now()
  60. where user_id_ = #{userId}
  61. </update>
  62. <update id="changeAccount">
  63. update user_cash_account
  64. <choose>
  65. <when test="null != inOrOut and inOrOut == 'IN'">
  66. set amount_total_ = (amount_total_ + #{transAmount}),amount_usable_ = (amount_usable_ + #{transAmount}),
  67. </when>
  68. <otherwise>
  69. set amount_total_ = (amount_total_ - #{transAmount}),amount_usable_ = (amount_usable_ - #{transAmount}),
  70. </otherwise>
  71. </choose>
  72. update_time_ = now()
  73. where user_id_ = #{userId}
  74. </update>
  75. <select id="detail" resultType="com.yonge.cooleshow.biz.dal.vo.UserAccountVo">
  76. SELECT
  77. <include refid="baseColumns"/>,
  78. (select sum(a.trans_amount_) from user_cash_account_record a where a.account_id_ = t.user_id_
  79. and a.post_status_ = 'WAIT' and a.in_or_out_ = 'IN') as amountUnrecorded,
  80. (select sum(a.trans_amount_) from user_cash_account_record a where a.account_id_ = t.user_id_
  81. and a.post_status_ = 'RECORDED' and a.in_or_out_ = 'IN'
  82. and a.biz_type_ in ('LIVE_SHARE','VIDEO_SHARE','MUSIC_SHARE','VIP_SHARE','MALL_SHARE')) as amountShare
  83. FROM user_cash_account t
  84. where t.user_id_ = #{id}
  85. </select>
  86. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserAccountVo">
  87. SELECT
  88. <include refid="baseColumns"/>
  89. FROM user_cash_account t
  90. </select>
  91. <select id="accountTotal" resultType="com.yonge.cooleshow.biz.dal.vo.res.AccountTotal">
  92. select
  93. <if test="timeType != null and timeType == 'MONTH'">
  94. t.sys_day_ymd_ as timeStr,
  95. </if>
  96. <if test="timeType != null and timeType == 'YEAR'">
  97. t.sys_day_ym_ as timeStr,
  98. </if>
  99. sum(a.practiceAmount) as practiceAmount,
  100. sum(a.liveAmount) as liveAmount,
  101. sum(a.videoAmount) as videoAmount,
  102. sum(a.musicAmount) as musicAmount,
  103. sum(a.liveShareAmount) as liveShareAmount,
  104. sum(a.videoShareAmount) as videoShareAmount,
  105. sum(a.musicShareAmount) as musicShareAmount,
  106. sum(a.vipShareAmount) as vipShareAmount,
  107. sum(a.mallShareAmount) as mallShareAmount
  108. from sys_day t
  109. left join (
  110. select
  111. DATE_FORMAT(t.create_time_, '%Y-%m-%d') as timeStr,
  112. sum(if(t.biz_type_ = 'PRACTICE',t.trans_amount_,0)) as practiceAmount,
  113. sum(if(t.biz_type_ = 'LIVE',t.trans_amount_,0)) as liveAmount,
  114. sum(if(t.biz_type_ = 'VIDEO',t.trans_amount_,0)) as videoAmount,
  115. sum(if(t.biz_type_ = 'MUSIC',t.trans_amount_,0)) as musicAmount,
  116. sum(if(t.biz_type_ = 'LIVE_SHARE',t.trans_amount_,0)) as liveShareAmount,
  117. sum(if(t.biz_type_ = 'VIDEO_SHARE',t.trans_amount_,0)) as videoShareAmount,
  118. sum(if(t.biz_type_ = 'MUSIC_SHARE',t.trans_amount_,0)) as musicShareAmount,
  119. sum(if(t.biz_type_ = 'VIP_SHARE',t.trans_amount_,0)) as vipShareAmount,
  120. sum(if(t.biz_type_ = 'MALL_SHARE',t.trans_amount_,0)) as mallShareAmount
  121. from user_cash_account_record t
  122. <where>
  123. <if test="param.startTime !=null">
  124. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  125. </if>
  126. <if test="param.endTime !=null">
  127. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  128. </if>
  129. <if test="param.userId !=null">
  130. AND t.account_id_ = #{param.userId}
  131. </if>
  132. </where>
  133. group by DATE_FORMAT(t.create_time_,'%Y-%m-%d')
  134. ) a on t.sys_day_ymd_ = a.timeStr
  135. <where>
  136. <if test="param.startTime !=null">
  137. <![CDATA[AND t.sys_day_ >= #{param.startTime} ]]>
  138. </if>
  139. <if test="param.endTime !=null">
  140. <![CDATA[AND t.sys_day_ < #{param.endTime} ]]>
  141. </if>
  142. </where>
  143. <if test="timeType != null and timeType == 'MONTH'">
  144. group by t.sys_day_ymd_
  145. </if>
  146. <if test="timeType != null and timeType == 'YEAR'">
  147. group by t.sys_day_ym_
  148. </if>
  149. order by t.sys_day_ymd_
  150. </select>
  151. <select id="totalTransAmountByOrderNo" resultType="java.math.BigDecimal">
  152. select sum(trans_amount_) from user_cash_account_record
  153. where post_status_ in ('WAIT','FROZEN','RECORDED') and in_or_out_ = 'IN' and err_flag_ = 0
  154. and order_no_ = #{orderNo}
  155. </select>
  156. <select id="accountShareTotal" resultType="com.yonge.cooleshow.biz.dal.vo.res.AccountShareTotal">
  157. select
  158. sum(if(t.post_status_ in ('WAIT','RECORDED'),t.trans_amount_,0)) as totalAmount,
  159. sum(if(t.post_status_ = 'WAIT',t.trans_amount_,0)) as waitAmount,
  160. sum(if(t.post_status_ = 'RECORDED',t.trans_amount_,0)) as recordedAmount,
  161. sum(if(t.post_status_ = 'CANCEL',t.trans_amount_,0)) as cancelAmount,
  162. count(distinct t.buy_user_) as studentNum
  163. from user_cash_account_record t
  164. where t.account_id_ = #{param.userId}
  165. and t.biz_type_ in ('LIVE_SHARE','VIDEO_SHARE','MUSIC_SHARE','VIP_SHARE','MALL_SHARE')
  166. </select>
  167. </mapper>