TaPersonMapper.xml 18KB

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