FsUserIntegralLogsMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.fs.his.mapper.FsUserIntegralLogsMapper">
  6. <resultMap type="FsUserIntegralLogs" id="FsUserIntegralLogsResult">
  7. <result property="id" column="id" />
  8. <result property="userId" column="user_id" />
  9. <result property="logType" column="log_type" />
  10. <result property="integral" column="integral" />
  11. <result property="balance" column="balance" />
  12. <result property="businessId" column="business_id" />
  13. <result property="createTime" column="create_time" />
  14. <result property="businessType" column="business_type" />
  15. <result property="status" column="status" />
  16. </resultMap>
  17. <sql id="selectFsUserIntegralLogsVo">
  18. select id, user_id,status, log_type,business_type, integral, balance, business_id, create_time from fs_user_integral_logs
  19. </sql>
  20. <select id="selectFsUserIntegralLogsList" parameterType="FsUserIntegralLogs" resultMap="FsUserIntegralLogsResult">
  21. <include refid="selectFsUserIntegralLogsVo"/>
  22. <where>
  23. <if test="userId != null "> and user_id = #{userId}</if>
  24. <if test="logType != null and logType != ''"> and log_type = #{logType}</if>
  25. <if test="integral != null "> and integral = #{integral}</if>
  26. <if test="balance != null "> and balance = #{balance}</if>
  27. <if test="businessId != null and businessId != ''"> and business_id = #{businessId}</if>
  28. <if test="createTime != null "> and create_time = #{createTime}</if>
  29. <if test="businessType != null "> and business_type = #{businessType}</if>
  30. </where>
  31. </select>
  32. <select id="selectFsUserIntegralLogsListCOUNT" resultType="java.lang.Long">
  33. select count(*) from fs_user_integral_logs
  34. <where>
  35. <if test="userId != null "> and user_id = #{userId}</if>
  36. <if test="logType != null and logType != ''"> and log_type = #{logType}</if>
  37. <if test="integral != null "> and integral = #{integral}</if>
  38. <if test="balance != null "> and balance = #{balance}</if>
  39. <if test="businessId != null and businessId != ''"> and business_id = #{businessId}</if>
  40. <if test="createTime != null "> and create_time = #{createTime}</if>
  41. <if test="businessType != null "> and business_type = #{businessType}</if>
  42. </where>
  43. </select>
  44. <select id="selectFsUserIntegralLogsById" parameterType="Long" resultMap="FsUserIntegralLogsResult">
  45. <include refid="selectFsUserIntegralLogsVo"/>
  46. where id = #{id}
  47. </select>
  48. <select id="selectFsUserIntegralLogsByUserIdAndLogType" resultType="com.fs.his.domain.FsUserIntegralLogs">
  49. select * from fs_user_integral_logs where log_type=#{logType} and user_id = #{userId}
  50. <if test="date != null">
  51. <![CDATA[
  52. and create_time >= #{date} and create_time < date_add(#{date}, interval 1 day)
  53. ]]>
  54. </if>
  55. </select>
  56. <select id="getExchangDetailList" resultType="com.fs.his.vo.ExchangeDetailVo">
  57. SELECT
  58. id,
  59. user_id,
  60. log_type,
  61. integral,
  62. balance,
  63. create_time,
  64. ROUND(ABS(integral / 1000), 3) AS commission
  65. FROM
  66. fs_user_integral_logs
  67. WHERE
  68. user_id = #{userId}
  69. AND log_type = #{logType}
  70. order by create_time desc
  71. </select>
  72. <select id="sumIntegralByLogTypeAndCreateTime" resultType="java.lang.Long">
  73. SELECT COALESCE(SUM(integral), 0) FROM fs_user_integral_logs where log_type = #{logType} and <include refid="timeCondition"/>
  74. </select>
  75. <insert id="insertFsUserIntegralLogs" parameterType="FsUserIntegralLogs" useGeneratedKeys="true" keyProperty="id">
  76. insert into fs_user_integral_logs
  77. <trim prefix="(" suffix=")" suffixOverrides=",">
  78. <if test="userId != null">user_id,</if>
  79. <if test="logType != null">log_type,</if>
  80. <if test="integral != null">integral,</if>
  81. <if test="balance != null">balance,</if>
  82. <if test="businessId != null">business_id,</if>
  83. <if test="createTime != null">create_time,</if>
  84. <if test="businessType != null">business_type,</if>
  85. <if test="status != null">status,</if>
  86. </trim>
  87. <trim prefix="values (" suffix=")" suffixOverrides=",">
  88. <if test="userId != null">#{userId},</if>
  89. <if test="logType != null">#{logType},</if>
  90. <if test="integral != null">#{integral},</if>
  91. <if test="balance != null">#{balance},</if>
  92. <if test="businessId != null">#{businessId},</if>
  93. <if test="createTime != null">#{createTime},</if>
  94. <if test="businessType != null">#{businessType},</if>
  95. <if test="status != null">#{status},</if>
  96. </trim>
  97. </insert>
  98. <update id="updateFsUserIntegralLogs" parameterType="FsUserIntegralLogs">
  99. update fs_user_integral_logs
  100. <trim prefix="SET" suffixOverrides=",">
  101. <if test="userId != null">user_id = #{userId},</if>
  102. <if test="logType != null">log_type = #{logType},</if>
  103. <if test="integral != null">integral = #{integral},</if>
  104. <if test="balance != null">balance = #{balance},</if>
  105. <if test="businessId != null">business_id = #{businessId},</if>
  106. <if test="createTime != null">create_time = #{createTime},</if>
  107. <if test="businessType != null">business_type = #{businessType},</if>
  108. <if test="status != null">status = #{status},</if>
  109. </trim>
  110. where id = #{id}
  111. </update>
  112. <delete id="deleteFsUserIntegralLogsById" parameterType="Long">
  113. delete from fs_user_integral_logs where id = #{id}
  114. </delete>
  115. <delete id="deleteFsUserIntegralLogsByIds" parameterType="String">
  116. delete from fs_user_integral_logs where id in
  117. <foreach item="id" collection="array" open="(" separator="," close=")">
  118. #{id}
  119. </foreach>
  120. </delete>
  121. <sql id="timeCondition">
  122. <choose>
  123. <!-- type为null时,使用startTime和endTime -->
  124. <when test="param.type == null">
  125. a.create_time >= #{param.startTime}
  126. AND a.create_time &lt; DATE_ADD(#{param.endTime}, INTERVAL 1 DAY)
  127. </when>
  128. <!-- 1. 今天 -->
  129. <when test="param.type == 1">
  130. a.create_time >= CURDATE()
  131. AND a.create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  132. </when>
  133. <!-- 2. 昨天 -->
  134. <when test="param.type == 2">
  135. a.create_time >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  136. AND a.create_time &lt; CURDATE()
  137. </when>
  138. <!-- 3. 本周 -->
  139. <when test="param.type == 3">
  140. a.create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  141. AND a.create_time &lt; DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
  142. </when>
  143. <!-- 4. 上周 -->
  144. <when test="param.type == 4">
  145. a.create_time >= DATE_SUB(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
  146. AND a.create_time &lt; DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  147. </when>
  148. <!-- 5. 本月 -->
  149. <when test="param.type == 5">
  150. a.create_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
  151. AND a.create_time &lt; DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
  152. </when>
  153. <!-- 6. 上月 -->
  154. <when test="param.type == 6">
  155. a.create_time >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
  156. AND a.create_time &lt; DATE_FORMAT(CURDATE(), '%Y-%m-01')
  157. </when>
  158. <!-- 7. 本季度 -->
  159. <when test="param.type == 7">
  160. a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
  161. AND a.create_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
  162. </when>
  163. <!-- 8. 上季度 -->
  164. <when test="param.type == 8">
  165. a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
  166. AND a.create_time &lt; STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
  167. </when>
  168. <!-- 9. 本年 -->
  169. <when test="param.type == 9">
  170. a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
  171. AND a.create_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
  172. </when>
  173. <!-- 10. 去年 -->
  174. <when test="param.type == 10">
  175. a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
  176. AND a.create_time &lt; STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
  177. </when>
  178. </choose>
  179. </sql>
  180. </mapper>