TaPersonMapper.xml 19KB

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