FsUserIntegralLogsMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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(a.integral), 0) FROM fs_user_integral_logs a where a.log_type = #{logType} and <include refid="timeCondition"/>
  74. </select>
  75. <select id="statisticsListByCompany" resultType="com.fs.his.vo.FsUserIntegralLogsStatisticsVo">
  76. SELECT
  77. COALESCE(cuu.company_id, 0) AS id,
  78. CASE
  79. WHEN cuu.company_id IS NULL OR cuu.company_id &lt;= 0 THEN '公域用户'
  80. ELSE MAX(c.company_name)
  81. END AS `name`,
  82. SUM(f.integral) AS now_integral,
  83. SUM(f.withdraw_integral) AS withdraw_integral,
  84. SUM(f.integral) - SUM(f.withdraw_integral) AS disable_integral,
  85. SUM(f.withdraw_finish) AS finish_integral
  86. FROM fs_user f
  87. LEFT JOIN (
  88. SELECT DISTINCT user_id, company_id
  89. FROM company_user_user
  90. WHERE user_id IS NOT NULL
  91. AND company_id IS NOT NULL
  92. AND company_id > 0
  93. ) cuu ON cuu.user_id = f.user_id
  94. LEFT JOIN company c ON c.company_id = cuu.company_id
  95. GROUP BY
  96. CASE
  97. WHEN cuu.company_id IS NULL OR cuu.company_id &lt;= 0 THEN 0
  98. ELSE cuu.company_id
  99. END;
  100. </select>
  101. <select id="statisticsListByUser" resultType="com.fs.his.vo.FsUserIntegralLogsStatisticsVo">
  102. SELECT user_id AS id ,nick_name AS `name`, integral AS now_integral,withdraw_integral,
  103. integral-withdraw_integral AS disable_integral,withdraw_finish AS finish_integral
  104. FROM fs_user WHERE user_id = #{userId}
  105. </select>
  106. <insert id="insertFsUserIntegralLogs" parameterType="FsUserIntegralLogs" useGeneratedKeys="true" keyProperty="id">
  107. insert into fs_user_integral_logs
  108. <trim prefix="(" suffix=")" suffixOverrides=",">
  109. <if test="userId != null">user_id,</if>
  110. <if test="logType != null">log_type,</if>
  111. <if test="integral != null">integral,</if>
  112. <if test="balance != null">balance,</if>
  113. <if test="businessId != null">business_id,</if>
  114. <if test="createTime != null">create_time,</if>
  115. <if test="businessType != null">business_type,</if>
  116. <if test="status != null">status,</if>
  117. </trim>
  118. <trim prefix="values (" suffix=")" suffixOverrides=",">
  119. <if test="userId != null">#{userId},</if>
  120. <if test="logType != null">#{logType},</if>
  121. <if test="integral != null">#{integral},</if>
  122. <if test="balance != null">#{balance},</if>
  123. <if test="businessId != null">#{businessId},</if>
  124. <if test="createTime != null">#{createTime},</if>
  125. <if test="businessType != null">#{businessType},</if>
  126. <if test="status != null">#{status},</if>
  127. </trim>
  128. </insert>
  129. <update id="updateFsUserIntegralLogs" parameterType="FsUserIntegralLogs">
  130. update fs_user_integral_logs
  131. <trim prefix="SET" suffixOverrides=",">
  132. <if test="userId != null">user_id = #{userId},</if>
  133. <if test="logType != null">log_type = #{logType},</if>
  134. <if test="integral != null">integral = #{integral},</if>
  135. <if test="balance != null">balance = #{balance},</if>
  136. <if test="businessId != null">business_id = #{businessId},</if>
  137. <if test="createTime != null">create_time = #{createTime},</if>
  138. <if test="businessType != null">business_type = #{businessType},</if>
  139. <if test="status != null">status = #{status},</if>
  140. </trim>
  141. where id = #{id}
  142. </update>
  143. <delete id="deleteFsUserIntegralLogsById" parameterType="Long">
  144. delete from fs_user_integral_logs where id = #{id}
  145. </delete>
  146. <delete id="deleteFsUserIntegralLogsByIds" parameterType="String">
  147. delete from fs_user_integral_logs where id in
  148. <foreach item="id" collection="array" open="(" separator="," close=")">
  149. #{id}
  150. </foreach>
  151. </delete>
  152. <sql id="timeCondition">
  153. <choose>
  154. <!-- type为null时,使用startTime和endTime -->
  155. <when test="param.type == null">
  156. a.create_time >= #{param.startTime}
  157. AND a.create_time &lt; DATE_ADD(#{param.endTime}, INTERVAL 1 DAY)
  158. </when>
  159. <!-- 1. 今天 -->
  160. <when test="param.type == 1">
  161. a.create_time >= CURDATE()
  162. AND a.create_time &lt; DATE_ADD(CURDATE(), INTERVAL 1 DAY)
  163. </when>
  164. <!-- 2. 昨天 -->
  165. <when test="param.type == 2">
  166. a.create_time >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)
  167. AND a.create_time &lt; CURDATE()
  168. </when>
  169. <!-- 3. 本周 -->
  170. <when test="param.type == 3">
  171. a.create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  172. AND a.create_time &lt; DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
  173. </when>
  174. <!-- 4. 上周 -->
  175. <when test="param.type == 4">
  176. a.create_time >= DATE_SUB(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
  177. AND a.create_time &lt; DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  178. </when>
  179. <!-- 5. 本月 -->
  180. <when test="param.type == 5">
  181. a.create_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
  182. AND a.create_time &lt; DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
  183. </when>
  184. <!-- 6. 上月 -->
  185. <when test="param.type == 6">
  186. a.create_time >= DATE_SUB(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)
  187. AND a.create_time &lt; DATE_FORMAT(CURDATE(), '%Y-%m-01')
  188. </when>
  189. <!-- 7. 本季度 -->
  190. <when test="param.type == 7">
  191. a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
  192. AND a.create_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
  193. </when>
  194. <!-- 8. 上季度 -->
  195. <when test="param.type == 8">
  196. a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d'), INTERVAL 3 MONTH)
  197. AND a.create_time &lt; STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-', QUARTER(CURDATE())*3-2, '-01'), '%Y-%m-%d')
  198. </when>
  199. <!-- 9. 本年 -->
  200. <when test="param.type == 9">
  201. a.create_time >= STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
  202. AND a.create_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
  203. </when>
  204. <!-- 10. 去年 -->
  205. <when test="param.type == 10">
  206. a.create_time >= DATE_SUB(STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d'), INTERVAL 1 YEAR)
  207. AND a.create_time &lt; STR_TO_DATE(CONCAT(YEAR(CURDATE()), '-01-01'), '%Y-%m-%d')
  208. </when>
  209. </choose>
  210. </sql>
  211. </mapper>