TaPersonMapper.xml 17KB

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