UserMapper.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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_agent da
  73. left join
  74. rrx_user u
  75. on da.user_id = u.uid
  76. where
  77. da.status = 1
  78. and u.identity in (1, 2, 3)
  79. <![CDATA[ and da.add_time >= #{beginTime} ]]>
  80. <![CDATA[ and da.add_time <= #{endTime} ]]>
  81. and u.spread_uid > 0
  82. group by u.spread_uid
  83. </select>
  84. <select id="selectByAccount" resultType="com.tdba.cxb.ares.api.model.UserVo">
  85. select
  86. u.account 'mobile',
  87. u.uid 'id',
  88. u.nickname 'name',
  89. u.avatar
  90. from
  91. user_operator uo
  92. left join
  93. rrx_user u
  94. on uo.uid = u.uid
  95. where
  96. uo.del_flag = 0
  97. and u.status = 1
  98. and u.account = #{mobile}
  99. limit 1
  100. </select>
  101. <select id="selectByUid" resultType="com.tdba.cxb.ares.api.model.UserVo">
  102. select
  103. u.account 'mobile',
  104. u.uid 'id',
  105. u.nickname 'name',
  106. u.avatar
  107. from
  108. user_operator uo
  109. left join
  110. rrx_user u
  111. on uo.uid = u.uid
  112. where
  113. uo.del_flag = 0
  114. and u.status = 1
  115. and u.uid = #{uid}
  116. limit 1
  117. </select>
  118. <select id="selectByBindUid" resultType="com.tdba.cxb.ares.api.model.UserVo">
  119. select
  120. u.account 'mobile',
  121. u.uid 'id',
  122. u.nickname,
  123. u.avatar,
  124. ub.name,
  125. '1' as 'status'
  126. from
  127. user_bind ub
  128. left join
  129. rrx_user u
  130. on ub.uid = u.uid
  131. where
  132. ub.del_flag = 0
  133. and ub.bind_uid = #{bindUid}
  134. </select>
  135. <select id="selectByAccountForSimple" resultType="com.tdba.cxb.ares.api.model.UserVo">
  136. select
  137. u.account 'mobile',
  138. u.uid 'id',
  139. u.nickname 'name',
  140. u.avatar
  141. from
  142. rrx_user u
  143. where
  144. u.account = #{mobile}
  145. limit 1
  146. </select>
  147. <select id="selectTotal" resultType="com.tdba.cxb.ares.api.model.DataTotalResp">
  148. select
  149. user_type,
  150. sum(num) 'count'
  151. from
  152. user_count
  153. where
  154. del_flag = 0
  155. <choose>
  156. <when test="uid != null">
  157. and uid = #{uid}
  158. </when>
  159. <otherwise>
  160. and uid in (
  161. select
  162. uid
  163. from
  164. user_bind ub
  165. where
  166. ub.del_flag = 0
  167. and ub.type = 0
  168. and ub.bind_uid = #{bindUid}
  169. )
  170. </otherwise>
  171. </choose>
  172. group by
  173. user_type
  174. </select>
  175. <select id="selectList" resultType="com.tdba.cxb.ares.api.model.DataListResp">
  176. select
  177. <choose>
  178. <when test="type == null || type == 0">
  179. DATE_FORMAT(date,'%Y-%m-%d') as 'date',
  180. </when>
  181. <when test="type == 1">
  182. DATE_FORMAT(date,'%Y-%m') as 'date',
  183. </when>
  184. </choose>
  185. sum(IF(user_type = 0, num, 0)) as 'user_count',
  186. sum(IF(user_type = 1, num, 0)) as 'warehouse_count',
  187. sum(IF(user_type = 2, num, 0)) as 'merchant_count',
  188. sum(IF(user_type = 3, num, 0)) as 'channel_count',
  189. sum(IF(user_type = 4, num, 0)) as 'agent_count'
  190. from
  191. user_count
  192. where
  193. del_flag = 0
  194. and uid in (
  195. select
  196. uid
  197. from
  198. user_bind ub
  199. where
  200. ub.del_flag = 0
  201. and ub.type = 0
  202. and ub.bind_uid = #{uid}
  203. )
  204. <choose>
  205. <when test="type == null || type == 0">
  206. group by `date`
  207. </when>
  208. <when test="type == 1">
  209. group by DATE_FORMAT(date,'%Y-%m')
  210. </when>
  211. </choose>
  212. <choose>
  213. <when test="type == null || type == 0">
  214. order by `date` desc
  215. </when>
  216. <when test="type == 1">
  217. order by DATE_FORMAT(date,'%Y-%m') desc
  218. </when>
  219. </choose>
  220. </select>
  221. </mapper>