UserMapper.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.tdba.cxb.ares.api.repository.UserMapper">
  4. <select id="selectByTimeRegion" resultType="com.tdba.cxb.ares.api.model.UserDto">
  5. select
  6. uid,
  7. spread_uid
  8. from
  9. rrx_user
  10. where
  11. -- <![CDATA[ spread_uid > 0 ]]>
  12. <![CDATA[ create_time >= #{beginTime} ]]>
  13. <![CDATA[ and create_time <= #{endTime} ]]>
  14. </select>
  15. <select id="selectDacang" resultType="com.tdba.cxb.ares.api.model.UserDto">
  16. select
  17. count(1) 'num',
  18. u.spread_uid,
  19. group_concat(u.uid) 'uid_concat'
  20. from
  21. rrx_da_cang_user da
  22. left join
  23. rrx_user u
  24. on da.uid = u.uid
  25. where
  26. da.status = 1
  27. <![CDATA[ and da.ctime >= #{beginTime} ]]>
  28. <![CDATA[ and da.ctime <= #{endTime} ]]>
  29. and u.spread_uid > 0
  30. group by u.spread_uid
  31. </select>
  32. <select id="selectMerchant" resultType="com.tdba.cxb.ares.api.model.UserDto">
  33. select
  34. count(1) 'num',
  35. u.spread_uid,
  36. group_concat(u.uid) 'uid_concat'
  37. from
  38. rrx_merchant_admin da
  39. left join
  40. rrx_user u
  41. on da.uid = u.uid
  42. where
  43. da.status = 1
  44. <![CDATA[ and da.create_time >= #{beginTime} ]]>
  45. <![CDATA[ and da.create_time <=#{endTime} ]]>
  46. and u.spread_uid > 0
  47. group by u.spread_uid
  48. </select>
  49. <select id="selectChannel" resultType="com.tdba.cxb.ares.api.model.UserDto">
  50. select
  51. count(1) 'num',
  52. u.spread_uid,
  53. group_concat(u.uid) 'uid_concat'
  54. from
  55. rrx_channel_user da
  56. left join
  57. rrx_user u
  58. on da.uid = u.uid
  59. where
  60. da.status = 1
  61. <![CDATA[ and da.ctime >= #{beginTime} ]]>
  62. <![CDATA[ and da.ctime <= #{endTime} ]]>
  63. and u.spread_uid > 0
  64. group by u.spread_uid
  65. </select>
  66. <select id="selectAgent" resultType="com.tdba.cxb.ares.api.model.UserDto">
  67. select
  68. count(1) 'num',
  69. u.spread_uid,
  70. group_concat(u.uid) 'uid_concat'
  71. from
  72. rrx_user u
  73. where
  74. u.identity in (1, 2, 3)
  75. <![CDATA[ and u.create_time >= #{beginTime} ]]>
  76. <![CDATA[ and u.create_time <= #{endTime} ]]>
  77. and u.spread_uid > 0
  78. group by u.spread_uid
  79. </select>
  80. <select id="selectByAccount" resultType="com.tdba.cxb.ares.api.model.UserVo">
  81. select
  82. u.account 'mobile',
  83. u.uid 'id',
  84. u.nickname 'name',
  85. u.avatar
  86. from
  87. user_operator uo
  88. left join
  89. rrx_user u
  90. on uo.uid = u.uid
  91. where
  92. uo.del_flag = 0
  93. and u.status = 1
  94. and u.account = #{mobile}
  95. limit 1
  96. </select>
  97. <select id="selectByUid" resultType="com.tdba.cxb.ares.api.model.UserVo">
  98. select
  99. u.account 'mobile',
  100. u.uid 'id',
  101. u.nickname 'name',
  102. u.avatar
  103. from
  104. user_operator uo
  105. left join
  106. rrx_user u
  107. on uo.uid = u.uid
  108. where
  109. uo.del_flag = 0
  110. and u.status = 1
  111. and u.uid = #{uid}
  112. limit 1
  113. </select>
  114. <select id="selectByBindUid" resultType="com.tdba.cxb.ares.api.model.UserVo">
  115. select
  116. u.account 'mobile',
  117. u.uid 'id',
  118. u.nickname,
  119. u.avatar,
  120. ub.name,
  121. '1' as 'status'
  122. from
  123. user_bind ub
  124. left join
  125. rrx_user u
  126. on ub.uid = u.uid
  127. where
  128. ub.del_flag = 0
  129. and ub.bind_uid = #{bindUid}
  130. </select>
  131. <select id="selectByAccountForSimple" resultType="com.tdba.cxb.ares.api.model.UserVo">
  132. select
  133. u.account 'mobile',
  134. u.uid 'id',
  135. u.nickname 'name',
  136. u.avatar
  137. from
  138. rrx_user u
  139. where
  140. u.account = #{mobile}
  141. limit 1
  142. </select>
  143. <select id="selectTotal" resultType="com.tdba.cxb.ares.api.model.DataTotalResp">
  144. select
  145. user_type,
  146. sum(num) 'count'
  147. from
  148. user_count
  149. where
  150. del_flag = 0
  151. <choose>
  152. <when test="uid != null">
  153. and uid = #{uid}
  154. </when>
  155. <otherwise>
  156. and uid in (
  157. select
  158. uid
  159. from
  160. user_bind ub
  161. where
  162. ub.del_flag = 0
  163. and ub.type = 0
  164. and ub.bind_uid = #{bindUid}
  165. )
  166. </otherwise>
  167. </choose>
  168. group by
  169. user_type
  170. </select>
  171. <select id="selectList" resultType="com.tdba.cxb.ares.api.model.DataListResp">
  172. select
  173. <choose>
  174. <when test="type == null || type == 0">
  175. DATE_FORMAT(date,'%Y-%m-%d') as 'date',
  176. </when>
  177. <when test="type == 1">
  178. DATE_FORMAT(date,'%Y-%m') as 'date',
  179. </when>
  180. </choose>
  181. sum(IF(user_type = 0, num, 0)) as 'user_count',
  182. sum(IF(user_type = 1, num, 0)) as 'warehouse_count',
  183. sum(IF(user_type = 2, num, 0)) as 'merchant_count',
  184. sum(IF(user_type = 3, num, 0)) as 'channel_count',
  185. sum(IF(user_type = 4, num, 0)) as 'agent_count'
  186. from
  187. user_count
  188. where
  189. del_flag = 0
  190. and uid in (
  191. select
  192. uid
  193. from
  194. user_bind ub
  195. where
  196. ub.del_flag = 0
  197. and ub.type = 0
  198. and ub.bind_uid = #{uid}
  199. )
  200. <choose>
  201. <when test="type == null || type == 0">
  202. group by `date`
  203. </when>
  204. <when test="type == 1">
  205. group by DATE_FORMAT(date,'%Y-%m')
  206. </when>
  207. </choose>
  208. <choose>
  209. <when test="type == null || type == 0">
  210. order by `date` desc
  211. </when>
  212. <when test="type == 1">
  213. order by DATE_FORMAT(date,'%Y-%m') desc
  214. </when>
  215. </choose>
  216. </select>
  217. </mapper>