UserMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.yami.shop.dao.UserMapper">
  4. <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.User">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="user_id" jdbcType="VARCHAR" property="userId"/>
  9. <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
  10. <result column="real_name" jdbcType="VARCHAR" property="realName"/>
  11. <result column="user_mail" jdbcType="VARCHAR" property="userMail"/>
  12. <result column="login_password" jdbcType="VARCHAR" property="loginPassword"/>
  13. <result column="pay_password" jdbcType="VARCHAR" property="payPassword"/>
  14. <result column="user_mobile" jdbcType="VARCHAR" property="userMobile"/>
  15. <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
  16. <result column="user_regtime" jdbcType="TIMESTAMP" property="userRegtime"/>
  17. <result column="user_regip" jdbcType="VARCHAR" property="userRegip"/>
  18. <result column="user_memo" jdbcType="VARCHAR" property="userMemo"/>
  19. <result column="sex" jdbcType="CHAR" property="sex"/>
  20. <result column="birth_date" jdbcType="CHAR" property="birthDate"/>
  21. <result column="growth" jdbcType="BIGINT" property="growth"/>
  22. <result column="score" jdbcType="BIGINT" property="score"/>
  23. <result column="level" jdbcType="INTEGER" property="level"/>
  24. <result column="level_type" jdbcType="INTEGER" property="levelType"/>
  25. <result column="pic" jdbcType="VARCHAR" property="pic"/>
  26. <result column="status" jdbcType="INTEGER" property="status"/>
  27. </resultMap>
  28. <select id="getUserByBizUserId" resultMap="BaseResultMap">
  29. select *
  30. from tz_user u
  31. where u.user_id =
  32. (select user_id from tz_app_connect ac where ac.app_id = #{appId} and ac.biz_user_id = #{bizUserId})
  33. </select>
  34. <update id="setUserLevelBylevelId">
  35. UPDATE
  36. tz_user
  37. SET `level` = #{level} - 1
  38. WHERE `level` = #{level}
  39. </update>
  40. <update id="setMaxUserLevelBylevelId">
  41. UPDATE
  42. tz_user
  43. SET
  44. `level` = #{level}
  45. WHERE user_id IN
  46. (SELECT user_id FROM tz_user_extension WHERE growth &gt; #{minNeedGrowth}
  47. <if test="maxNeedGrowth != null">
  48. AND growth &lt; #{maxNeedGrowth}
  49. </if>)
  50. </update>
  51. <select id="selectMemberByEndTime" resultMap="BaseResultMap">
  52. select *
  53. from tz_user u
  54. where vip_end_time &lt; #{endOfDay}
  55. and level_type = 1
  56. </select>
  57. <update id="updateBatchById">
  58. <foreach collection="userList" item="user" separator=";">
  59. update tz_user set level =#{user.level},level_type=0 where user_id = #{user.userId}
  60. </foreach>
  61. </update>
  62. <select id="getUserPage" resultType="com.yami.shop.bean.model.User">
  63. SELECT u.nick_name,u.status,u.pic,u.level,u.level_type,ul.level_name,
  64. u.user_id,u.real_name,u.user_mobile,ue.score
  65. FROM tz_user u
  66. left JOIN tz_user_level ul ON ul.level = u.level AND ul.level_type = u.level_type
  67. JOIN tz_user_extension ue ON ue.`user_id` = u.user_id
  68. <where>
  69. <if test="user.nickName != null and user.nickName != ''">
  70. AND u.nick_name LIKE CONCAT("%",#{user.nickName},"%")
  71. </if>
  72. <if test="user.status != null">
  73. AND u.status = #{user.status}
  74. </if>
  75. <if test="user.levelType != null and user.levelType != ''">
  76. AND u.level_Type = #{user.levelType}
  77. </if>
  78. <if test="user.realName != null and user.realName != ''">
  79. AND u.real_name LIKE CONCAT("%",#{user.realName},"%")
  80. </if>
  81. <if test="user.userMobile != null and user.userMobile != ''">
  82. AND u.user_mobile LIKE CONCAT("%",#{user.userMobile},"%")
  83. </if>
  84. </where>
  85. </select>
  86. <select id="statisticsList" resultType="com.yami.shop.bean.vo.UserPointsVO">
  87. SELECT u.user_id,u.real_name,u.user_mobile,
  88. c.channel_name,
  89. sum(IF(pr.points_type = 1, pr.points, 0)) AS successStatus,
  90. sum(IF(pr.expiry_date IS NOT NULL AND pr.expiry_date &lt;= NOW() and pr.points_type = 1, pr.points -
  91. pr.variable_points, 0, 0)) AS availablePoints,
  92. sum(IF(pr.points_type = 1, pr.points, 0)) AS successStatus
  93. FROM tz_user u
  94. left JOIN tz_points_record pr ON pr.user_id = u.user_id
  95. left join tz_channel c ON c.id = pr.channel_id
  96. <where>
  97. </where>
  98. </select>
  99. <select id="enterpriseUserList" resultType="com.yami.shop.bean.vo.EnterpriseUserVo">
  100. SELECT a.user_id,a.`status`,a.real_name,a.user_mobile,a.channel_id,
  101. (SELECT channel_name FROM tz_channel WHERE id= a.channel_id) channelName,
  102. IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id),0) total, -- 总积分
  103. IFNULL(( select (
  104. SUM(CASE WHEN points_type = 1 OR points_type = 3 THEN points ELSE 0 END) -- 充值和退款的总积分
  105. -
  106. GREATEST(
  107. SUM( CASE WHEN expiry_date &lt;= NOW() THEN
  108. CASE WHEN points_type = 1 OR points_type = 3 THEN points
  109. WHEN points_type = 2 THEN -variable_points
  110. ELSE 0 END
  111. ELSE 0 END ), 0) -- 所以情况的过期积分
  112. -
  113. SUM(CASE WHEN points_type = 2 THEN variable_points ELSE 0 END) -- 下单的所有积分 未使用 -过期的 = 可用的
  114. ) from tz_points_record where user_id = a.user_id and channel_id = a.channel_id ),0) available, -- 当前可用积分
  115. IFNULL(( select GREATEST(
  116. SUM(
  117. CASE WHEN expiry_date &lt;= NOW() THEN
  118. CASE WHEN points_type = 1 OR points_type = 3 THEN points
  119. WHEN points_type = 2 THEN -variable_points
  120. ELSE 0 END
  121. ELSE 0 END ), 0 ) from tz_points_record where user_id = a.user_id and channel_id = a.channel_id),0) expired, -- 已过期积分
  122. IFNULL((select (
  123. SUM(CASE WHEN points_type = 2 THEN variable_points ELSE 0 END)
  124. -
  125. SUM(CASE WHEN points_type = 3 THEN points ELSE 0 END)) from tz_points_record where user_id = a.user_id and channel_id = a.channel_id),0) used -- 已消耗积分
  126. FROM tz_user a
  127. <where>
  128. a.channel_id in (SELECT id FROM tz_channel)
  129. <if test="po.channelIdList != null and po.channelIdList != ''">
  130. and a.channel_id in
  131. <foreach collection="po.channelIdList" item="channelId" open="(" close=")" separator=",">
  132. #{channelId}
  133. </foreach>
  134. </if>
  135. <if test="po.realName != null and po.realName != ''">
  136. AND a.real_name LIKE CONCAT("%",#{po.realName},"%")
  137. </if>
  138. <if test="po.userMobile != null and po.userMobile != ''">
  139. AND a.user_mobile LIKE CONCAT("%",#{po.userMobile},"%")
  140. </if>
  141. </where>
  142. </select>
  143. <insert id="addUserLog" parameterType="string">
  144. insert into tz_user_add_log(operator, batch_no, task_name, create_time, complete_time, `status`, channel,real_name, phone)
  145. values (#{operator}, #{batchNo}, "员工导入", NOW(), NOW(), #{status}, #{channel}, #{realName}, #{phone})
  146. </insert>
  147. <select id="enterpriseUserLogList" resultType="com.yami.shop.bean.po.EnterpriseUserLogPo">
  148. SELECT b.batch_no,
  149. b.operator,
  150. b.task_name,
  151. b.create_time,
  152. b.complete_time,
  153. b.total,
  154. b.success,
  155. b.error
  156. FROM (SELECT batch_no,
  157. ANY_VALUE(operator) AS operator,
  158. ANY_VALUE(task_name) AS task_name,
  159. MIN(create_time) AS create_time,
  160. MAX(complete_time) AS complete_time,
  161. COUNT(1) AS total,
  162. SUM(`status` = 1) AS success,
  163. SUM(`status` = 0) AS error
  164. FROM tz_user_add_log
  165. GROUP BY batch_no) b
  166. ORDER BY b.complete_time DESC
  167. </select>
  168. <select id="userList" resultType="com.yami.shop.bean.model.User">
  169. select * from tz_user
  170. <where>
  171. <if test="user.nickName != null and user.nickName != ''">
  172. AND nick_name LIKE CONCAT("%",#{user.nickName},"%")
  173. </if>
  174. </where>
  175. </select>
  176. <select id="enterpriseUserLogErrList" resultType="com.yami.shop.bean.po.EnterpriseUserLogPo">
  177. SELECT *
  178. FROM tz_user_add_log
  179. WHERE batch_no = #{batchNo}
  180. and `status` = 0
  181. ORDER BY create_time
  182. </select>
  183. <select id="exportList" resultType="com.yami.shop.bean.vo.EnterpriseUserVo">
  184. SELECT a.user_id,a.`status`,a.real_name,a.user_mobile,a.channel_id,
  185. (SELECT channel_name FROM tz_channel WHERE id= a.channel_id) channelName,
  186. IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id),0) total, -- 总积分
  187. IFNULL(( select (
  188. SUM(CASE WHEN points_type = 1 OR points_type = 3 THEN points ELSE 0 END) -- 充值和退款的总积分
  189. -
  190. GREATEST(
  191. SUM( CASE WHEN expiry_date &lt;= NOW() THEN
  192. CASE WHEN points_type = 1 OR points_type = 3 THEN points
  193. WHEN points_type = 2 THEN -variable_points
  194. ELSE 0 END
  195. ELSE 0 END ), 0) -- 所以情况的过期积分
  196. -
  197. SUM(CASE WHEN points_type = 2 THEN variable_points ELSE 0 END) -- 下单的所有积分 未使用 -过期的 = 可用的
  198. ) from tz_points_record where user_id = a.user_id and channel_id = a.channel_id ),0) available, -- 当前可用积分
  199. IFNULL(( select GREATEST(
  200. SUM(
  201. CASE WHEN expiry_date &lt;= NOW() THEN
  202. CASE WHEN points_type = 1 OR points_type = 3 THEN points
  203. WHEN points_type = 2 THEN -variable_points
  204. ELSE 0 END
  205. ELSE 0 END ), 0 ) from tz_points_record where user_id = a.user_id and channel_id = a.channel_id),0) expired, -- 已过期积分
  206. IFNULL((select (
  207. SUM(CASE WHEN points_type = 2 THEN variable_points ELSE 0 END)
  208. -
  209. SUM(CASE WHEN points_type = 3 THEN points ELSE 0 END)) from tz_points_record where user_id = a.user_id and channel_id = a.channel_id),0) used -- 已消耗积分
  210. FROM tz_user a
  211. <where>
  212. a.channel_id in (SELECT id FROM tz_channel)
  213. <if test="po.channelIdList != null and po.channelIdList != ''">
  214. and a.channel_id in
  215. <foreach collection="po.channelIdList" item="channelId" open="(" close=")" separator=",">
  216. #{channelId}
  217. </foreach>
  218. </if>
  219. <if test="po.realName != null and po.realName != ''">
  220. AND a.real_name LIKE CONCAT("%",#{po.realName},"%")
  221. </if>
  222. <if test="po.userMobile != null and po.userMobile != ''">
  223. AND a.user_mobile LIKE CONCAT("%",#{po.userMobile},"%")
  224. </if>
  225. </where>
  226. </select>
  227. </mapper>