TaPersonMapper.xml 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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.huiju.estateagents.mapper.TaPersonMapper">
  4. <select id="selectCardList" resultType="java.util.HashMap">
  5. SELECT
  6. t.person_id AS id,
  7. t.name,
  8. t.company,
  9. t.department,
  10. t.post,
  11. t.tel AS phone,
  12. t.avatarurl AS avatar,
  13. t.photo,
  14. u.description as description
  15. FROM
  16. ta_person t left join ta_user u on t.user_id = u.user_id
  17. LEFT JOIN ta_person_building p ON u.user_id = p.user_id
  18. WHERE
  19. t.person_type = #{personType}
  20. AND t.status = #{status}
  21. and u.status != 9
  22. and t.org_id = #{orgId}
  23. <if test="buildingId != null and buildingId != ''">
  24. and p.building_id = #{buildingId}
  25. </if>
  26. ORDER BY
  27. t.create_date DESC
  28. </select>
  29. <select id="selectBuildingConsultants" resultType="java.util.HashMap">
  30. SELECT
  31. t.person_id AS id,
  32. u.user_name,
  33. u.org_name,
  34. u.department,
  35. u.position,
  36. u.phone,
  37. u.avatar,
  38. u.photo,
  39. u.description
  40. FROM
  41. ta_person t
  42. JOIN ta_person_building s USING (user_id)
  43. left join ta_user u on t.user_id = u.user_id
  44. WHERE
  45. s.building_id = #{buildingId}
  46. AND t.person_type = #{personType}
  47. AND t. STATUS = #{status}
  48. ORDER BY
  49. t.create_date DESC
  50. </select>
  51. <select id="getSalesExecutive" resultType="com.huiju.estateagents.entity.TaPerson">
  52. SELECT
  53. *
  54. FROM
  55. ta_person t
  56. WHERE
  57. t.person_type = 'Sales Executive'
  58. AND t.status = 1
  59. LIMIT 1
  60. </select>
  61. <select id="getPersonByOpenId" resultType="com.huiju.estateagents.entity.TaPerson">
  62. SELECT
  63. *
  64. FROM
  65. ta_person t
  66. WHERE
  67. t.mini_openid = #{openId}
  68. AND IFNULL(t.status, 0) &gt; -1
  69. </select>
  70. <update id="setFieldIncrement">
  71. UPDATE ta_person
  72. SET ${field} = IFNULL(${field}, 0) + #{increment}
  73. WHERE person_id = #{personId}
  74. </update>
  75. <select id="selectCustomer" resultType="com.huiju.estateagents.entity.TaPerson">
  76. SELECT
  77. a.*,
  78. b.event as event,
  79. b.activity as activity,
  80. b.data as data,
  81. (select b.visit_time FROM ta_person_visit_record b where a.person_id = b.person_id ORDER BY b.visit_time desc LIMIT 1) as visitTime
  82. FROM
  83. ta_person a
  84. LEFT JOIN ta_person_visit_record b ON a.person_id = b.person_id
  85. WHERE
  86. a.person_type IS NULL
  87. ORDER BY create_date desc
  88. </select>
  89. <select id="getById" resultType="com.huiju.estateagents.entity.TaPerson">
  90. SELECT
  91. a.*
  92. FROM
  93. ta_person a
  94. WHERE
  95. a.person_id = #{personId}
  96. </select>
  97. <select id="getUserProjects" resultType="java.lang.String">
  98. SELECT
  99. b.building_name
  100. FROM
  101. ta_person_building a
  102. LEFT JOIN ta_building b ON a.building_id = b.building_id
  103. WHERE a.person_id = #{personId}
  104. </select>
  105. <select id="selectByIdPerson" resultType="com.huiju.estateagents.entity.TaPerson">
  106. select * from ta_person where mini_openid = #{openid};
  107. </select>
  108. <select id="getConsultantByName" resultType="java.lang.String">
  109. select person_id from ta_person where name like CONCAT('%',#{name}, '%')
  110. </select>
  111. <select id="getConsultantByTel" resultType="java.lang.String">
  112. select person_id from ta_person where tel = #{tel}
  113. </select>
  114. <select id="selectCardListofMine" resultType="java.util.HashMap">
  115. SELECT
  116. t.person_id AS id,
  117. t.name,
  118. t.company,
  119. t.department,
  120. t.post,
  121. t.tel AS phone,
  122. t.avatarurl AS avatar,
  123. t.photo,
  124. u.description as description
  125. FROM
  126. ta_person t left join ta_user u on t.user_id = u.user_id
  127. WHERE
  128. t.person_type = #{personType}
  129. AND t.status = #{status}
  130. <if test="personIds != null">
  131. and t.person_id in
  132. <foreach collection="personIds" item="item" index="index" open="(" close=")" separator=",">
  133. #{item}
  134. </foreach>
  135. </if>
  136. ORDER BY
  137. t.create_date DESC
  138. </select>
  139. <select id="selectRecentlyCount" resultType="integer" >
  140. SELECT
  141. COUNT(1) as activity_count
  142. FROM
  143. ta_person tp
  144. where tp.org_id = #{org} AND
  145. tp.person_type IN ('customer','drift','estate agent')
  146. <if test="startDate != null or endDate != null">
  147. AND tp.create_date BETWEEN #{startDate} and #{endDate}
  148. </if>
  149. <if test="startDate == null or endDate == null">
  150. AND tp.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  151. </if>
  152. </select>
  153. <select id="selectUserBehavior" resultType="com.huiju.estateagents.po.PersonPO">
  154. SELECT
  155. temp_date.date as date,
  156. temp_date.type_name as activity,
  157. temp.activityCount as activityCount
  158. FROM
  159. (
  160. SELECT
  161. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date, b.type_id, b.type_name
  162. from sequence a, td_biz_event_type b
  163. <trim prefix="where">
  164. <if test="startDate != null or endDate != null">
  165. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  166. </if>
  167. </trim>
  168. ) AS temp_date
  169. LEFT JOIN (
  170. SELECT
  171. COUNT(1) as activityCount,
  172. tpvr.event_type,
  173. DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' ) as date
  174. FROM
  175. ta_person tp
  176. INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
  177. where tp.org_id = #{org} AND tp.person_type IN ('customer','drift','estate agent')
  178. <if test="buildingId != null and buildingId != ''">
  179. and tpvr.building_id = #{buildingId}
  180. </if>
  181. <if test="eventType != null and eventType != ''">
  182. and tpvr.event_type = #{eventType}
  183. </if>
  184. <if test="event != null and event != ''">
  185. and tpvr.event = #{event}
  186. </if>
  187. <if test="activity != null and activity != ''">
  188. and tpvr.activity = #{activity}
  189. </if>
  190. GROUP BY tpvr.event_type, DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' )
  191. ) AS temp ON temp_date.date = temp.date and temp_date.type_id = temp.event_type
  192. order by temp_date.date asc
  193. </select>
  194. <select id="selectActiveUserCount" resultType="map">
  195. SELECT
  196. temp_date.date as date,
  197. sum(temp.activity_count) as activity_count,
  198. temp.visit_time as visit_time
  199. FROM
  200. (
  201. SELECT
  202. <if test="dateType == 'day'.toString()">
  203. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  204. </if>
  205. <if test="dateType == 'week'.toString()">
  206. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum WEEK ), '%Y-%m-%d' ) AS date
  207. </if>
  208. <if test="dateType == 'month'.toString()">
  209. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum MONTH ), '%Y-%m' ) AS date
  210. </if>
  211. FROM
  212. sequence a
  213. <trim prefix="where">
  214. <if test="startDate != null or endDate != null">
  215. a.rownum <![CDATA[ < ]]> datediff(#{endDate}, #{startDate})
  216. </if>
  217. <if test="startDate == null or endDate == null">
  218. a.rownum <![CDATA[ < ]]> 7
  219. </if>
  220. </trim>
  221. ) AS temp_date
  222. LEFT JOIN (
  223. SELECT
  224. COUNT(1) as activity_count,
  225. tpvr.max_visit_time AS visit_time
  226. FROM
  227. ta_person tp
  228. LEFT JOIN
  229. ( SELECT *, MAX(visit_time) as max_visit_time FROM ta_person_visit_record GROUP BY person_id ) as tpvr
  230. ON tp.person_id = tpvr.person_id
  231. where tp.org_id = #{org} AND tp.person_type IN ('customer','drift','estate agent')
  232. GROUP BY DATE_FORMAT( tpvr.max_visit_time , '%Y-%m-%d' )
  233. ) AS temp ON
  234. <if test="dateType == 'month'.toString()">
  235. temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m' ) GROUP BY temp_date.date ORDER BY temp_date.date
  236. </if>
  237. <if test="dateType == 'day'.toString()">
  238. temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' ) GROUP BY temp_date.date ORDER BY temp_date.date
  239. </if>
  240. </select>
  241. <select id="selectNewsUserCount" resultType="map">
  242. SELECT
  243. authorization_count_table.date as date,
  244. ifnull(authorization_count_table.authorization_count, 0) as authorization_count,
  245. ifnull(user_count_table.user_count, 0) as user_count
  246. FROM
  247. (
  248. SELECT
  249. *
  250. FROM
  251. (
  252. SELECT
  253. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  254. FROM
  255. sequence a
  256. <trim prefix="where">
  257. <if test="startDate != null or endDate != null">
  258. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  259. </if>
  260. </trim>
  261. ) AS temp_date
  262. LEFT JOIN (
  263. SELECT
  264. COUNT(1) as authorization_count,
  265. tp.create_date as create_date
  266. FROM
  267. ta_person tp
  268. where tp.person_type IN ('customer','drift','estate agent') and tp.org_id = #{orgId}
  269. and tp.phone is NOT NULL
  270. <if test="startDate != null or endDate != null">
  271. AND tp.create_date BETWEEN #{startDate} and #{endDate}
  272. </if>
  273. <if test="startDate == null or endDate == null">
  274. AND tp.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  275. </if>
  276. GROUP BY DATE_FORMAT( tp.create_date , '%Y-%m-%d' )
  277. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
  278. ) as authorization_count_table
  279. ,
  280. (
  281. SELECT
  282. *
  283. FROM
  284. (
  285. SELECT
  286. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
  287. FROM
  288. sequence a
  289. <trim prefix="where">
  290. <if test="startDate != null or endDate != null">
  291. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  292. </if>
  293. </trim>
  294. ) AS temp_date
  295. LEFT JOIN (
  296. SELECT
  297. COUNT(1) as user_count,
  298. tp.create_date as create_date
  299. FROM
  300. ta_person tp
  301. where tp.person_type IN ('customer','drift','estate agent') and tp.org_id = #{orgId}
  302. <if test="startDate != null or endDate != null">
  303. AND tp.create_date BETWEEN #{startDate} and #{endDate}
  304. </if>
  305. <if test="startDate == null or endDate == null">
  306. AND tp.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
  307. </if>
  308. GROUP BY DATE_FORMAT( tp.create_date , '%Y-%m-%d' )
  309. ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
  310. ) as user_count_table
  311. where
  312. user_count_table.date = authorization_count_table.date
  313. GROUP BY date
  314. </select>
  315. <select id="selectUserSourcePie" resultType="integer">
  316. select count(1)
  317. FROM ta_person
  318. WHERE org_id = #{org} AND person_type IN ('customer','drift','estate agent')
  319. <if test="recommendPersonType != null and recommendPersonType != ''">
  320. and recommend_person_type = #{recommendPersonType}
  321. </if>
  322. </select>
  323. <select id="selectUserSourceColumnar" resultType="map">
  324. SELECT
  325. tpf.from_name as from_name,
  326. (
  327. SELECT
  328. COUNT(1)
  329. FROM ta_person tps
  330. LEFT JOIN td_person_from tpfs
  331. ON tps.from_code = tpfs.from_code
  332. WHERE tpfs.from_code = tpf.from_code and tps.phone is NOT NULL
  333. AND tps.org_id = #{org}
  334. and tps.person_type IN ('customer','drift','estate agent')
  335. <if test="startDate != null or endDate != null">
  336. and tps.create_date BETWEEN #{startDate} and #{endDate}
  337. </if>
  338. <if test="startDate == null or endDate == null">
  339. and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
  340. </if>
  341. ) as registered,
  342. (
  343. SELECT
  344. COUNT(1)
  345. FROM ta_person tps
  346. LEFT JOIN td_person_from tpfs
  347. ON tps.from_code = tpfs.from_code
  348. WHERE tpfs.from_code = tpf.from_code
  349. AND tps.org_id = #{org}
  350. and tps.person_type IN ('customer','drift','estate agent')
  351. <if test="startDate != null or endDate != null">
  352. and tps.create_date BETWEEN #{startDate} and #{endDate}
  353. </if>
  354. <if test="startDate == null or endDate == null">
  355. and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
  356. </if>
  357. ) as user_count
  358. FROM td_person_from tpf
  359. LEFT JOIN ta_person tp
  360. ON tp.from_code = tpf.from_code
  361. where tp.org_id = #{org} AND tp.person_type IN ('customer','drift','estate agent')
  362. GROUP BY tpf.from_code
  363. </select>
  364. <select id="selectUserSourceData" resultType="map">
  365. select
  366. temp_date.date AS date,
  367. temp_date.from_name as from_name,
  368. temp_date.from_code as from_code,
  369. IFNULL(user_count.count, 0) as count,
  370. IFNULL(registered_count.count,0) as registered,
  371. user_count.create_date as create_date
  372. FROM
  373. (
  374. SELECT
  375. DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date,
  376. tempf.from_name as from_name,
  377. tempf.from_code as from_code
  378. FROM
  379. sequence a
  380. ,
  381. td_person_from tempf
  382. <trim prefix="where">
  383. <if test="startDate != null or endDate != null">
  384. a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
  385. </if>
  386. </trim>
  387. ) AS temp_date
  388. LEFT JOIN
  389. (
  390. SELECT
  391. ifnull(COUNT(1), 0) as count,
  392. tps.create_date as create_date,
  393. tpfs.from_code as from_code,
  394. tpfs.from_name as from_name
  395. FROM ta_person tps
  396. LEFT JOIN td_person_from tpfs
  397. ON tps.from_code = tpfs.from_code
  398. WHERE tpfs.from_code = tps.from_code
  399. AND tps.org_id = #{org}
  400. and tps.person_type IN ('customer','drift','estate agent')
  401. AND tps.create_date BETWEEN #{startDate} AND #{endDate}
  402. GROUP BY tpfs.from_code
  403. ) as user_count
  404. ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date and temp_date.from_code = user_count.from_code
  405. LEFT JOIN
  406. (
  407. SELECT
  408. ifnull(COUNT(1), 0) as count,
  409. tps.create_date as create_date,
  410. tpfs.from_code as from_code,
  411. tpfs.from_name as from_name
  412. FROM ta_person tps
  413. LEFT JOIN td_person_from tpfs
  414. ON tps.from_code = tpfs.from_code
  415. WHERE tpfs.from_code = tps.from_code
  416. AND tps.org_id = #{org}
  417. and tps.person_type IN ('customer','drift','estate agent')
  418. AND tps.create_date BETWEEN #{startDate} AND #{endDate}
  419. and tps.phone is not null
  420. GROUP BY tpfs.from_code
  421. ) as registered_count
  422. ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date and temp_date.from_code = registered_count.from_code
  423. order by temp_date.date DESC
  424. </select>
  425. <select id="getPersonList" resultType="com.huiju.estateagents.entity.TaPerson">
  426. SELECT
  427. a.*
  428. FROM
  429. ta_person a
  430. LEFT JOIN ta_person_building b ON a.person_id = b.person_id
  431. <where>
  432. 1=1
  433. <if test="personType != null and personType!= ''">
  434. and a.person_type = #{personType}
  435. </if>
  436. <if test="name != null and name!= ''">
  437. and a.name like CONCAT('%',#{name}, '%')
  438. </if>
  439. <if test="personTags != null and personTags!= ''">
  440. and a.person_tags like CONCAT('%',#{personTags}, '%')
  441. </if>
  442. <if test="phone != null and phone!= ''">
  443. and a.tel = #{phone}
  444. </if>
  445. <if test="buildingId != null and buildingId!= ''">
  446. and b.building_id = #{buildingId}
  447. </if>
  448. <if test="status != null">
  449. and a.status = #{status}
  450. </if>
  451. </where>
  452. GROUP BY a.person_id
  453. </select>
  454. <select id="channelBrokerList" resultType="com.huiju.estateagents.entity.TaPerson">
  455. select
  456. p.*,
  457. COUNT(rc.person_id) AS recommendCount
  458. from ta_channel_person tch
  459. left join ta_person p on tch.person_id = p.person_id
  460. LEFT JOIN ta_recommend_customer rc ON p.person_id = rc.person_id
  461. <where>
  462. <if test="name !=null and name !=''">
  463. and rc.name like CONCAT('%',#{name}, '%')
  464. </if>
  465. <if test="phone !=null and phone !=''">
  466. and rc.phone like CONCAT('%',#{phone}, '%')
  467. </if>
  468. and p.org_id= #{orgid}
  469. and tch.channel_id = #{channelId}
  470. </where>
  471. GROUP BY tch.person_id
  472. </select>
  473. <select id="InviteClientsList" resultType="com.huiju.estateagents.entity.TaPerson">
  474. select * from ta_person WHERE recommend_agent = #{id}
  475. </select>
  476. <update id="upDatePersonCityToId">
  477. UPDATE ta_person a
  478. INNER JOIN (
  479. SELECT
  480. t.*, s.pinyin AS province
  481. FROM
  482. td_city t
  483. INNER JOIN td_city s ON t.parentid = s.id
  484. ) b ON a.city = b.pinyin
  485. AND a.province = b.province
  486. set a.city = b.id
  487. where a.city IS NOT NULL
  488. and (a.city REGEXP '[^0-9.]')=1
  489. and a.person_id = #{personId}
  490. </update>
  491. </mapper>