You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

429 lines
16 KiB

  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.iformall.mapper.TtCUserMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.tt.TtCUser">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="user_id" jdbcType="BIGINT" property="userId"/>
  7. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  8. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId"/>
  9. <result column="open_id" jdbcType="VARCHAR" property="openId"/>
  10. <result column="union_id" jdbcType="VARCHAR" property="unionId"/>
  11. <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
  12. <result column="gender" jdbcType="INTEGER" property="gender"/>
  13. <result column="avatar_url" jdbcType="VARCHAR" property="avatarUrl"/>
  14. <result column="phone" jdbcType="VARCHAR" property="phone"/>
  15. <result column="pure_phone" jdbcType="VARCHAR" property="purePhone"/>
  16. <result column="city" jdbcType="VARCHAR" property="city"/>
  17. <result column="province" jdbcType="VARCHAR" property="province"/>
  18. <result column="language" jdbcType="VARCHAR" property="language"/>
  19. <result column="country_code" jdbcType="VARCHAR" property="countryCode"/>
  20. <result column="register_ip" jdbcType="VARCHAR" property="registerIp"/>
  21. <result column="verify_code_phone" jdbcType="VARCHAR" property="verifyCodePhone"/>
  22. <result column="qrcode_source" jdbcType="VARCHAR" property="qrcodeSource"/>
  23. <result column="scene" jdbcType="VARCHAR" property="scene"/>
  24. <result column="scene_address" jdbcType="VARCHAR" property="sceneAddress"/>
  25. <result column="session_key" jdbcType="VARCHAR" property="sessionKey"/>
  26. <result column="score" jdbcType="INTEGER" property="score"/>
  27. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  28. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  29. <result column="app_id" jdbcType="VARCHAR" property="appId"/>
  30. <result column="token" jdbcType="VARCHAR" property="token"/>
  31. <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime"/>
  32. <result column="latitude" jdbcType="DECIMAL" property="latitude"/>
  33. <result column="longitude" jdbcType="DECIMAL" property="longitude"/>
  34. <result column="locate_city" jdbcType="VARCHAR" property="locateCity"/>
  35. <result column="login_count" jdbcType="INTEGER" property="loginCount"/>
  36. <result column="extra_info" jdbcType="VARCHAR" property="extraInfo"/>
  37. <result column="is_subscribe" jdbcType="TINYINT" property="isSubscribe"/>
  38. <result column="open_app_id" jdbcType="VARCHAR" property="openAppId"/>
  39. <result column="mp_open_id" jdbcType="VARCHAR" property="mpOpenId"/>
  40. <result column="mp_app_id" jdbcType="VARCHAR" property="mpAppId"/>
  41. <result column="mp_subscribe" jdbcType="TINYINT" property="mpSubscribe"/>
  42. <result column="mp_subscribe_time" jdbcType="TIMESTAMP" property="mpSubscribeTime"/>
  43. <result column="mp_subscribe_scene" jdbcType="VARCHAR" property="mpSubscribeScene"/>
  44. <result column="subs_open_id" jdbcType="VARCHAR" property="subsOpenId"/>
  45. <result column="subs_app_id" jdbcType="VARCHAR" property="subsAppId"/>
  46. <result column="subs_subscribe" jdbcType="TINYINT" property="subsSubscribe"/>
  47. <result column="subs_subscribe_time" jdbcType="TIMESTAMP" property="subsSubscribeTime"/>
  48. <result column="subs_subscribe_scene" jdbcType="VARCHAR" property="subsSubscribeScene"/>
  49. <result column="credit" jdbcType="INTEGER" property="credit"/>
  50. <result column="active_time" jdbcType="TIMESTAMP" property="activeTime"/>
  51. <result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
  52. <result column="agree_protocol" jdbcType="INTEGER" property="agreeProtocol"/>
  53. </resultMap>
  54. <sql id="allColumns">
  55. `id`,`user_id`,`tenant_id`,`parent_tenant_id`,`open_id`,`union_id`,`nick_name`,`gender`,`avatar_url`,`phone`,`pure_phone`,
  56. `city`,`province`,`language`,`country_code`,`register_ip`,`verify_code_phone`,
  57. `qrcode_source`,`scene`,`scene_address`,`session_key`,`score`,
  58. `update_date`,`create_date`,`app_id`,`token`,`expire_time`,`latitude`, `longitude`, `locate_city`,
  59. `login_count`, `extra_info`, `is_subscribe`,
  60. `open_app_id`,
  61. `mp_open_id`,`mp_app_id`,`mp_subscribe`,`mp_subscribe_time`,`mp_subscribe_scene`,
  62. `subs_open_id`,`subs_app_id`,`subs_subscribe`,`subs_subscribe_time`,`subs_subscribe_scene`,`credit`,
  63. `active_time`,`qr_code`,`agree_protocol`
  64. </sql>
  65. <sql id="dynamicWhereConditions">
  66. where 1 = 1
  67. <if test=" null != id ">
  68. and `id` = #{id}
  69. </if>
  70. <if test=" null != userId ">
  71. and `user_id` = #{userId}
  72. </if>
  73. <if test=" null != tenantId and '' != tenantId">
  74. and `tenant_id` = #{tenantId}
  75. </if>
  76. <if test=" null != parentTenantId and '' != parentTenantId">
  77. and `parent_tenant_id` = #{parentTenantId}
  78. </if>
  79. <if test=" null != openId ">
  80. and `open_id` = #{openId}
  81. </if>
  82. <if test=" null != unionId ">
  83. and `union_id` = #{unionId}
  84. </if>
  85. <if test=" null != nickName ">
  86. and `nick_name` like concat('%', #{nickName},'%')
  87. </if>
  88. <if test=" null != gender ">
  89. and `gender` = #{gender}
  90. </if>
  91. <if test=" null != avatarUrl ">
  92. and `avatar_url` like concat('%', #{avatarUrl},'%')
  93. </if>
  94. <if test=" null != phone ">
  95. and `phone` like concat('%', #{phone},'%')
  96. </if>
  97. <if test=" null != purePhone ">
  98. and `pure_phone` like concat('%', #{purePhone},'%')
  99. </if>
  100. <if test=" null != city ">
  101. and `city` like concat('%', #{city},'%')
  102. </if>
  103. <if test=" null != province ">
  104. and `province` like concat('%', #{province},'%')
  105. </if>
  106. <if test=" null != language ">
  107. and `language` like concat('%', #{language},'%')
  108. </if>
  109. <if test=" null != countryCode ">
  110. and `country_code` like concat('%', #{countryCode},'%')
  111. </if>
  112. <if test=" null != registerIp ">
  113. and `register_ip` like concat('%', #{registerIp},'%')
  114. </if>
  115. <if test=" null != verifyCodePhone ">
  116. and `verify_code_phone` like concat('%', #{verifyCodePhone},'%')
  117. </if>
  118. <if test=" null != qrcodeSource ">
  119. and `qrcode_source` like concat('%', #{qrcodeSource},'%')
  120. </if>
  121. <if test=" null != scene ">
  122. and `scene` like concat('%', #{scene},'%')
  123. </if>
  124. <if test=" null != sceneAddress ">
  125. and `scene_address` like concat('%', #{sceneAddress},'%')
  126. </if>
  127. <if test=" null != sessionKey ">
  128. and `session_key` like concat('%', #{sessionKey},'%')
  129. </if>
  130. <if test=" null != score ">
  131. and `score` = #{score}
  132. </if>
  133. <if test=" null != updateDate ">
  134. and `update_date` = #{updateDate}
  135. </if>
  136. <if test=" null != createDate ">
  137. and `create_date` = #{createDate}
  138. </if>
  139. <if test=" null != appId ">
  140. and `app_id` like concat('%', #{appId},'%')
  141. </if>
  142. <if test=" null != token ">
  143. and `token` like concat('%', #{token},'%')
  144. </if>
  145. <if test=" null != expireTime ">
  146. and `expire_time` = #{expireTime}
  147. </if>
  148. <if test=" null != latitude ">
  149. and `latitude` = #{latitude}
  150. </if>
  151. <if test=" null != longitude ">
  152. and `longitude` = #{longitude}
  153. </if>
  154. <if test=" null != loginCount ">
  155. and `login_count` = #{loginCount}
  156. </if>
  157. <if test=" null != extraInfo ">
  158. and `extra_info` = #{extraInfo}
  159. </if>
  160. <if test=" null != isSubscribe ">
  161. and `is_subscribe` = #{isSubscribe}
  162. </if>
  163. <if test=" null != openAppId ">
  164. and `open_app_id` = #{openAppId}
  165. </if>
  166. <if test=" null != mpOpenId ">
  167. and `mp_open_id` = #{mpOpenId}
  168. </if>
  169. <if test=" null != mpAppId ">
  170. and `mp_app_id` = #{mpAppId}
  171. </if>
  172. <if test=" null != subsOpenId ">
  173. and `subs_open_id` = #{subsOpenId}
  174. </if>
  175. <if test=" null != subsAppId ">
  176. and `subs_app_id` = #{subsAppId}
  177. </if>
  178. <if test=" null != credit ">
  179. and `credit` = #{credit}
  180. </if>
  181. <if test=" null != ids ">
  182. and id in
  183. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  184. #{idItem}
  185. </foreach>
  186. </if>
  187. <if test=" null != sortColumns">order by ${sortColumns}</if>
  188. </sql>
  189. <select id="findList" parameterType="com.iformall.domain.po.tt.TtCUser" resultMap="BaseResultMap">
  190. select
  191. <include refid="allColumns"/>
  192. from tt_c_user
  193. <include refid="dynamicWhereConditions"/>
  194. </select>
  195. <select id="listOpenId" parameterType="com.iformall.domain.po.tt.TtCUser" resultType="String">
  196. select open_id
  197. from tt_c_user
  198. where user_id is not null
  199. and `tenant_id` = #{tenantId}
  200. <if test=" null != parentTenantId and '' != parentTenantId">
  201. and `parent_tenant_id` = #{parentTenantId}
  202. </if>
  203. <if test=" null == userIds ">
  204. and DATE_SUB(CURDATE(), INTERVAL 100 DAY) &lt;= date(active_time)
  205. </if>
  206. <if test=" null != userIds ">
  207. and user_id in
  208. <foreach collection="userIds" index="index" item="userIdItem" open="(" separator="," close=")">
  209. #{userIdItem}
  210. </foreach>
  211. </if>
  212. </select>
  213. <select id="findByOpenId" parameterType="com.iformall.domain.po.tt.TtCUser" resultMap="BaseResultMap">
  214. select <include refid="allColumns"/>
  215. from tt_c_user
  216. where `open_id` = #{openId}
  217. <if test=" null != appId and '' != appId">
  218. and `app_id` = #{appId}
  219. </if>
  220. </select>
  221. <select id="findByUnionId" parameterType="com.iformall.domain.po.tt.TtCUser" resultMap="BaseResultMap">
  222. select <include refid="allColumns"/>
  223. from tt_c_user
  224. where `open_app_id` = #{openAppId} and `union_id` = #{unionId}
  225. </select>
  226. <select id="findByToken" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  227. select <include refid="allColumns"/>
  228. from tt_c_user
  229. where `token` = #{token} and `tenant_id` = #{tenantId}
  230. </select>
  231. <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  232. select <include refid="allColumns"/>
  233. from tt_c_user
  234. where id = #{id}
  235. and `tenant_id` = #{tenantId}
  236. </select>
  237. <select id="findCount" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  238. select count(id)
  239. from tt_c_user
  240. where `tenant_id` = #{tenantId}
  241. <if test=" null != parentTenantId and '' != parentTenantId">
  242. and `parent_tenant_id` = #{parentTenantId}
  243. </if>
  244. <if test=" null != sex ">
  245. and gender =#{sex}
  246. </if>
  247. <if test=" null != startTime ">
  248. and create_date &gt;= #{startTime}
  249. </if>
  250. <if test=" null != endTime">
  251. and create_date &lt; #{endTime}
  252. </if>
  253. </select>
  254. <select id="findCountData" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="com.iformall.domain.vo.UserStructureVo">
  255. select DATE_FORMAT(create_date,'%m/%d') as name,count(id) count
  256. from tt_c_user
  257. where `tenant_id` = #{tenantId}
  258. <if test=" null != parentTenantId and '' != parentTenantId">
  259. and `parent_tenant_id` = #{parentTenantId}
  260. </if>
  261. <if test=" null != sex ">
  262. and gender =#{sex}
  263. </if>
  264. <if test=" null != startTime ">
  265. and create_date &gt;= #{startTime}
  266. </if>
  267. <if test=" null != endTime">
  268. and create_date &lt; #{endTime}
  269. </if>
  270. group by name
  271. </select>
  272. <select id="findCountHistory" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="com.iformall.domain.vo.UserCountVo">
  273. select count(id) as incCount,
  274. <if test="1 == reportType ">
  275. date_format(create_date, '%Y-%m-%d') as reportTime
  276. </if>
  277. <if test="2 == reportType ">
  278. date_format(create_date, '%Y-%m') as reportTime
  279. </if>
  280. <if test="3 == reportType ">
  281. date_format(create_date, '%Y') as reportTime
  282. </if>
  283. from tt_c_user
  284. where `tenant_id` = #{tenantId}
  285. <if test=" null != parentTenantId and '' != parentTenantId">
  286. and `parent_tenant_id` = #{parentTenantId}
  287. </if>
  288. <if test=" null != startTime ">
  289. and create_date &gt;= #{startTime}
  290. </if>
  291. <if test=" null != endTime">
  292. and create_date &lt; #{endTime}
  293. </if>
  294. <if test="1 == reportType or 2 == reportType or 3 == reportType">
  295. group by reportTime
  296. </if>
  297. </select>
  298. <select id="listByChannel" resultMap="BaseResultMap" >
  299. select id,user_id,nick_name,phone,create_date,scene_address
  300. from tt_c_user
  301. where `tenant_id` = #{tenantId}
  302. <if test=" null != parentTenantId and '' != parentTenantId">
  303. and `parent_tenant_id` = #{parentTenantId}
  304. </if>
  305. <if test=" null != startDate ">
  306. and create_date &gt;= #{startDate}
  307. </if>
  308. <if test=" null != endDate">
  309. and create_date &lt; #{endDate}
  310. </if>
  311. <if test=" sceneList!= null ">
  312. and scene_address in
  313. <foreach collection="sceneList" index="index" item="scene" open="(" separator="," close=")">
  314. #{scene}
  315. </foreach>
  316. </if>
  317. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  318. <if test=" null == sortColumns"> order by create_date desc </if>
  319. </select>
  320. <select id="countByChannel" resultType="java.lang.Long" >
  321. select count(id)
  322. from tt_c_user
  323. where `tenant_id` = #{tenantId}
  324. <if test=" null != parentTenantId and '' != parentTenantId">
  325. and `parent_tenant_id` = #{parentTenantId}
  326. </if>
  327. <if test=" null != startDate ">
  328. and create_date &gt;= #{startDate}
  329. </if>
  330. <if test=" null != endDate">
  331. and create_date &lt; #{endDate}
  332. </if>
  333. <if test=" sceneList!= null ">
  334. and scene_address in
  335. <foreach collection="sceneList" index="index" item="scene" open="(" separator="," close=")">
  336. #{scene}
  337. </foreach>
  338. </if>
  339. </select>
  340. <update id="updateUserId" parameterType="com.iformall.domain.po.tt.TtCUser">
  341. update tt_c_user
  342. set user_id=#{userId}
  343. where id = #{id}
  344. </update>
  345. <update id="delForUserIdOnly">
  346. update tt_c_user set update_date=now(),
  347. phone = null,
  348. pure_phone = null,
  349. user_id = null
  350. where user_id = #{userId} and tenant_id = #{tenantId} and id != #{id}
  351. </update>
  352. <select id="findTokenList" parameterType="hashmap" resultType="String" >
  353. select token from tt_c_user where user_id=#{userId} and tenant_id = #{tenantId} and id != #{id}
  354. </select>
  355. <!-- tenant_id = IF(tenant_id is null ,null,CONCAT(tenant_id,"_del")),-->
  356. <!-- parent_tenant_id = IF(parent_tenant_id is null ,null,CONCAT(parent_tenant_id,"_del")),-->
  357. <!-- open_id = IF(open_id is null ,null,CONCAT(open_id,"_del")),-->
  358. <!-- union_id = IF(union_id is null ,null,CONCAT(union_id,"_del"))-->
  359. <select id="findOpenIdList" parameterType="hashmap" resultType="String" >
  360. select open_id from tt_c_user where user_id=#{userId} and tenant_id = #{tenantId}
  361. </select>
  362. <select id="findCuserId" parameterType="hashmap" resultType="Long" >
  363. select id from tt_c_user where user_id=#{userId} and tenant_id = #{tenantId}
  364. </select>
  365. </mapper>