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.

222 lines
8.7 KiB

2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
4 weeks ago
  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.example.demo.mapper.ConsumeMapper">
  4. <!-- 查询所有消费记录 -->
  5. <select id="selectAll" resultType="com.example.demo.domain.vo.ConsumeUser">
  6. SELECT u.name AS name,
  7. u.jwcode AS jwcode,
  8. u.market AS market,
  9. ugr.goods_name AS goodsName,
  10. ugr.pay_platform AS payPlatform,
  11. ugr.sum_gold AS sumGold,
  12. ugr.permanent_gold AS permanentGold,
  13. (COALESCE(ugr.free_june, 0) + COALESCE(ugr.free_december, 0)) AS freeGold,
  14. ugr.task_gold AS taskGold,
  15. ugr.remark AS remark,
  16. a.admin_name AS adminName,
  17. ugr.create_time AS createTime
  18. FROM user_gold_record ugr
  19. left JOIN
  20. user u ON u.jwcode = ugr.jwcode
  21. left JOIN
  22. admin a ON ugr.admin_id = a.id
  23. <where>
  24. ugr.type = 1 AND ugr.flag = 1
  25. <!-- 判断 market 是否不为总部且 markets 不为空 -->
  26. <if test="markets != null and markets.size() > 0 and '总部' not in markets">
  27. AND (
  28. <foreach collection="markets" item="market" open="" close="" separator=" OR ">
  29. u.market LIKE CONCAT('%', #{market}, '%')
  30. </foreach>
  31. )
  32. </if>
  33. </where>
  34. <trim prefix="ORDER BY" suffixOverrides=",">
  35. <choose>
  36. <!-- 当指定排序字段时使用指定字段排序 -->
  37. <when test="sortField != null and sortField != ''">
  38. <choose>
  39. <!-- 对三种金币数量的排序处理 -->
  40. <when test="sortField == 'taskGold'">ugr.task_gold</when>
  41. <when test="sortField == 'permanentGold'">ugr.permanent_gold</when>
  42. <when test="sortField == 'freeGold'">(COALESCE(ugr.free_june, 0) + COALESCE(ugr.free_december,
  43. 0))
  44. </when>
  45. <!-- 对时间字段的排序处理 -->
  46. <when test="sortField == 'createTime'">ugr.create_time</when>
  47. <!-- 其他字段不支持排序,使用默认排序 -->
  48. <otherwise>ugr.create_time</otherwise>
  49. </choose>
  50. <!-- 排序方向处理 -->
  51. <if test="sortOrder != null and sortOrder != ''">
  52. <choose>
  53. <when test="sortOrder == 'ASC'">ASC</when>
  54. <when test="sortOrder == 'DESC'">DESC</when>
  55. <otherwise>DESC</otherwise>
  56. </choose>
  57. </if>
  58. <if test="sortOrder == null or sortOrder == ''">
  59. DESC
  60. </if>
  61. </when>
  62. <!-- 未指定排序字段时,使用默认的时间降序排序 -->
  63. <otherwise>
  64. ugr.create_time DESC
  65. </otherwise>
  66. </choose>
  67. </trim>
  68. </select>
  69. <!-- 查询筛选后消费记录 -->
  70. <select id="selectBy" resultType="com.example.demo.domain.vo.ConsumeUser">
  71. SELECT u.name AS name,
  72. u.jwcode AS jwcode,
  73. u.market AS market,
  74. ugr.goods_name AS goodsName,
  75. ugr.pay_platform AS payPlatform,
  76. ugr.sum_gold AS sumGold,
  77. ugr.permanent_gold AS permanentGold,
  78. (COALESCE(ugr.free_june, 0) + COALESCE(ugr.free_december, 0)) AS freeGold,
  79. ugr.task_gold AS taskGold,
  80. ugr.remark AS remark,
  81. a.admin_name AS adminName,
  82. ugr.create_time AS createTime
  83. FROM user_gold_record ugr
  84. left JOIN
  85. user u ON u.jwcode = ugr.jwcode
  86. left JOIN
  87. admin a ON ugr.admin_id = a.id
  88. <where>
  89. ugr.type = 1 AND ugr.flag = 1
  90. <if test="markets != null and markets.size() > 0 and '总部' not in markets">
  91. AND (
  92. <foreach collection="markets" item="market" open="" close="" separator=" OR ">
  93. u.market LIKE CONCAT('%', #{market}, '%')
  94. </foreach>
  95. )
  96. </if>
  97. <if test="jwcode != null and jwcode != ''">
  98. AND ugr.jwcode = #{jwcode}
  99. </if>
  100. <if test="goodsName != null and goodsName != ''">
  101. AND ugr.goods_name = #{goodsName}
  102. </if>
  103. <if test="market != null and market != ''">
  104. AND u.market = #{market}
  105. </if>
  106. <if test="payPlatform != null and payPlatform != ''">
  107. AND ugr.pay_platform = #{payPlatform}
  108. </if>
  109. <if test="startTime != null and endTime != null">
  110. AND ugr.create_time BETWEEN #{startTime} AND #{endTime}
  111. </if>
  112. </where>
  113. <trim prefix="ORDER BY" suffixOverrides=",">
  114. <choose>
  115. <!-- 当指定排序字段时使用指定字段排序 -->
  116. <when test="sortField != null and sortField != ''">
  117. <choose>
  118. <!-- 对三种金币数量的排序处理 -->
  119. <when test="sortField == 'taskGold'">ugr.task_gold</when>
  120. <when test="sortField == 'permanentGold'">ugr.permanent_gold</when>
  121. <when test="sortField == 'freeGold'">(COALESCE(ugr.free_june, 0) + COALESCE(ugr.free_december,
  122. 0))
  123. </when>
  124. <!-- 对时间字段的排序处理 -->
  125. <when test="sortField == 'createTime'">ugr.create_time</when>
  126. <!-- 其他字段不支持排序,使用默认排序 -->
  127. <otherwise>ugr.create_time</otherwise>
  128. </choose>
  129. <!-- 排序方向处理 -->
  130. <if test="sortOrder != null and sortOrder != ''">
  131. <choose>
  132. <when test="sortOrder == 'ASC'">ASC</when>
  133. <when test="sortOrder == 'DESC'">DESC</when>
  134. <otherwise>DESC</otherwise>
  135. </choose>
  136. </if>
  137. <if test="sortOrder == null or sortOrder == ''">
  138. DESC
  139. </if>
  140. </when>
  141. <!-- 未指定排序字段时,使用默认的时间降序排序 -->
  142. <otherwise>
  143. ugr.create_time DESC
  144. </otherwise>
  145. </choose>
  146. </trim>
  147. </select>
  148. <select id="selectOrderCodeByJwcode" resultType="com.example.demo.domain.vo.ConsumeUser">
  149. SELECT ugr.jwcode AS jwcode,
  150. ugr.order_code AS orderCode,
  151. ugr.is_refund AS isRefund
  152. FROM user_gold_record ugr
  153. where ugr.order_code = #{orderCode}
  154. AND ugr.jwcode = #{jwcode}
  155. AND ugr.flag = 1
  156. </select>
  157. <insert id="add" parameterType="com.example.demo.domain.entity.UserGoldRecord" useGeneratedKeys="true"
  158. keyProperty="id">
  159. INSERT INTO user_gold_record
  160. <trim prefix="(" suffix=")" suffixOverrides=",">
  161. order_code,
  162. jwcode,
  163. sum_gold,
  164. permanent_gold,
  165. free_june,
  166. free_december,
  167. task_gold,
  168. goods_name,
  169. remark,
  170. type,
  171. pay_platform,
  172. is_refund,
  173. admin_id,
  174. audit_status,
  175. create_time,
  176. pay_time
  177. </trim>
  178. VALUES
  179. <trim prefix="(" suffix=")" suffixOverrides=",">
  180. #{orderCode},
  181. #{jwcode},
  182. #{sumGold},
  183. #{permanentGold},
  184. #{freeJune},
  185. #{freeDecember},
  186. #{taskGold},
  187. #{goodsName},
  188. #{remark},
  189. #{type},
  190. #{payPlatform},
  191. #{isRefund},
  192. #{adminId},
  193. #{auditStatus},
  194. #{createTime},
  195. #{payTime}
  196. </trim>
  197. </insert>
  198. <update id="updateIsRefund" parameterType="java.lang.String">
  199. UPDATE user_gold_record
  200. SET is_refund = 1
  201. where order_code = #{orderCode}
  202. AND flag = 1
  203. </update>
  204. <update id="updateUserGold" parameterType="com.example.demo.domain.entity.UserGoldRecord">
  205. UPDATE user
  206. SET sum_consume_permanent = #{permanentGold},
  207. sum_consume_free = COALESCE(#{freeJune}, 0) + COALESCE(#{freeDecember}, 0),
  208. sum_consume_task = #{taskGold}
  209. where jwcode = #{jwcode}
  210. </update>
  211. </mapper>