No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

385 líneas
15 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="findByOpenId" parameterType="com.iformall.domain.po.WxCUser" resultMap="BaseResultMap">
  192. select <include refid="allColumns"/> from wx_c_user
  193. where `app_id` = #{appId} and `open_id` = #{openId}
  194. </select>
  195. <select id="findByUnionId" parameterType="com.iformall.domain.po.WxCUser" resultMap="BaseResultMap">
  196. select <include refid="allColumns"/> from wx_c_user
  197. where `open_app_id` = #{openAppId} and `union_id` = #{unionId}
  198. </select>
  199. <select id="findByToken" resultMap="BaseResultMap">
  200. select <include refid="allColumns"/> from wx_c_user
  201. where `token` = #{token}
  202. </select>
  203. <select id="findCount" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  204. select count(id) from wx_c_user where 1=1
  205. <if test=" null != sex ">
  206. and gender =#{sex}
  207. </if>
  208. <if test=" null != startTime ">
  209. and create_date &gt;= #{startTime}
  210. </if>
  211. <if test=" null != endTime">
  212. and create_date &lt; #{endTime}
  213. </if>
  214. <if test=" null != tenantId and '' != tenantId">
  215. and `tenant_id` = #{tenantId}
  216. </if>
  217. <if test=" null != parentTenantId and '' != parentTenantId">
  218. and `parent_tenant_id` = #{parentTenantId}
  219. </if>
  220. </select>
  221. <select id="findCountHistory" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="com.iformall.domain.vo.UserCountVo">
  222. select count(id) as incCount,
  223. <if test="1 == reportType ">
  224. date_format(create_date, '%Y-%m-%d') as reportTime,
  225. </if>
  226. <if test="2 == reportType ">
  227. date_format(create_date, '%Y-%m') as reportTime,
  228. </if>
  229. <if test="3 == reportType ">
  230. date_format(create_date, '%Y') as reportTime,
  231. </if>
  232. <if test="1 == reportType or 2 == reportType or 3 == reportType">
  233. (select count(id) from wx_c_user where
  234. <if test="1 == reportType ">
  235. date_format(create_date, '%Y-%m-%d') &lt;= reportTime
  236. </if>
  237. <if test="2 == reportType ">
  238. date_format(create_date, '%Y-%m') &lt;= reportTime
  239. </if>
  240. <if test="3 == reportType ">
  241. date_format(create_date, '%Y') &lt;= reportTime
  242. </if>
  243. <if test=" null != tenantId and '' != tenantId">
  244. and `tenant_id` = #{tenantId}
  245. </if>
  246. <if test=" null != parentTenantId and '' != parentTenantId">
  247. and `parent_tenant_id` = #{parentTenantId}
  248. </if>
  249. ) as totalCount
  250. </if>
  251. from wx_c_user where 1=1
  252. <if test=" null != tenantId and '' != tenantId">
  253. and `tenant_id` = #{tenantId}
  254. </if>
  255. <if test=" null != parentTenantId and '' != parentTenantId">
  256. and `parent_tenant_id` = #{parentTenantId}
  257. </if>
  258. <if test=" null != startTime ">
  259. and create_date &gt;= #{startTime}
  260. </if>
  261. <if test=" null != endTime">
  262. and create_date &lt; #{endTime}
  263. </if>
  264. <if test="1 == reportType or 2 == reportType or 3 == reportType">
  265. group by reportTime
  266. </if>
  267. </select>
  268. <select id="listByChannel" resultMap="BaseResultMap" >
  269. select id,user_id,nick_name,phone,create_date,scene_address from wx_c_user where 1=1
  270. <if test=" null != tenantId and '' != tenantId">
  271. and `tenant_id` = #{tenantId}
  272. </if>
  273. <if test=" null != parentTenantId and '' != parentTenantId">
  274. and `parent_tenant_id` = #{parentTenantId}
  275. </if>
  276. <if test=" null != startDate ">
  277. and create_date &gt;= #{startDate}
  278. </if>
  279. <if test=" null != endDate">
  280. and create_date &lt; #{endDate}
  281. </if>
  282. <if test=" sceneList!= null ">
  283. and scene_address in
  284. <foreach collection="sceneList" index="index" item="scene" open="(" separator="," close=")">
  285. #{scene}
  286. </foreach>
  287. </if>
  288. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  289. <if test=" null == sortColumns"> order by create_date desc </if>
  290. </select>
  291. <select id="countByChannel" resultType="java.lang.Long" >
  292. select count(id) from wx_c_user where 1=1
  293. <if test=" null != tenantId and '' != tenantId">
  294. and `tenant_id` = #{tenantId}
  295. </if>
  296. <if test=" null != parentTenantId and '' != parentTenantId">
  297. and `parent_tenant_id` = #{parentTenantId}
  298. </if>
  299. <if test=" null != startDate ">
  300. and create_date &gt;= #{startDate}
  301. </if>
  302. <if test=" null != endDate">
  303. and create_date &lt; #{endDate}
  304. </if>
  305. <if test=" sceneList!= null ">
  306. and scene_address in
  307. <foreach collection="sceneList" index="index" item="scene" open="(" separator="," close=")">
  308. #{scene}
  309. </foreach>
  310. </if>
  311. </select>
  312. <select id="checkCountByTenantOpenId" resultType="hashmap" >
  313. 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
  314. </select>
  315. <update id="updateUserId" parameterType="com.iformall.domain.po.WxCUser">
  316. update wx_c_user set user_id=#{userId}
  317. where id = #{id}
  318. </update>
  319. <update id="delForUserIdOnly">
  320. update wx_c_user set update_date=now(),
  321. token = null,
  322. expire_time=now(),
  323. tenant_id = IF(tenant_id is null ,null,CONCAT(tenant_id,"_del")),
  324. parent_tenant_id = IF(parent_tenant_id is null ,null,CONCAT(parent_tenant_id,"_del")),
  325. open_id = IF(open_id is null ,null,CONCAT(open_id,"_del")),
  326. union_id = IF(union_id is null ,null,CONCAT(union_id,"_del"))
  327. where user_id = #{userId} and tenant_id = #{tenantId} and id != #{id}
  328. </update>
  329. </mapper>