TaRecommendCustomerMapper.xml 32KB

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