Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

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