25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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