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