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.
 
 
 
 
 

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