Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

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