TaRecommendCustomerMapper.xml 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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.TaRecommendCustomerMapper">
  4. <select id="getMyCutsomerNum" resultType="int">
  5. SELECT
  6. count(*) AS total
  7. FROM
  8. ta_recommend_customer t
  9. WHERE
  10. t.recommend_person = #{personId}
  11. AND t.status &gt; -1
  12. </select>
  13. <select id="getCustomerPersonId" resultType="java.lang.String">
  14. SELECT
  15. person_id
  16. FROM
  17. ta_customer_person
  18. WHERE
  19. customer_id = #{customerId}
  20. </select>
  21. <select id="getCustomerDetail" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  22. SELECT
  23. a.*,
  24. (select c.visit_time FROM ta_person_visit_record c where c.person_id = #{personId} ORDER BY c.visit_time asc LIMIT 1) as visitTime,
  25. (SELECT SUM(d.visit_duration) FROM ta_person_visit_record d WHERE d.person_id= #{personId}) as duration
  26. FROM
  27. ta_recommend_customer a
  28. LEFT JOIN ta_person_visit_record c ON a.person_id = c.person_id
  29. where a.customer_id = #{customerId}
  30. GROUP BY a.customer_id
  31. </select>
  32. <select id="getRecCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  33. SELECT
  34. a.*,
  35. a.customer_id as customerId,
  36. c.phone as recommendTel,
  37. c.nickname as recommendName
  38. FROM
  39. ta_recommend_customer a
  40. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  41. <where>
  42. a.status > 0
  43. and a.report_recommend_status = 2
  44. <if test="orgId != null">
  45. and a.org_id = #{orgId}
  46. </if>
  47. <if test="building != null and building !=''">
  48. and a.building_id = #{building}
  49. </if>
  50. <if test="name != null and name !=''">
  51. and a.name like CONCAT('%',#{name}, '%')
  52. </if>
  53. <if test="tel != null and tel!=''">
  54. and a.phone like CONCAT('%',#{tel}, '%')
  55. </if>
  56. <if test="consultName != null and consultName !=''">
  57. and c.nickname like CONCAT('%',#{consultName}, '%')
  58. </if>
  59. <if test="consultTel != null and consultTel !=''">
  60. and c.phone like CONCAT('%',#{consultTel}, '%')
  61. </if>
  62. <if test="entryType != null and entryType !=''">
  63. and a.entry_type = #{entryType}
  64. </if>
  65. <if test="verifyStatus != null and verifyStatus !=''">
  66. and a.verify_status = #{verifyStatus}
  67. </if>
  68. <if test="sex != null and sex !=''">
  69. and a.sex = #{sex}
  70. </if>
  71. <if test="personBuildingList != null and personBuildingList.size > 0">
  72. AND a.building_id in
  73. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  74. #{personBuilding.buildingId}
  75. </foreach>
  76. </if>
  77. </where>
  78. order by a.create_date desc
  79. </select>
  80. <select id="getIndependentAgents" resultType="com.huiju.estateagents.entity.TaPerson">
  81. SELECT
  82. a.*,
  83. tc.channel_name as channelName
  84. FROM
  85. ta_person a
  86. left join ta_channel_person tcp on a.person_id = tcp.person_id
  87. left join ta_channel tc on tc.channel_id = tcp.channel_id
  88. <where>
  89. a.person_type in ('estate agent', 'channel agent')
  90. and a.status >0
  91. <if test="name != null and name !=''">
  92. and a.nickname = #{name}
  93. </if>
  94. <if test="tel != null and tel!=''">
  95. and a.phone = #{tel}
  96. </if>
  97. <if test="orgId != null">
  98. and a.org_id = #{orgId}
  99. </if>
  100. </where>
  101. ORDER BY
  102. create_date DESC
  103. </select>
  104. <select id="getRepCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  105. SELECT
  106. a.*,
  107. a.customer_id AS customerId,
  108. b.NAME AS consultantName,
  109. b.tel AS consultTel,
  110. c.building_name as intentionName
  111. FROM
  112. ta_recommend_customer a
  113. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  114. LEFT JOIN ta_building c ON a.building_id = c.building_id
  115. <where>
  116. a.status > 0
  117. and a.report_recommend_status = 1
  118. <if test="orgId != null">
  119. and a.org_id = #{orgId}
  120. </if>
  121. <if test="building != null and building !=''">
  122. and a.building_id = #{building}
  123. </if>
  124. <if test="name != null and name !=''">
  125. and a.name = #{name}
  126. </if>
  127. <if test="tel != null and tel!=''">
  128. and a.phone like concat(concat("%",#{tel}),"%")
  129. </if>
  130. <if test="consultName != null and consultName !=''">
  131. and b.name like CONCAT('%',#{consultName}, '%')
  132. </if>
  133. <if test="consultTel != null and consultTel !=''">
  134. and b.tel = #{consultTel}
  135. </if>
  136. <if test="entryType != null and entryType !=''">
  137. and a.entry_type = #{entryType}
  138. </if>
  139. <if test="verifyStatus != null and verifyStatus !=''">
  140. and a.verify_status = #{verifyStatus}
  141. </if>
  142. <if test="sex != null">
  143. and a.sex = #{sex}
  144. </if>
  145. <if test="personBuildingList != null and personBuildingList.size > 0">
  146. AND a.building_id in
  147. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  148. #{personBuilding.buildingId}
  149. </foreach>
  150. </if>
  151. </where>
  152. order by a.create_date desc
  153. </select>
  154. <select id="getCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  155. SELECT
  156. a.*,
  157. a.customer_id as customerId,
  158. IFNULL(b.name,d.user_name) as consultantName,
  159. IFNULL(b.tel,d.phone) as consultTel,
  160. c.nickname as recommendName,
  161. c.tel as recommendTel,
  162. IFNULL(c.name,c.nickname) AS sharePersonName
  163. FROM
  164. ta_recommend_customer a
  165. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  166. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  167. LEFT JOIN ta_user d on d.user_id = a.realty_consultant
  168. LEFT JOIN ta_person_from_record p ON a.person_id = p.person_id AND p.is_first_time = 1
  169. <if test="orgId != null">
  170. and p.org_id = #{orgId}
  171. </if>
  172. LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
  173. <where>
  174. a.status > 0
  175. and a.verify_status = 1
  176. and a.realty_consultant is not null
  177. and a.realty_consultant != ''
  178. <if test="orgId != null">
  179. and a.org_id = #{orgId}
  180. </if>
  181. <if test="building != null and building !=''">
  182. and a.building_id = #{building}
  183. </if>
  184. <if test="name != null and name !=''">
  185. and a.name like CONCAT('%',#{name}, '%')
  186. </if>
  187. <if test="tel != null and tel!=''">
  188. and a.phone like CONCAT('%',#{tel}, '%')
  189. </if>
  190. <if test="consultName != null and consultName !=''">
  191. and IFNULL(b.name,d.user_name) like CONCAT('%',#{consultName}, '%')
  192. </if>
  193. <if test="consultTel != null and consultTel !=''">
  194. and IFNULL(b.tel,d.phone) like CONCAT('%',#{consultTel}, '%')
  195. </if>
  196. <if test="entryType != null and entryType !=''">
  197. and a.entry_type = #{entryType}
  198. </if>
  199. <if test="verifyStatus != null and verifyStatus !=''">
  200. and a.verify_status = #{verifyStatus}
  201. </if>
  202. <if test="status != null and status !=''">
  203. and a.status = #{status}
  204. </if>
  205. <if test="sex != null and sex !=''">
  206. and a.sex = #{sex}
  207. </if>
  208. <if test="personBuildingList != null and personBuildingList.size > 0">
  209. AND a.building_id in
  210. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  211. #{personBuilding.buildingId}
  212. </foreach>
  213. </if>
  214. <if test="sceneType !=null and sceneType !=''">
  215. and p.scene_type = #{sceneType}
  216. </if>
  217. </where>
  218. order by a.create_date desc
  219. </select>
  220. <select id="getCustomerById" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  221. SELECT
  222. a.*,
  223. b.name as consultantName
  224. FROM
  225. ta_recommend_customer a
  226. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  227. WHERE a.customer_id = #{customerId}
  228. </select>
  229. <select id="getPublicCustomerList" resultType="com.huiju.estateagents.entity.TaPerson">
  230. SELECT
  231. b.*,
  232. (
  233. SELECT
  234. IF
  235. ( ifnull( tpp.NAME, '' ) != '', tpp.NAME, tpp.nickname )
  236. FROM
  237. ta_share_person_from tspf
  238. LEFT JOIN ta_person tpp ON tspf.share_person = tpp.person_id
  239. WHERE
  240. tspf.is_first_time = 1
  241. AND b.person_id = tspf.person_id
  242. ORDER BY
  243. tspf.create_date ASC
  244. LIMIT 1
  245. ) AS sharePersonName
  246. FROM
  247. ta_person b
  248. LEFT JOIN ta_person_from_record r ON b.person_id = r.person_id AND r.is_first_time = 1 and r.org_id = #{orgId}
  249. left join td_wx_dict d on r.scene_id = d.scene_id
  250. <where>
  251. b.status > 0
  252. and b.org_id = #{orgId}
  253. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  254. AND b.person_id not IN ( SELECT c.person_id FROM ta_recommend_customer c WHERE c.org_id = #{orgId} AND person_id is not null AND person_id != '' )
  255. <if test="name != null and name !=''">
  256. and b.nickname like CONCAT('%',#{name}, '%')
  257. </if>
  258. <if test="sceneType !=null and sceneType !=''">
  259. and d.scene_type = #{sceneType}
  260. </if>
  261. <if test="tel != null and tel!=''">
  262. and b.phone like CONCAT('%',#{tel}, '%')
  263. </if>
  264. <if test="entryType != null and entryType !=''">
  265. and b.entry_type = #{entryType}
  266. </if>
  267. <if test="sex != null and sex !=''">
  268. and b.sex = #{sex}
  269. </if>
  270. <if test="consultTel != null and consultTel !=''">
  271. and b.tel like CONCAT('%',#{consultTel}, '%')
  272. </if>
  273. and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
  274. </where>
  275. order by b.create_date desc
  276. </select>
  277. <select id="getRecCustomerExport" resultType="com.huiju.estateagents.excel.ExcelRecommendCustomer">
  278. SELECT
  279. a.name as name,
  280. a.phone as phone,
  281. a.intention as intention,
  282. a.create_date as createDate,
  283. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  284. c.nickname as recommend,
  285. c.phone as recommendTel,
  286. if(a.verify_status = 0, '待审核', if(a.verify_status = 1, '已通过', if(a.verify_status = 2, '未通过', ''))) as verifyStatusName
  287. FROM
  288. ta_recommend_customer a
  289. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  290. <where>
  291. a.status > 0
  292. and a.report_recommend_status = 2
  293. <if test="orgId != null">
  294. and a.org_id = #{orgId}
  295. </if>
  296. <if test="personBuildingList != null and personBuildingList.size > 0">
  297. AND a.building_id in
  298. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  299. #{personBuilding.buildingId}
  300. </foreach>
  301. </if>
  302. </where>
  303. order by a.create_date desc
  304. limit #{pageCode}, #{pageSize}
  305. </select>
  306. <select id="getRecCustomerExportCount" resultType="java.lang.Integer">
  307. SELECT
  308. count(*)
  309. FROM
  310. ta_recommend_customer a
  311. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  312. <where>
  313. a.status > 0
  314. and a.report_recommend_status = 2
  315. <if test="orgId != null">
  316. and a.org_id = #{orgId}
  317. </if>
  318. <if test="personBuildingList != null and personBuildingList.size > 0">
  319. AND a.building_id in
  320. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  321. #{personBuilding.buildingId}
  322. </foreach>
  323. </if>
  324. </where>
  325. </select>
  326. <select id="getRepCustomerReportCount" resultType="java.lang.Integer">
  327. SELECT
  328. count(*)
  329. FROM
  330. ta_recommend_customer a
  331. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  332. LEFT JOIN ta_building c ON a.building_id = c.building_id
  333. <where>
  334. a.status > 0
  335. and a.report_recommend_status = 1
  336. <if test="orgId != null">
  337. and a.org_id = #{orgId}
  338. </if>
  339. <if test="building != null and building !=''">
  340. and a.building_id = #{building}
  341. </if>
  342. <if test="name != null and name !=''">
  343. and a.name = #{name}
  344. </if>
  345. <if test="tel != null and tel!=''">
  346. and a.phone like concat(concat("%",#{tel}),"%")
  347. </if>
  348. <if test="consultName != null and consultName !=''">
  349. and b.name like CONCAT('%',#{consultName}, '%')
  350. </if>
  351. <if test="consultTel != null and consultTel !=''">
  352. and b.tel = #{consultTel}
  353. </if>
  354. <if test="entryType != null and entryType !=''">
  355. and a.entry_type = #{entryType}
  356. </if>
  357. <if test="verifyStatus != null and verifyStatus !=''">
  358. and a.verify_status = #{verifyStatus}
  359. </if>
  360. <if test="sex != null and sex !=''">
  361. and a.sex = #{sex}
  362. and a.org_id = #{orgid}
  363. </if>
  364. <if test="personBuildingList != null and personBuildingList.size > 0">
  365. AND a.building_id in
  366. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  367. #{personBuilding.buildingId}
  368. </foreach>
  369. </if>
  370. </where>
  371. order by a.create_date desc
  372. </select>
  373. <select id="getRepCustomerReportExport" resultType="com.huiju.estateagents.excel.ReporRecommendCustomer" >
  374. SELECT
  375. a.name as name,
  376. a.phone as phone,
  377. c.building_name as intentionName,
  378. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  379. b.NAME AS consultantName,
  380. b.tel AS consultTel
  381. FROM
  382. ta_recommend_customer a
  383. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  384. LEFT JOIN ta_building c ON a.building_id = c.building_id
  385. <where>
  386. a.status > 0
  387. and a.report_recommend_status = 1
  388. <if test="orgId != null">
  389. and a.org_id = #{orgId}
  390. </if>
  391. <if test="building != null and building !=''">
  392. and a.building_id = #{building}
  393. </if>
  394. <if test="name != null and name !=''">
  395. and a.name = #{name}
  396. </if>
  397. <if test="tel != null and tel!=''">
  398. and a.phone like concat(concat("%",#{tel}),"%")
  399. </if>
  400. <if test="consultName != null and consultName !=''">
  401. and b.name like CONCAT('%',#{consultName}, '%')
  402. </if>
  403. <if test="consultTel != null and consultTel !=''">
  404. and b.tel = #{consultTel}
  405. </if>
  406. <if test="entryType != null and entryType !=''">
  407. and a.entry_type = #{entryType}
  408. </if>
  409. <if test="verifyStatus != null and verifyStatus !=''">
  410. and a.verify_status = #{verifyStatus}
  411. </if>
  412. <if test="sex != null and sex !=''">
  413. and a.sex = #{sex}
  414. and a.org_id = #{orgid}
  415. </if>
  416. <if test="personBuildingList != null and personBuildingList.size > 0">
  417. AND a.building_id in
  418. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  419. #{personBuilding.buildingId}
  420. </foreach>
  421. </if>
  422. </where>
  423. order by a.create_date desc
  424. limit #{pageCode}, #{pageSize}
  425. </select>
  426. <select id="getIndependentAgentsCount" resultType="java.lang.Integer">
  427. SELECT
  428. count(*)
  429. FROM
  430. ta_person a
  431. left join ta_channel_person tcp on a.person_id = tcp.person_id
  432. left join ta_channel tc on tc.channel_id = tcp.channel_id
  433. <where>
  434. a.person_type = 'estate agent'
  435. and a.status >0
  436. <if test="orgId != null">
  437. and a.org_id = #{orgId}
  438. </if>
  439. </where>
  440. ORDER BY
  441. a.create_date DESC
  442. </select>
  443. <select id="getIndependentAgentsExport" resultType="com.huiju.estateagents.excel.AgentsRecommendCustomer">
  444. SELECT
  445. a.nickname as nickname,
  446. a.phone as phone,
  447. if(a.gender = '1', '男', if(a.gender = '2', '女', '未知')) as gender,
  448. if(ifnull(tc.channel_name, '') != '', '渠道经纪人', '独立经纪人') as personType,
  449. tc.channel_name as channelName,
  450. (
  451. SELECT
  452. count( 1 )
  453. FROM
  454. ta_person tp
  455. WHERE
  456. tp.recommend_agent = a.person_id
  457. ) AS agentCount,
  458. (
  459. SELECT
  460. count( 1 )
  461. FROM
  462. ta_recommend_customer tarc
  463. WHERE
  464. tarc.recommend_person = a.person_id
  465. and tarc.status = 1
  466. and tarc.org_id = #{orgId}
  467. ) AS recommedCount
  468. FROM
  469. ta_person a
  470. left join ta_channel_person tcp on a.person_id = tcp.person_id
  471. left join ta_channel tc on tc.channel_id = tcp.channel_id
  472. <where>
  473. ifnull(a.person_type, '') in ('channel agent', 'estate agent')
  474. and a.status >0
  475. <if test="orgId != null">
  476. and a.org_id = #{orgId}
  477. </if>
  478. </where>
  479. ORDER BY
  480. a.create_date DESC
  481. limit #{pageCode}, #{pageSize}
  482. </select>
  483. <select id="getPublicCustomerExportListCount" resultType="Integer">
  484. SELECT
  485. count(1)
  486. FROM
  487. ta_person b
  488. <where>
  489. b.status > 0
  490. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  491. <if test="name != null and name !=''">
  492. and b.nickname like CONCAT('%',#{name}, '%')
  493. </if>
  494. <if test="tel != null and tel!=''">
  495. and b.phone like CONCAT('%',#{tel}, '%')
  496. </if>
  497. <if test="entryType != null and entryType !=''">
  498. and b.entry_type = #{entryType}
  499. </if>
  500. <if test="sex != null and sex !=''">
  501. and b.sex = #{sex}
  502. </if>
  503. <if test="orgId != null">
  504. and b.org_id = #{orgId}
  505. </if>
  506. <if test="consultTel != null and consultTel !=''">
  507. and b.tel like CONCAT('%',#{consultTel}, '%')
  508. </if>
  509. and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
  510. </where>
  511. order by b.create_date desc
  512. </select>
  513. <select id="getPublicCustomerExportList" resultType="com.huiju.estateagents.excel.PublicCustomerExport">
  514. SELECT
  515. b.nickname as nickname,
  516. b.phone as phone,
  517. if(b.gender = 1, '男', if(b.gender = 2, '女', '未知')) as sex
  518. FROM
  519. ta_person b
  520. <where>
  521. b.status > 0
  522. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  523. <if test="name != null and name !=''">
  524. and b.nickname like CONCAT('%',#{name}, '%')
  525. </if>
  526. <if test="tel != null and tel!=''">
  527. and b.phone like CONCAT('%',#{tel}, '%')
  528. </if>
  529. <if test="entryType != null and entryType !=''">
  530. and b.entry_type = #{entryType}
  531. </if>
  532. <if test="sex != null and sex !=''">
  533. and b.sex = #{sex}
  534. </if>
  535. <if test="orgId != null">
  536. and b.org_id = #{orgId}
  537. </if>
  538. <if test="consultTel != null and consultTel !=''">
  539. and b.tel like CONCAT('%',#{consultTel}, '%')
  540. </if>
  541. and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
  542. </where>
  543. order by b.create_date desc
  544. limit #{pageCode}, #{pageSize}
  545. </select>
  546. <select id="getCustomerExportListCount" resultType="Integer" >
  547. SELECT
  548. count(1)
  549. FROM
  550. ta_recommend_customer a
  551. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  552. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  553. <where>
  554. a.status > 0
  555. and a.verify_status = 1
  556. and realty_consultant is not null
  557. <if test="orgId != null">
  558. and a.org_id = #{orgId}
  559. </if>
  560. <if test="building != null and building !=''">
  561. and a.building_id = #{building}
  562. </if>
  563. <if test="name != null and name !=''">
  564. and a.name like CONCAT('%',#{name}, '%')
  565. </if>
  566. <if test="tel != null and tel!=''">
  567. and a.phone like CONCAT('%',#{tel}, '%')
  568. </if>
  569. <if test="consultName != null and consultName !=''">
  570. and b.name like CONCAT('%',#{consultName}, '%')
  571. </if>
  572. <if test="consultTel != null and consultTel !=''">
  573. and b.tel like CONCAT('%',#{consultTel}, '%')
  574. </if>
  575. <if test="entryType != null and entryType !=''">
  576. and a.entry_type = #{entryType}
  577. </if>
  578. <if test="verifyStatus != null and verifyStatus !=''">
  579. and a.verify_status = #{verifyStatus}
  580. </if>
  581. <if test="status != null and status !=''">
  582. and a.status = #{status}
  583. </if>
  584. <if test="sex != null and sex !=''">
  585. and a.sex = #{sex}
  586. </if>
  587. <if test="personBuildingList != null and personBuildingList.size > 0">
  588. AND a.building_id in
  589. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  590. #{personBuilding.buildingId}
  591. </foreach>
  592. </if>
  593. </where>
  594. order by a.create_date desc
  595. </select>
  596. <select id="getCustomerExportList" resultType="com.huiju.estateagents.excel.PrivateCustomerExport">
  597. SELECT
  598. a.name AS name,
  599. a.phone as phone,
  600. if(a.sex = 1, '男', if(a.sex = 2, '女', '未知')) as sex,
  601. CASE
  602. WHEN b.NAME IS NULL THEN
  603. c.NAME ELSE b.NAME
  604. END AS consultantName,
  605. CASE
  606. WHEN b.tel IS NULL THEN
  607. c.tel ELSE b.tel
  608. END AS consultTel
  609. FROM
  610. ta_recommend_customer a
  611. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  612. left join ta_person c on a.realty_consultant = c.user_id
  613. <where>
  614. a.status > 0
  615. and a.verify_status = 1
  616. and realty_consultant is not null
  617. <if test="orgId != null">
  618. and a.org_id = #{orgId}
  619. </if>
  620. <if test="building != null and building !=''">
  621. and a.building_id = #{building}
  622. </if>
  623. <if test="name != null and name !=''">
  624. and a.name like CONCAT('%',#{name}, '%')
  625. </if>
  626. <if test="tel != null and tel!=''">
  627. and a.phone like CONCAT('%',#{tel}, '%')
  628. </if>
  629. <if test="consultName != null and consultName !=''">
  630. and b.name like CONCAT('%',#{consultName}, '%')
  631. </if>
  632. <if test="consultTel != null and consultTel !=''">
  633. and b.tel like CONCAT('%',#{consultTel}, '%')
  634. </if>
  635. <if test="entryType != null and entryType !=''">
  636. and a.entry_type = #{entryType}
  637. </if>
  638. <if test="verifyStatus != null and verifyStatus !=''">
  639. and a.verify_status = #{verifyStatus}
  640. </if>
  641. <if test="status != null and status !=''">
  642. and a.status = #{status}
  643. </if>
  644. <if test="sex != null and sex !=''">
  645. and a.sex = #{sex}
  646. </if>
  647. <if test="personBuildingList != null and personBuildingList.size > 0">
  648. AND a.building_id in
  649. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  650. #{personBuilding.buildingId}
  651. </foreach>
  652. </if>
  653. </where>
  654. order by a.create_date desc
  655. limit #{pageCode}, #{pageSize}
  656. </select>
  657. <select id="getMyCustStatistics" resultType="java.util.Map">
  658. SELECT
  659. sum( IF ( STATUS = 4 AND verify_status = 1, 1, 0 ) ) AS clinchSum,
  660. sum( IF ( STATUS != 4 AND verify_status = 1, 1, 0 ) ) AS followSum
  661. FROM
  662. ta_recommend_customer
  663. WHERE
  664. org_id = #{orgId}
  665. AND ( realty_consultant = #{personId}
  666. <if test="userId != null and userId != ''">
  667. OR realty_consultant = #{userId}
  668. </if>
  669. )
  670. </select>
  671. <select id="getMyCustFollowOrClinch" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  672. SELECT
  673. *
  674. FROM
  675. ta_recommend_customer
  676. WHERE
  677. org_id = #{orgId}
  678. AND ( realty_consultant = #{personId} OR realty_consultant = #{userId} )
  679. <if test="type == 'follow'">
  680. AND STATUS != 4
  681. AND verify_status = 1
  682. <if test="name != null and name !=''">
  683. and (`name` like CONCAT('%',#{name}, '%') or phone like CONCAT('%',#{name}, '%'))
  684. </if>
  685. <if test="phone != null and phone !=''">
  686. and phone like CONCAT('%',#{phone}, '%')
  687. </if>
  688. <if test="status != null and status !=''">
  689. and status = #{status}
  690. </if>
  691. <if test="startReportDate != null and startReportDate !=''">
  692. and date_format( report_date, '%Y-%m-%d' ) >= #{startReportDate}
  693. </if>
  694. <if test="endReportDate != null and endReportDate !=''">
  695. and date_format( report_date, '%Y-%m-%d' ) &lt;= #{endReportDate}
  696. </if>
  697. <if test="startArrivalDate != null and startArrivalDate !=''">
  698. and date_format( arrival_date, '%Y-%m-%d' ) >= #{startArrivalDate}
  699. </if>
  700. <if test="endArrivalDate != null and endArrivalDate !=''">
  701. and date_format( arrival_date, '%Y-%m-%d' ) &lt;= #{endArrivalDate}
  702. </if>
  703. </if>
  704. <if test="type == 'clinch'">
  705. AND STATUS = 4
  706. </if>
  707. </select>
  708. <select id="getMyCustDetailById" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  709. SELECT
  710. *
  711. FROM
  712. ta_recommend_customer
  713. where customer_id = #{customerId}
  714. </select>
  715. <select id="getCustomerIntentions" resultType="com.huiju.estateagents.entity.PersonIntention">
  716. SELECT
  717. SUM( a.intention ) AS intention,
  718. a.building_id,
  719. b.building_name
  720. FROM
  721. ta_person_intention_record a
  722. left join ta_building b on a.building_id = b.building_id
  723. WHERE
  724. a.person_id = #{personId}
  725. <if test="personBuildingList != null and personBuildingList.size > 0">
  726. AND a.building_id in
  727. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  728. #{personBuilding.buildingId}
  729. </foreach>
  730. </if>
  731. GROUP BY
  732. a.building_id
  733. ORDER BY
  734. intention DESC
  735. </select>
  736. <select id="getCustomersIRecommended" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  737. select a.*,b.avatarurl from ta_recommend_customer a left join ta_person b on a.person_id = b.person_id
  738. where a.recommend_person = #{customerId}
  739. and a.status = #{status}
  740. and a.org_id = #{orgId}
  741. <if test="personBuildingList != null and personBuildingList.size > 0">
  742. AND a.building_id in
  743. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  744. #{personBuilding.buildingId}
  745. </foreach>
  746. </if>
  747. </select>
  748. </mapper>