SysUserCashAccountDetailMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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.SysUserCashAccountDetailDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.SysUserCashAccountDetail" id="SysUserCashAccountDetail">
  9. <result column="id_" property="id"/>
  10. <result column="user_id_" property="userId"/>
  11. <result column="phone_" property="phone"/>
  12. <result column="username_" property="username"/>
  13. <result column="subject_name_" property="subjectName"/>
  14. <result column="trans_no_" property="transNo"/>
  15. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  16. <result column="trans_type_" property="transType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  17. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  18. <result column="amount_" property="amount"/>
  19. <result column="com_amount_" property="comAmount"/>
  20. <result column="per_amount_" property="perAmount"/>
  21. <result column="balance_" property="balance"/>
  22. <result column="description_" property="description"/>
  23. <result column="comment_" property="comment"/>
  24. <result column="create_time_" property="createTime"/>
  25. <result column="update_time_" property="updateTime"/>
  26. <result column="attribute1_" property="attribute"/>
  27. <result column="channel_" property="channel"/>
  28. <result column="organ_name_" property="organName"/>
  29. <result column="platform_account_no_" property="platformAccountNo"/>
  30. </resultMap>
  31. <!-- 根据主键查询一条记录 -->
  32. <select id="get" resultMap="SysUserCashAccountDetail">
  33. SELECT * FROM sys_user_cash_account_detail WHERE id_ = #{id}
  34. </select>
  35. <!-- 全查询 -->
  36. <select id="findAll" resultMap="SysUserCashAccountDetail">
  37. SELECT *
  38. FROM sys_user_cash_account_detail
  39. ORDER BY id_
  40. </select>
  41. <!-- 向数据库增加一条记录 -->
  42. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SysUserCashAccountDetail" useGeneratedKeys="true"
  43. keyColumn="id" keyProperty="id">
  44. INSERT INTO sys_user_cash_account_detail
  45. <trim prefix="(" suffix=")" suffixOverrides=",">
  46. <if test="id!=null">id_,</if>
  47. <if test="userId!=null">user_id_,</if>
  48. <if test="transNo!=null">trans_no_,</if>
  49. <if test="type!=null">type_,</if>
  50. <if test="transType!=null">trans_type_,</if>
  51. <if test="status!=null">status_,</if>
  52. <if test="amount!=null">amount_,</if>
  53. <if test="comAmount!=null">com_amount_,</if>
  54. <if test="perAmount!=null">per_amount_,</if>
  55. <if test="balance!=null">balance_,</if>
  56. <if test="description!=null">description_,</if>
  57. <if test="comment!=null">comment_,</if>
  58. create_time_,
  59. update_time_,
  60. <if test="attribute!=null">attribute1_,</if>
  61. <if test="channel!=null">channel_,</if>
  62. <if test="platformAccountNo!=null">platform_account_no_,</if>
  63. </trim>
  64. VALUES
  65. <trim prefix="(" suffix=")" suffixOverrides=",">
  66. <if test="id!=null">#{id},</if>
  67. <if test="userId!=null">#{userId},</if>
  68. <if test="transNo!=null">#{transNo},</if>
  69. <if test="type!=null">#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},</if>
  70. <if test="transType!=null">#{transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},</if>
  71. <if test="status!=null">#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},</if>
  72. <if test="amount!=null">#{amount},</if>
  73. <if test="comAmount!=null">#{comAmount},</if>
  74. <if test="perAmount!=null">#{perAmount},</if>
  75. <if test="balance!=null">#{balance},</if>
  76. <if test="description!=null">#{description},</if>
  77. <if test="comment!=null">#{comment},</if>
  78. NOW(),
  79. NOW(),
  80. <if test="attribute!=null">#{attribute},</if>
  81. <if test="channel!=null">#{channel},</if>
  82. <if test="platformAccountNo!=null">#{platformAccountNo},</if>
  83. </trim>
  84. </insert>
  85. <insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.SysUserCashAccountDetail" useGeneratedKeys="true"
  86. keyColumn="id" keyProperty="id">
  87. INSERT INTO sys_user_cash_account_detail
  88. (user_id_,trans_no_,type_,trans_type_,status_,amount_,balance_,description_,comment_,
  89. create_time_,update_time_,attribute1_,channel_,platform_account_no_)
  90. VALUE
  91. <foreach collection="sysUserCashAccountDetails" item="sysUserCashAccountDetail" separator=",">
  92. (#{sysUserCashAccountDetail.userId},#{sysUserCashAccountDetail.transNo},
  93. #{sysUserCashAccountDetail.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  94. #{sysUserCashAccountDetail.transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  95. #{sysUserCashAccountDetail.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  96. #{sysUserCashAccountDetail.amount},#{sysUserCashAccountDetail.balance},#{sysUserCashAccountDetail.description},
  97. #{sysUserCashAccountDetail.comment},now(),now(),#{sysUserCashAccountDetail.attribute},#{sysUserCashAccountDetail.channel},
  98. #{sysUserCashAccountDetail.platformAccountNo})
  99. </foreach>
  100. </insert>
  101. <!-- 根据主键查询一条记录 -->
  102. <update id="update" parameterType="com.ym.mec.biz.dal.entity.SysUserCashAccountDetail">
  103. UPDATE sys_user_cash_account_detail
  104. <set>
  105. <if test="status != null">
  106. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  107. </if>
  108. <if test="userId != null">
  109. user_id_ = #{userId},
  110. </if>
  111. <if test="balance != null">
  112. balance_ = #{balance},
  113. </if>
  114. <if test="comment != null">
  115. comment_ = #{comment},
  116. </if>
  117. update_time_ = NOW(),
  118. <if test="amount != null">
  119. amount_ = #{amount},
  120. </if>
  121. <if test="comAmount != null">
  122. com_amount_ = #{comAmount},
  123. </if>
  124. <if test="perAmount != null">
  125. per_amount_ = #{perAmount},
  126. </if>
  127. <if test="description != null">
  128. description_ = #{description},
  129. </if>
  130. <if test="transNo != null">
  131. trans_no_ = #{transNo},
  132. </if>
  133. <if test="type != null">
  134. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  135. </if>
  136. <if test="transType != null">
  137. trans_type_ = #{transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  138. </if>
  139. <if test="attribute != null">
  140. attribute1_ = #{attribute},
  141. </if>
  142. <if test="channel != null">
  143. channel_ = #{channel},
  144. </if>
  145. <if test="platformAccountNo != null">
  146. platform_account_no_ = #{platformAccountNo},
  147. </if>
  148. </set>
  149. WHERE id_ = #{id}
  150. </update>
  151. <!-- 根据主键删除一条记录 -->
  152. <delete id="delete">
  153. DELETE FROM sys_user_cash_account_detail WHERE id_ = #{id}
  154. </delete>
  155. <!-- 分页查询 -->
  156. <select id="queryPage" resultMap="SysUserCashAccountDetail" parameterType="map">
  157. SELECT * FROM sys_user_cash_account_detail
  158. <where>
  159. <if test="userId != null">
  160. user_id_ = #{userId}
  161. </if>
  162. <if test="search != null and search != ''">
  163. AND create_time_ LIKE CONCAT(#{search},'%')
  164. </if>
  165. <if test="channel != null ">
  166. AND channel_ NOT IN (#{channel}) OR channel_ IS NULL
  167. </if>
  168. </where>
  169. ORDER BY id_ DESC
  170. <include refid="global.limit"/>
  171. </select>
  172. <!-- 查询当前表的总记录数 -->
  173. <select id="queryCount" resultType="int">
  174. SELECT COUNT(*) FROM sys_user_cash_account_detail
  175. <where>
  176. <if test="userId != null">
  177. user_id_ = #{userId}
  178. </if>
  179. <if test="search != null and search != ''">
  180. AND create_time_ LIKE CONCAT(#{search},'%')
  181. </if>
  182. <if test="channel != null ">
  183. AND channel_ NOT IN (#{channel}) OR channel_ IS NULL
  184. </if>
  185. </where>
  186. </select>
  187. <select id="selectDetailByTransNo" resultMap="SysUserCashAccountDetail">
  188. SELECT * FROM sys_user_cash_account_detail WHERE trans_no_ = #{transNo}
  189. </select>
  190. <select id="queryStatisticsWithCurrentMonth" resultType="map">
  191. select sum(case when sucad.type_ = 'RECHARGE' then 1 else 0 end) income_num_,sum(case when sucad.type_ =
  192. 'RECHARGE' then sucad.amount_ else 0 end) income_total_,sum(case when (sucad.type_ = 'WITHDRAW' or sucad.type_ =
  193. 'REWARDS' or sucad.type_ = 'WAGE') then 1 else 0 end) expend_num_,sum(case when (sucad.type_ = 'WITHDRAW' or
  194. sucad.type_ = 'REWARDS' or sucad.type_ = 'WAGE') then sucad.amount_ else 0 end) expend_total_ from
  195. sys_user_cash_account_detail sucad
  196. left join sys_user u on sucad.user_id_ = u.id_
  197. where sucad.status_ = 'SUCCESS' and DATE_FORMAT(sucad.create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) and u.organ_id_ not in (36,38)
  198. <if test="organId != null">
  199. AND FIND_IN_SET(u.organ_id_,#{organId})
  200. </if>
  201. </select>
  202. <select id="countByTypeAndTime" resultType="java.lang.Integer">
  203. SELECT COUNT(s.id_) FROM sys_user_cash_account_detail s
  204. WHERE s.type_ = 'REWARDS' AND DATE_FORMAT(s.create_time_,'%Y-%m') = #{currentMonth}
  205. AND s.user_id_ = #{teacherId} AND s.description_ = #{activeId}
  206. </select>
  207. <sql id="queryAccountDetailCondition">
  208. <where>
  209. <if test="userId!=null">
  210. user_id_=#{userId}
  211. </if>
  212. </where>
  213. </sql>
  214. <select id="queryAccountDetail" resultMap="SysUserCashAccountDetail">
  215. SELECT * FROM (
  216. SELECT create_time_,amount_,balance_,status_,type_,description_,comment_ FROM sys_user_cash_account_detail
  217. <include refid="queryAccountDetailCondition"/>
  218. UNION ALL
  219. SELECT create_time_,amount_,balance_,status_,type_,description_,comment_ FROM sys_user_courses_account_detail
  220. <include refid="queryAccountDetailCondition"/>
  221. ) t ORDER BY t.create_time_
  222. <include refid="global.limit"/>
  223. </select>
  224. <select id="countAccountDetails" resultType="int">
  225. SELECT COUNT(t.id_) FROM (
  226. SELECT id_,create_time_,amount_,balance_,status_,type_,description_,comment_ FROM sys_user_cash_account_detail
  227. <include refid="queryAccountDetailCondition"/>
  228. UNION ALL
  229. SELECT id_,create_time_,amount_,balance_,status_,type_,description_,comment_ FROM sys_user_courses_account_detail
  230. <include refid="queryAccountDetailCondition"/>
  231. ) t
  232. </select>
  233. <select id="exportDetail" resultMap="SysUserCashAccountDetail">
  234. SELECT o.name_ organ_name_,su.username_,su.phone_,GROUP_CONCAT(sb.name_ ORDER BY sb.name_) subject_name_,cad.* FROM sys_user_cash_account_detail cad
  235. LEFT JOIN sys_user su ON su.id_ = cad.user_id_
  236. LEFT JOIN organization o ON o.id_ = su.organ_id_
  237. LEFT JOIN student s ON s.user_id_ = su.id_
  238. LEFT JOIN `subject` sb ON FIND_IN_SET(sb.id_,s.subject_id_list_)
  239. <where>
  240. <if test="queryInfo.userId != null">
  241. AND cad.user_id_ = #{queryInfo.userId}
  242. </if>
  243. <if test="queryInfo.organId != null">
  244. AND FIND_IN_SET(su.organ_id_,#{queryInfo.organId})
  245. </if>
  246. <if test="queryInfo.startTime != null and queryInfo.startTime != ''">
  247. AND DATE_FORMAT(cad.create_time_,'%Y-%m-%d') >= #{queryInfo.startTime}
  248. </if>
  249. <if test="queryInfo.endTime != null and queryInfo.startTime != ''">
  250. AND DATE_FORMAT(cad.create_time_,'%Y-%m-%d') &lt;= #{queryInfo.endTime}
  251. </if>
  252. </where>
  253. GROUP BY cad.id_
  254. ORDER BY cad.user_id_,cad.id_ DESC
  255. </select>
  256. </mapper>