UserAccountMapper.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. FROM user_cash_account t
  79. where t.user_id_ = #{id}
  80. </select>
  81. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserAccountVo">
  82. SELECT
  83. <include refid="baseColumns"/>
  84. FROM user_cash_account t
  85. </select>
  86. <select id="accountTotal" resultType="com.yonge.cooleshow.biz.dal.vo.res.AccountTotal">
  87. select
  88. <if test="timeType != null and timeType == 'MONTH'">
  89. t.sys_day_ymd_ as timeStr,
  90. </if>
  91. <if test="timeType != null and timeType == 'YEAR'">
  92. t.sys_day_ym_ as timeStr,
  93. </if>
  94. sum(a.practiceAmount) as practiceAmount,
  95. sum(a.liveAmount) as liveAmount,
  96. sum(a.videoAmount) as videoAmount,
  97. sum(a.musicAmount) as musicAmount
  98. from sys_day t
  99. left join (
  100. select
  101. DATE_FORMAT(t.create_time_, '%Y-%m-%d') as timeStr,
  102. sum(if(t.biz_type_ = 'PRACTICE',t.trans_amount_,0)) as practiceAmount,
  103. sum(if(t.biz_type_ = 'LIVE',t.trans_amount_,0)) as liveAmount,
  104. sum(if(t.biz_type_ = 'VIDEO',t.trans_amount_,0)) as videoAmount,
  105. sum(if(t.biz_type_ = 'MUSIC',t.trans_amount_,0)) as musicAmount
  106. from user_cash_account_record t
  107. <where>
  108. <if test="param.startTime !=null">
  109. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  110. </if>
  111. <if test="param.endTime !=null">
  112. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  113. </if>
  114. <if test="param.userId !=null">
  115. AND t.account_id_ = #{param.userId}
  116. </if>
  117. </where>
  118. group by DATE_FORMAT(t.create_time_,'%Y-%m-%d')
  119. ) a on t.sys_day_ymd_ = a.timeStr
  120. <where>
  121. <if test="param.startTime !=null">
  122. <![CDATA[AND t.sys_day_ >= #{param.startTime} ]]>
  123. </if>
  124. <if test="param.endTime !=null">
  125. <![CDATA[AND t.sys_day_ < #{param.endTime} ]]>
  126. </if>
  127. </where>
  128. <if test="timeType != null and timeType == 'MONTH'">
  129. group by t.sys_day_ymd_
  130. </if>
  131. <if test="timeType != null and timeType == 'YEAR'">
  132. group by t.sys_day_ym_
  133. </if>
  134. order by t.sys_day_ymd_
  135. </select>
  136. </mapper>