TaPersonMapper.xml 21KB

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