TaPersonMapper.xml 19KB

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