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.
 
 
 
 
 

476 rivejä
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="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 msg_count &gt;= 10
  204. <if test=" null != tenantId and '' != tenantId">
  205. and `tenant_id` = #{tenantId}
  206. </if>
  207. <if test=" null != parentTenantId and '' != parentTenantId">
  208. and `parent_tenant_id` = #{parentTenantId}
  209. </if>
  210. <if test=" null != userIds ">
  211. and user_id in
  212. <foreach collection="userIds" index="index" item="userIdItem" open="(" separator="," close=")">
  213. #{userIdItem}
  214. </foreach>
  215. </if>
  216. </select>
  217. <update id="updateMsgCount" parameterType="com.iformall.domain.po.WxCUser">
  218. update wx_c_user
  219. set msg_count = msg_count+2
  220. where msg_count &lt; 10
  221. <if test=" null != id ">
  222. and `id` = #{id}
  223. </if>
  224. <if test=" null != openId ">
  225. and `open_id` = #{openId}
  226. </if>
  227. <if test=" null != tenantId and '' != tenantId">
  228. and `tenant_id` = #{tenantId}
  229. </if>
  230. <if test=" null != parentTenantId and '' != parentTenantId">
  231. and `parent_tenant_id` = #{parentTenantId}
  232. </if>
  233. </update>
  234. <!-- <update id="updateMsgCountDown">-->
  235. <!-- update wx_c_user set msg_count = msg_count-1-->
  236. <!-- where msg_count &gt; 0-->
  237. <!-- <if test=" null != tenantId and '' != tenantId">-->
  238. <!-- and `tenant_id` = #{tenantId}-->
  239. <!-- </if>-->
  240. <!-- and `open_id` = #{openId}-->
  241. <!-- </update>-->
  242. <select id="findByOpenId" parameterType="com.iformall.domain.po.WxCUser" resultMap="BaseResultMap">
  243. select <include refid="allColumns"/>
  244. from wx_c_user
  245. where `open_id` = #{openId}
  246. <if test=" null != appId and '' != appId">
  247. and `app_id` = #{appId}
  248. </if>
  249. </select>
  250. <select id="findByUnionId" parameterType="com.iformall.domain.po.WxCUser" resultMap="BaseResultMap">
  251. select <include refid="allColumns"/>
  252. from wx_c_user
  253. where `open_app_id` = #{openAppId}
  254. and `union_id` = #{unionId}
  255. </select>
  256. <select id="findByToken" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  257. select <include refid="allColumns"/>
  258. from wx_c_user
  259. where `token` = #{token}
  260. and `tenant_id` = #{tenantId}
  261. </select>
  262. <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  263. select <include refid="allColumns"/>
  264. from wx_c_user
  265. where id = #{id}
  266. and `tenant_id` = #{tenantId}
  267. </select>
  268. <select id="findCount" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  269. select count(id)
  270. from wx_c_user
  271. where `tenant_id` = #{tenantId}
  272. <if test=" null != parentTenantId and '' != parentTenantId">
  273. and `parent_tenant_id` = #{parentTenantId}
  274. </if>
  275. <if test=" null != sex ">
  276. and gender =#{sex}
  277. </if>
  278. <if test=" null != startTime ">
  279. and create_date &gt;= #{startTime}
  280. </if>
  281. <if test=" null != endTime">
  282. and create_date &lt; #{endTime}
  283. </if>
  284. </select>
  285. <select id="findCountData" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="com.iformall.domain.vo.UserStructureVo">
  286. select DATE_FORMAT(create_date,'%m/%d') as name,count(id) count
  287. from wx_c_user
  288. where `tenant_id` = #{tenantId}
  289. <if test=" null != parentTenantId and '' != parentTenantId">
  290. and `parent_tenant_id` = #{parentTenantId}
  291. </if>
  292. <if test=" null != sex ">
  293. and gender =#{sex}
  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. group by name
  302. </select>
  303. <select id="findCountHistory" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="com.iformall.domain.vo.UserCountVo">
  304. select count(id) as incCount,
  305. <if test="1 == reportType ">
  306. date_format(create_date, '%Y-%m-%d') as reportTime
  307. </if>
  308. <if test="2 == reportType ">
  309. date_format(create_date, '%Y-%m') as reportTime
  310. </if>
  311. <if test="3 == reportType ">
  312. date_format(create_date, '%Y') as reportTime
  313. </if>
  314. from wx_c_user
  315. where `tenant_id` = #{tenantId}
  316. <if test=" null != parentTenantId and '' != parentTenantId">
  317. and `parent_tenant_id` = #{parentTenantId}
  318. </if>
  319. <if test=" null != startTime ">
  320. and create_date &gt;= #{startTime}
  321. </if>
  322. <if test=" null != endTime">
  323. and create_date &lt; #{endTime}
  324. </if>
  325. <if test="1 == reportType or 2 == reportType or 3 == reportType">
  326. group by reportTime
  327. </if>
  328. </select>
  329. <select id="listByChannel" resultMap="BaseResultMap" >
  330. select id,user_id,nick_name,phone,create_date,scene_address
  331. from wx_c_user
  332. where `tenant_id` = #{tenantId}
  333. <if test=" null != parentTenantId and '' != parentTenantId">
  334. and `parent_tenant_id` = #{parentTenantId}
  335. </if>
  336. <if test=" null != startDate ">
  337. and create_date &gt;= #{startDate}
  338. </if>
  339. <if test=" null != endDate">
  340. and create_date &lt; #{endDate}
  341. </if>
  342. <if test=" sceneList!= null ">
  343. and scene_address in
  344. <foreach collection="sceneList" index="index" item="scene" open="(" separator="," close=")">
  345. #{scene}
  346. </foreach>
  347. </if>
  348. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  349. <if test=" null == sortColumns"> order by create_date desc </if>
  350. </select>
  351. <select id="countByChannel" resultType="java.lang.Long" >
  352. select count(id)
  353. from wx_c_user
  354. where `tenant_id` = #{tenantId}
  355. <if test=" null != parentTenantId and '' != parentTenantId">
  356. and `parent_tenant_id` = #{parentTenantId}
  357. </if>
  358. <if test=" null != startDate ">
  359. and create_date &gt;= #{startDate}
  360. </if>
  361. <if test=" null != endDate">
  362. and create_date &lt; #{endDate}
  363. </if>
  364. <if test=" sceneList!= null ">
  365. and scene_address in
  366. <foreach collection="sceneList" index="index" item="scene" open="(" separator="," close=")">
  367. #{scene}
  368. </foreach>
  369. </if>
  370. </select>
  371. <update id="updateUserId" parameterType="com.iformall.domain.po.WxCUser">
  372. update wx_c_user
  373. set user_id=#{userId}
  374. where id = #{id}
  375. </update>
  376. <update id="delForUserIdOnly">
  377. update wx_c_user set update_date=now(),
  378. phone = null,
  379. pure_phone = null,
  380. user_id = null
  381. where user_id = #{userId} and tenant_id = #{tenantId} and id != #{id}
  382. </update>
  383. <select id="findTokenList" parameterType="hashmap" resultType="String" >
  384. select token from wx_c_user where user_id=#{userId} and tenant_id = #{tenantId} and id != #{id}
  385. </select>
  386. <!-- tenant_id = IF(tenant_id is null ,null,CONCAT(tenant_id,"_del")),-->
  387. <!-- parent_tenant_id = IF(parent_tenant_id is null ,null,CONCAT(parent_tenant_id,"_del")),-->
  388. <!-- open_id = IF(open_id is null ,null,CONCAT(open_id,"_del")),-->
  389. <!-- union_id = IF(union_id is null ,null,CONCAT(union_id,"_del"))-->
  390. <select id="findOpenId" parameterType="hashmap" resultType="String" >
  391. select open_id from wx_c_user where user_id=#{userId} and tenant_id = #{tenantId}
  392. </select>
  393. <select id="findCuserId" parameterType="hashmap" resultType="Long" >
  394. select id from wx_c_user where user_id=#{userId} and tenant_id = #{tenantId}
  395. </select>
  396. <update id="updateAuthorizeStateByOpenId" parameterType="com.iformall.domain.po.WxCUser">
  397. update wx_c_user
  398. set `authorize_state` = #{authorizeState}
  399. <if test=" null != authorizeTime">
  400. ,`authorize_time` = #{authorizeTime}
  401. </if>
  402. <if test=" null != deauthorizeTime">
  403. ,`deauthorize_time` = #{deauthorizeTime}
  404. </if>
  405. WHERE `tenant_id` = #{tenantId}
  406. and `open_id` = #{openId}
  407. and `authorize_state` != #{authorizeState}
  408. </update>
  409. </mapper>