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

541 строка
19 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.WxCUserBasicInfoMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCUserBasicInfo">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="phone" jdbcType="VARCHAR" property="phone"/>
  7. <result column="birthdate" jdbcType="TIMESTAMP" property="birthdate"/>
  8. <result column="education" jdbcType="VARCHAR" property="education"/>
  9. <result column="sex" jdbcType="INTEGER" property="sex"/>
  10. <result column="email" jdbcType="VARCHAR" property="email"/>
  11. <result column="address" jdbcType="VARCHAR" property="address"/>
  12. <result column="poins" jdbcType="INTEGER" property="poins"/>
  13. <result column="tag_id" jdbcType="BIGINT" property="tagId"/>
  14. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  15. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  16. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  17. <result column="name" jdbcType="VARCHAR" property="name"/>
  18. <result column="level" jdbcType="VARCHAR" property="level"/>
  19. <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
  20. <result column="credit" jdbcType="INTEGER" property="credit"/>
  21. <result column="active_time" jdbcType="TIMESTAMP" property="activeTime"/>
  22. <result column="act_record" jdbcType="INTEGER" property="actRecord"/>
  23. <result column="score_date" jdbcType="TIMESTAMP" property="scoreDate"/>
  24. <result column="status" jdbcType="INTEGER" property="status"/>
  25. </resultMap>
  26. <sql id="allColumns">
  27. `id`,`phone`,`birthdate`,`education`,`sex`,`email`,`address`,`poins`,`tag_id`,
  28. `create_date`,`update_date`,`tenant_id`,`name`,`nick_name`,`credit`,`active_time`,`act_record`
  29. ,(select level from wx_level_config where poins >= points and tenant_id=#{tenantId} order by points desc limit 1 ) level,status
  30. </sql>
  31. <sql id="dynamicWhereConditions">
  32. where 1 = 1
  33. <if test=" null != id ">
  34. and `id` = #{id}
  35. </if>
  36. <if test=" null != tenantId ">
  37. and `tenant_id` = #{tenantId}
  38. </if>
  39. <if test=" null != phone ">
  40. and `phone` like concat('%', #{phone},'%')
  41. </if>
  42. <if test=" null != birthdate ">
  43. and `birthdate` = #{birthdate}
  44. </if>
  45. <if test=" null != education ">
  46. and `education` like concat('%', #{education},'%')
  47. </if>
  48. <if test=" null != sex ">
  49. and `sex` = #{sex}
  50. </if>
  51. <if test=" null != email ">
  52. and `email` like concat('%', #{email},'%')
  53. </if>
  54. <if test=" null != address ">
  55. and `address` like concat('%', #{address},'%')
  56. </if>
  57. <if test=" null != poins ">
  58. and `poins` = #{poins}
  59. </if>
  60. <if test=" null != credit ">
  61. and `credit` = #{credit}
  62. </if>
  63. <if test=" null != tagId ">
  64. and `tag_id` = #{tagId}
  65. </if>
  66. <if test=" null != createDate ">
  67. and `create_date` = #{createDate}
  68. </if>
  69. <if test=" null != updateDate ">
  70. and `update_date` = #{updateDate}
  71. </if>
  72. <if test=" null != actRecord ">
  73. and `act_record` = #{actRecord}
  74. </if>
  75. <if test=" null != name ">
  76. and `name` like concat('%', #{name},'%')
  77. </if>
  78. <if test=" null != startTime and null!=endTime">
  79. and `create_date` between #{startTime} and #{endTime}
  80. </if>
  81. <if test=" null != status ">
  82. and `status` = #{status}
  83. </if>
  84. <if test=" null != ids ">
  85. and id in
  86. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  87. #{idItem}
  88. </foreach>
  89. </if>
  90. <if test=" null != sortColumns">order by ${sortColumns}</if>
  91. </sql>
  92. <select id="findList" parameterType="com.iformall.domain.po.WxCUserBasicInfo" resultMap="BaseResultMap">
  93. select r.* from (
  94. select
  95. <include refid="allColumns"/>
  96. from wx_c_user_basic_info
  97. <include refid="dynamicWhereConditions"/>
  98. ) r where 1=1
  99. <if test="null != level and '' != level">
  100. and r.level =#{level}
  101. </if>
  102. </select>
  103. <sql id="allUserColumns">
  104. c.`id`,c.`phone`,cb.`birthdate`,cb.`education`,cb.`sex`,cb.`email`,cb.`address`,cb.`poins`,cb.`tag_id`,
  105. cb.`create_date`,cb.`update_date`,c.`tenant_id`,cb.`name`,cb.level,cb.nick_name,`cb.act_record`
  106. </sql>
  107. <update id="updateScore" parameterType="com.iformall.domain.po.WxCUserBasicInfo">
  108. update wx_c_user_basic_info set poins=#{poins} where phone=#{phone} and tenant_id=#{tenantId}
  109. and id=#{id}
  110. </update>
  111. <update id="updateNewId" parameterType="com.iformall.domain.vo.CUserBaseVo">
  112. update wx_c_user_basic_info set id=#{newId} , credit=#{credit} , poins=#{poins} where tenant_id=#{tenantId}
  113. and id = #{id}
  114. </update>
  115. <select id="findCountBySex" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  116. select count(id) from wx_c_user_basic_info
  117. where sex =#{sex}
  118. <if test=" null != startTime ">
  119. and create_date &gt;= #{startTime}
  120. </if>
  121. <if test=" null != endTime">
  122. and create_date &lt;= #{endTime}
  123. </if>
  124. <if test="null != tenantId">
  125. and tenant_id =#{tenantId}
  126. </if>
  127. </select>
  128. <select id="findCountByAge" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  129. select count(id) from wx_c_user_basic_info where 1=1
  130. <if test=" null != startTime ">
  131. and create_date &gt;= #{startTime}
  132. </if>
  133. <if test=" null != endTime">
  134. and create_date &lt;= #{endTime}
  135. </if>
  136. <if test=" null != birthStartTime ">
  137. and birthdate &gt;= #{birthStartTime}
  138. </if>
  139. <if test=" null != birthEndTime">
  140. and birthdate &lt;= #{birthEndTime}
  141. </if>
  142. <if test=" null == birthStartTime and null == birthEndTime">
  143. and birthdate is null
  144. </if>
  145. <if test="null != tenantId">
  146. and tenant_id =#{tenantId}
  147. </if>
  148. </select>
  149. <select id="findCountByScore" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  150. select count(id) from wx_c_user_basic_info where 1=1
  151. <if test=" null != startTime ">
  152. and create_date &gt;= #{startTime}
  153. </if>
  154. <if test=" null != endTime">
  155. and create_date &lt;= #{endTime}
  156. </if>
  157. <if test=" null != levelStartScore ">
  158. and poins &gt;= #{levelStartScore}
  159. </if>
  160. <if test=" null != levelEndScore">
  161. and poins &lt; #{levelEndScore}
  162. </if>
  163. <if test=" null == levelStartScore and null == levelEndScore">
  164. and poins is null
  165. </if>
  166. <if test="null != tenantId">
  167. and tenant_id =#{tenantId}
  168. </if>
  169. </select>
  170. <sql id="allColumnsOfScoreList">
  171. cub.id,cub.phone,cub.birthdate,cub.education,cub.sex,cub.email,cub.address,cub.poins,cub.tag_id,
  172. cub.create_date,cub.update_date,cub.tenant_id,cub.name,cub.level,cub.nick_name,cub.score_date
  173. </sql>
  174. <select id="findListByScore" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultMap="BaseResultMap">
  175. select <include refid="allColumnsOfScoreList"/>
  176. from wx_c_user_basic_info cub
  177. inner join wx_c_user cu on cu.id = cub.id
  178. where 1=1 and cub.status=0
  179. <if test=" null != levelStartScore ">
  180. and cub.poins &gt;= #{levelStartScore}
  181. </if>
  182. <if test=" null != levelEndScore">
  183. and cub.poins &lt;= #{levelEndScore}
  184. </if>
  185. <if test=" null == levelStartScore and null == levelEndScore">
  186. and cub.poins is null
  187. </if>
  188. <if test="null != tenantId">
  189. and cub.tenant_id =#{tenantId}
  190. </if>
  191. </select>
  192. <select id="findBirthdayList" resultMap="BaseResultMap">
  193. select <include refid="allColumnsOfScoreList"/>
  194. from wx_c_user_basic_info cub
  195. inner join wx_c_user cu on cu.id = cub.id
  196. where cub.status = 0 and cu.phone is not null
  197. AND DATE_FORMAT(cub.birthdate,'%m-%d') &gt;= #{begin}
  198. AND DATE_FORMAT(cub.birthdate,'%m-%d') &lt;= #{end}
  199. <if test="null != tenantId">
  200. and cub.tenant_id = #{tenantId}
  201. </if>
  202. </select>
  203. <select id="findCount" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  204. select count(id) from wx_c_user_basic_info where 1=1
  205. <if test=" null != startTime ">
  206. and create_date &gt;= #{startTime}
  207. </if>
  208. <if test=" null != endTime">
  209. and create_date &lt; #{endTime}
  210. </if>
  211. <if test="null != tenantId">
  212. and tenant_id =#{tenantId}
  213. </if>
  214. <if test="1 == queryImport">
  215. and create_date like '%00:00:00'
  216. </if>
  217. </select>
  218. <select id="findCountHistory" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="com.iformall.domain.vo.UserCountVo">
  219. select count(id) as incCount,
  220. <if test="1 == reportType ">
  221. date_format(create_date, '%Y-%m-%d') as reportTime,
  222. </if>
  223. <if test="2 == reportType ">
  224. date_format(create_date, '%Y-%m') as reportTime,
  225. </if>
  226. <if test="3 == reportType ">
  227. date_format(create_date, '%Y') as reportTime,
  228. </if>
  229. <if test="1 == reportType or 2 == reportType or 3 == reportType">
  230. (select count(id) from wx_c_user_basic_info
  231. where
  232. <if test="1 == reportType ">
  233. date_format(create_date, '%Y-%m-%d') &lt;= reportTime
  234. </if>
  235. <if test="2 == reportType ">
  236. date_format(create_date, '%Y-%m') &lt;= reportTime
  237. </if>
  238. <if test="3 == reportType ">
  239. date_format(create_date, '%Y') &lt;= reportTime
  240. </if>
  241. <if test="null != tenantId">
  242. and tenant_id =#{tenantId}
  243. </if>
  244. ) as totalCount
  245. </if>
  246. from wx_c_user_basic_info where 1=1
  247. <if test="null != tenantId">
  248. and tenant_id =#{tenantId}
  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="1 == reportType or 2 == reportType or 3 == reportType">
  257. group by reportTime
  258. </if>
  259. </select>
  260. <resultMap id="VoBaseResultMap" type="com.iformall.domain.vo.WxCUserBasicInfoVo">
  261. <id column="id" jdbcType="BIGINT" property="id"/>
  262. <result column="phone" jdbcType="VARCHAR" property="phone"/>
  263. <result column="birthdate" jdbcType="TIMESTAMP" property="birthdate"/>
  264. <result column="education" jdbcType="VARCHAR" property="education"/>
  265. <result column="sex" jdbcType="INTEGER" property="sex"/>
  266. <result column="email" jdbcType="VARCHAR" property="email"/>
  267. <result column="address" jdbcType="VARCHAR" property="address"/>
  268. <result column="poins" jdbcType="INTEGER" property="poins"/>
  269. <result column="tag_id" jdbcType="BIGINT" property="tagId"/>
  270. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  271. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  272. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  273. <result column="name" jdbcType="VARCHAR" property="name"/>
  274. <result column="level" jdbcType="VARCHAR" property="level"/>
  275. <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
  276. <result column="credit" jdbcType="INTEGER" property="credit"/>
  277. <result column="tags" jdbcType="VARCHAR" property="tags"/>
  278. <result column="active_time" jdbcType="TIMESTAMP" property="activeTime"/>
  279. </resultMap>
  280. <sql id="allVoColumns">
  281. cu.`id`,cu.`phone`,cu.`birthdate`,cu.`education`,cu.`sex`,cu.`email`,cu.`address`,cu.`poins`,cu.`tag_id`,
  282. cu.`create_date`,cu.`update_date`,cu.`tenant_id`,cu.`name`,cu.`level`,cu.`nick_name`,
  283. cut.`tags`,cu.`credit`,cu.`active_time`,cu.`act_record`
  284. </sql>
  285. <sql id="dynamicVoWhereConditions">
  286. where 1 = 1
  287. <if test=" null != id ">
  288. and cu.`id` = #{id}
  289. </if>
  290. <if test=" null != tenantId ">
  291. and cu.`tenant_id` = #{tenantId}
  292. </if>
  293. <if test=" null != phone ">
  294. and cu.`phone` like concat('%', #{phone},'%')
  295. </if>
  296. <if test=" null != birthdate ">
  297. and cu.`birthdate` = #{birthdate}
  298. </if>
  299. <if test=" null != education ">
  300. and cu.`education` like concat('%', #{education},'%')
  301. </if>
  302. <if test=" null != sex ">
  303. and cu.`sex` = #{sex}
  304. </if>
  305. <if test=" null != email ">
  306. and cu.`email` like concat('%', #{email},'%')
  307. </if>
  308. <if test=" null != address ">
  309. and cu.`address` like concat('%', #{address},'%')
  310. </if>
  311. <if test=" null != poins ">
  312. and cu.`poins` = #{poins}
  313. </if>
  314. <if test=" null != tagId ">
  315. and cu.`tag_id` = #{tagId}
  316. </if>
  317. <if test=" null != createDate ">
  318. and cu.`create_date` = #{createDate}
  319. </if>
  320. <if test=" null != updateDate ">
  321. and cu.`update_date` = #{updateDate}
  322. </if>
  323. <if test=" null != actRecord ">
  324. and cu.`act_record` = #{actRecord}
  325. </if>
  326. <if test=" null != name ">
  327. and `name` like concat('%', #{name},'%')
  328. </if>
  329. <if test=" null != startTime and null!=endTime">
  330. and cu.`create_date` between #{startTime} and #{endTime}
  331. </if>
  332. <if test=" null != ids ">
  333. and id in
  334. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  335. #{idItem}
  336. </foreach>
  337. </if>
  338. <if test=" null != sortColumns">order by ${sortColumns}</if>
  339. </sql>
  340. <select id="findVoList" parameterType="com.iformall.domain.po.WxCUserBasicInfo" resultMap="VoBaseResultMap">
  341. select
  342. <include refid="allVoColumns"/>
  343. from wx_c_user_basic_info cu
  344. left join wx_c_user_tags cut on cut.`id` = cu.`tag_id`
  345. <include refid="dynamicVoWhereConditions"/>
  346. </select>
  347. <select id="countVoList" parameterType="com.iformall.domain.po.WxCUserBasicInfo" resultType="java.lang.Integer">
  348. select
  349. count(*)
  350. from wx_c_user_basic_info cu
  351. left join wx_c_user_tags cut on cut.`id` = cu.`tag_id`
  352. <include refid="dynamicVoWhereConditions"/>
  353. </select>
  354. <sql id="msgColumns">
  355. cu.`id`,cu.`phone`,cu.`email`
  356. </sql>
  357. <sql id="filterWhereConditions">
  358. where 1=1
  359. <if test="null != tenantId">
  360. and cu.tenant_id =#{tenantId}
  361. </if>
  362. <if test=" null != startTime ">
  363. and cu.create_date &gt;= #{startTime}
  364. </if>
  365. <if test=" null != endTime">
  366. and cu.create_date &lt;= #{endTime}
  367. </if>
  368. <if test=" null != birthStartTime ">
  369. and cu.birthdate &gt;= #{birthStartTime}
  370. </if>
  371. <if test=" null != birthEndTime">
  372. and cu.birthdate &lt; #{birthEndTime}
  373. </if>
  374. <if test=" null != loginStartTime ">
  375. and cu.active_time &gt;= #{loginStartTime}
  376. </if>
  377. <if test=" null != loginEndTime">
  378. and cu.active_time &lt;= #{loginEndTime}
  379. </if>
  380. <if test=" null != verifiedStartTime and null != verifiedEndTime ">
  381. and 0&lt;
  382. (select count(*) from wx_coupon_order co
  383. where cu.id = co.c_user_id
  384. and co.coupon_order_status = 1
  385. and co.update_date &gt;= #{verifiedStartTime}
  386. and co.update_date &lt;= #{verifiedEndTime})
  387. </if>
  388. <if test=" null != phones">
  389. and cu.phone in (${phones})
  390. </if>
  391. <if test=" null != levelStartScore and (0 != levelStartScore and '' != levelStartScore)">
  392. and cu.poins &gt;= #{levelStartScore}
  393. <if test=" null != levelEndScore">
  394. and cu.poins &lt; #{levelEndScore}
  395. </if>
  396. </if>
  397. <if test=" null != levelStartScore and (0 == levelStartScore or '' == levelStartScore)">
  398. and (cu.poins is null or
  399. (cu.poins &gt;= #{levelStartScore}
  400. <if test=" null != levelEndScore">
  401. and cu.poins &lt; #{levelEndScore}
  402. </if>
  403. ))
  404. </if>
  405. <if test=" null != tagIds ">
  406. and JSON_CONTAINS(JSON_ARRAY(cut.tags),JSON_ARRAY
  407. <foreach collection="tagIds" index="index" item="idItem" open="(" separator="," close=")">
  408. #{idItem}
  409. </foreach>
  410. )
  411. </if>
  412. <if test=" null != sortColumns">order by ${sortColumns}</if>
  413. </sql>
  414. <select id="findCountByFilter" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  415. select count(*) from wx_c_user_basic_info cu
  416. <if test=" null != tagIds ">
  417. join wx_c_user_tags cut on cut.`id` = cu.`tag_id`
  418. </if>
  419. <include refid="filterWhereConditions"/>
  420. </select>
  421. <select id="findListByFilter" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultMap="BaseResultMap">
  422. select <include refid="msgColumns"/>
  423. from wx_c_user_basic_info cu
  424. <if test=" null != tagIds ">
  425. join wx_c_user_tags cut on cut.`id` = cu.`tag_id`
  426. </if>
  427. <include refid="filterWhereConditions"/>
  428. </select>
  429. <select id="findImportUserCount" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  430. SELECT count(*) FROM wx_c_user_basic_info cubi left join wx_c_user cu on cubi.id=cu.id where cu.id is null
  431. <if test="null != tenantId">
  432. and cubi.tenant_id =#{tenantId}
  433. </if>
  434. </select>
  435. <select id="findGrowUserCount" parameterType="com.iformall.domain.dto.WxCUserBasicInfoDto" resultType="java.lang.Long">
  436. SELECT count(*) FROM wx_c_user_basic_info cubi left join wx_c_user cu on cubi.id=cu.id where cu.id is not null
  437. <if test="null != tenantId">
  438. and cubi.tenant_id =#{tenantId}
  439. </if>
  440. </select>
  441. <update id="incActRecordById" parameterType="java.lang.Long">
  442. UPDATE wx_c_user_basic_info set act_record = act_record +1 where id = #{id}
  443. </update>
  444. <select id="selectNotCUserList" resultMap="BaseResultMap">
  445. select id,credit from wx_c_user_basic_info cub where not exists (select * from wx_c_user c where c.id=cub.id) and cub.credit is null
  446. </select>
  447. </mapper>