金币系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
9.8 KiB

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.example.demo.mapper.DetailYMapper" >
  6. <select id="select" resultType="com.example.demo.domain.entity.DetailY">
  7. SELECT
  8. username,
  9. name,
  10. detail_y.jwcode,
  11. area,
  12. detail_y.update_type,
  13. detail_y.create_time,
  14. detail_y.consume_platform,
  15. detail_y.free_coin,
  16. detail_y.recharge_coin,
  17. detail_y.task_coin,
  18. detail_y.product_name,
  19. (detail_y.recharge_coin + detail_y.free_coin + detail_y.task_coin) AS gold
  20. FROM
  21. detail_y
  22. <where>
  23. <if test="num!=null and num.length > 0">
  24. and recharge_coin NOT LIKE '-%'
  25. AND free_coin NOT LIKE '-%'
  26. AND task_coin NOT LIKE '-%'
  27. </if>
  28. <!-- 动态条件 -->
  29. <if test="jwcode != null and jwcode.length > 0">
  30. AND detail_y.jwcode = #{jwcode}
  31. </if>
  32. <if test="updateTypes != null">
  33. AND update_type IN
  34. <foreach collection="updateTypes" item="updateTypes" open="(" separator="," close=")">
  35. #{updateTypes}
  36. </foreach>
  37. </if>
  38. <if test="startDate != null and endDate != null">
  39. AND detail_y.create_time BETWEEN #{startDate} AND #{endDate}
  40. </if>
  41. <if test="consumePlatform != null and consumePlatform.length > 0">
  42. AND consume_platform = #{consumePlatform}
  43. </if>
  44. <if test="area != null and area.length > 0">
  45. AND area = #{area}
  46. </if>
  47. <if test="areas != null">
  48. AND area IN
  49. <foreach collection="areas" item="areas" open="(" separator="," close=")">
  50. #{areas}
  51. </foreach>
  52. </if>
  53. </where>
  54. <choose>
  55. <!-- 优先使用前端传入的排序参数 -->
  56. <when test="sortField != null and sortField.length >0 or sortOrder != null and sortOrder.length >0">
  57. ORDER BY ${sortField} ${sortOrder}
  58. </when>
  59. <!-- 默认排序 -->
  60. <otherwise>
  61. ORDER BY detaily_id DESC
  62. </otherwise>
  63. </choose>
  64. </select>
  65. <select id="select1" resultType="com.example.demo.domain.entity.DetailY">
  66. SELECT
  67. username,
  68. name,
  69. detail_y.jwcode,
  70. area,
  71. detail_y.update_type,
  72. detail_y.create_time,
  73. detail_y.consume_platform,
  74. detail_y.free_coin,
  75. detail_y.recharge_coin,
  76. detail_y.task_coin,
  77. detail_y.product_name,
  78. (detail_y.recharge_coin + detail_y.free_coin + detail_y.task_coin) AS gold
  79. FROM
  80. detail_y
  81. <where>
  82. <if test="num!=null and num.length > 0">
  83. AND (recharge_coin LIKE '-%'
  84. OR free_coin LIKE '-%'
  85. OR task_coin LIKE '-%')
  86. </if>
  87. <!-- 动态条件 -->
  88. <if test="jwcode != null and jwcode.length > 0">
  89. AND detail_y.jwcode = #{jwcode}
  90. </if>
  91. <if test="updateTypes != null">
  92. AND update_type IN
  93. <foreach collection="updateTypes" item="updateTypes" open="(" separator="," close=")">
  94. #{updateTypes}
  95. </foreach>
  96. </if>
  97. <if test="startDate != null and endDate != null">
  98. AND detail_y.create_time BETWEEN #{startDate} AND #{endDate}
  99. </if>
  100. <if test="consumePlatform != null and consumePlatform.length > 0">
  101. AND consume_platform = #{consumePlatform}
  102. </if>
  103. <if test="area != null and area.length > 0">
  104. AND area = #{area}
  105. </if>
  106. <if test="areas != null">
  107. AND area IN
  108. <foreach collection="areas" item="areas" open="(" separator="," close=")">
  109. #{areas}
  110. </foreach>
  111. </if>
  112. </where>
  113. <choose>
  114. <!-- 优先使用前端传入的排序参数 -->
  115. <when test="sortField != null and sortField.length >0 or sortOrder != null and sortOrder.length >0">
  116. ORDER BY ${sortField} ${sortOrder}
  117. </when>
  118. <!-- 默认排序 -->
  119. <otherwise>
  120. ORDER BY detaily_id DESC
  121. </otherwise>
  122. </choose>
  123. </select>
  124. <select id="getgold" resultType="com.example.demo.domain.vo.DetailYgold">
  125. select
  126. sum(recharge_coin) as SumbuyJb,
  127. sum(task_coin) as SumcoreJb,
  128. sum(free_coin) as SumfreeJb
  129. from detail_y
  130. group by jwcode
  131. </select>
  132. <select id="getDetailY" resultType="com.example.demo.domain.vo.SumDetailY">
  133. SELECT
  134. case when update_type = 0 then '充值'
  135. when update_type = 1 then '消费'
  136. when update_type = 2 then '退款'
  137. when update_type = 3 THEN '其他'
  138. else '未知'
  139. end as types,
  140. sum(recharge_coin) as SumR,
  141. sum(task_coin) as SumT,
  142. sum(free_coin) as SumF
  143. FROM
  144. detail_y
  145. <where>
  146. <if test="jwcode != null and jwcode.length > 0">
  147. AND detail_y.jwcode = #{jwcode}
  148. </if>
  149. <if test="updateTypes != null">
  150. AND update_type IN
  151. <foreach collection="updateTypes" item="updateTypes" open="(" separator="," close=")">
  152. #{updateTypes}
  153. </foreach>
  154. </if>
  155. <if test="startDate != null and endDate != null">
  156. AND detail_y.create_time BETWEEN #{startDate} AND #{endDate}
  157. </if>
  158. <if test="consumePlatform != null and consumePlatform.length > 0">
  159. AND consume_platform = #{consumePlatform}
  160. </if>
  161. <if test="area != null and area.length > 0">
  162. AND area = #{area}
  163. </if>
  164. <if test="areas != null">
  165. AND area IN
  166. <foreach collection="areas" item="areas" open="(" separator="," close=")">
  167. #{areas}
  168. </foreach>
  169. </if>
  170. </where>
  171. GROUP BY
  172. types;
  173. </select>
  174. <select id="getarea" resultType="java.lang.String">
  175. SELECT DISTINCT area FROM detail_y WHERE area IS NOT NULL
  176. </select>
  177. <select id="selectgold" resultType="com.example.demo.domain.vo.DetailYgold">
  178. SELECT
  179. `user`.name,
  180. `user`.area,
  181. user_gold.buy_jb,
  182. user_gold.core_jb,
  183. user_gold.free_12,
  184. user_gold.free_6,
  185. user_gold.jwcode,
  186. SUM(CASE WHEN detail_y.update_type = 0 THEN detail_y.recharge_coin ELSE 0 END) AS Rcoin,
  187. SUM(CASE WHEN detail_y.update_type = 1 THEN detail_y.recharge_coin + detail_y.free_coin + detail_y.task_coin ELSE 0 END) AS Scoin
  188. FROM
  189. detail_y
  190. LEFT JOIN
  191. user_gold ON detail_y.jwcode = user_gold.jwcode
  192. LEFT JOIN
  193. `user` ON detail_y.jwcode = `user`.jwcode
  194. <where>
  195. <if test='jwcode != null and jwcode.length > 0'>
  196. AND detail_y.jwcode = #{jwcode}
  197. </if>
  198. <if test='area != null and area.length > 0'>
  199. AND `user`.area = #{area}
  200. </if>
  201. <if test="areas != null">
  202. AND `user`.area IN
  203. <foreach collection="areas" item="areas" open="(" separator="," close=")">
  204. #{areas}
  205. </foreach>
  206. </if>
  207. </where>
  208. GROUP BY
  209. user_gold.jwcode
  210. <choose>
  211. <when test="sortField != null and sortField.length >0 or sortOrder != null and sortOrder.length >0">
  212. ORDER BY ${sortField} ${sortOrder}
  213. </when>
  214. <otherwise>
  215. ORDER BY Rcoin DESC
  216. </otherwise>
  217. </choose>
  218. </select>
  219. <select id="getCount" resultType="com.example.demo.domain.entity.DetailY">
  220. SELECT
  221. SUM(`buy_jb`) AS sumR,
  222. SUM(`core_jb`) AS sumT,
  223. SUM(`free_6`)+SUM(`free_12`) AS sumF
  224. FROM
  225. `user_gold`
  226. left join `user` on `user`.jwcode=`user_gold`.jwcode
  227. <where>
  228. <if test='jwcode != null and jwcode.length > 0'>
  229. AND user_gold.jwcode = #{jwcode}
  230. </if>
  231. <if test='area != null and area.length > 0'>
  232. AND area = #{area}
  233. </if>
  234. <if test="areas != null">
  235. AND area IN
  236. <foreach collection="areas" item="areas" open="(" separator="," close=")">
  237. #{areas}
  238. </foreach>
  239. </if>
  240. </where>
  241. </select>
  242. <select id="searchAll" resultType="com.example.demo.domain.entity.UserDetailExport">
  243. SELECT
  244. d.detaily_id,
  245. u.name,
  246. d.jwcode,
  247. u.area,
  248. d.consume_platform,
  249. d.update_type,
  250. d.recharge_coin,
  251. d.task_coin,
  252. d.free_coin,
  253. d.create_admin,
  254. d.create_time,
  255. (d.recharge_coin+d.task_coin+d.free_coin) AS gold
  256. FROM
  257. detail_y d
  258. LEFT JOIN
  259. user u ON d.jwcode = u.jwcode
  260. <where>
  261. <if test="updateType != null">
  262. AND d.update_type = #{updateType}
  263. </if>
  264. <if test="jwcode != null">
  265. AND d.jwcode = #{jwcode}
  266. </if>
  267. <if test="area != null">
  268. AND u.area = #{area}
  269. </if>
  270. <if test="areas != null">
  271. AND u.area IN
  272. <foreach collection="areas" item="areas" open="(" separator="," close=")">
  273. #{areas}
  274. </foreach>
  275. </if>
  276. <if test="startDate != null and endDate != null">
  277. AND d.create_time BETWEEN #{startDate} AND #{endDate}
  278. </if>
  279. </where>
  280. ORDER BY
  281. d.detaily_id DESC
  282. </select>
  283. </mapper>