Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

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