TaRecommendCustomerMapper.xml 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. concat(b.country, b.province) as province,
  531. z.intention,
  532. d.scene_alias as sceneType,
  533. t.building_name
  534. FROM
  535. ta_person b
  536. 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}
  537. left join ta_building t on b.building_id = t.building_id
  538. 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
  539. left join td_wx_dict d on r.scene_id = d.scene_id
  540. <where>
  541. b.status > 0
  542. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  543. <if test="name != null and name !=''">
  544. and b.nickname like CONCAT('%',#{name}, '%')
  545. </if>
  546. <if test="buildingId != null and buildingId !=''">
  547. AND b.building_id = #{buildingId}
  548. </if>
  549. <if test="personBuildingList != null and personBuildingList.size > 0">
  550. AND b.building_id in
  551. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  552. #{personBuilding.buildingId}
  553. </foreach>
  554. </if>
  555. <if test="tel != null and tel!=''">
  556. and b.phone like CONCAT('%',#{tel}, '%')
  557. </if>
  558. <if test="sceneType !=null and sceneType !=''">
  559. and d.scene_type = #{sceneType}
  560. </if>
  561. <if test="entryType != null and entryType !=''">
  562. and b.entry_type = #{entryType}
  563. </if>
  564. <if test="sex != null and sex !=''">
  565. and b.sex = #{sex}
  566. </if>
  567. <if test="orgId != null">
  568. and b.org_id = #{orgId}
  569. </if>
  570. <if test="consultTel != null and consultTel !=''">
  571. and b.tel like CONCAT('%',#{consultTel}, '%')
  572. </if>
  573. and NOT EXISTS ( select * from ta_recommend_customer a where a.org_id = #{orgId} and a.recommend_person = b.person_id)
  574. 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 != '' )
  575. </where>
  576. order by b.create_date desc
  577. </select>
  578. <!-- limit #{pageCode}, #{pageSize}-->
  579. <select id="getCustomerExportListCount" resultType="Integer" >
  580. SELECT
  581. count(1)
  582. FROM
  583. ta_recommend_customer a
  584. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  585. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  586. <where>
  587. a.status > 0
  588. and a.verify_status = 1
  589. and realty_consultant is not null
  590. <if test="orgId != null">
  591. and a.org_id = #{orgId}
  592. </if>
  593. <if test="building != null and building !=''">
  594. and a.building_id = #{building}
  595. </if>
  596. <if test="name != null and name !=''">
  597. and a.name like CONCAT('%',#{name}, '%')
  598. </if>
  599. <if test="tel != null and tel!=''">
  600. and a.phone like CONCAT('%',#{tel}, '%')
  601. </if>
  602. <if test="consultName != null and consultName !=''">
  603. and b.name like CONCAT('%',#{consultName}, '%')
  604. </if>
  605. <if test="consultTel != null and consultTel !=''">
  606. and b.tel like CONCAT('%',#{consultTel}, '%')
  607. </if>
  608. <if test="entryType != null and entryType !=''">
  609. and a.entry_type = #{entryType}
  610. </if>
  611. <if test="verifyStatus != null and verifyStatus !=''">
  612. and a.verify_status = #{verifyStatus}
  613. </if>
  614. <if test="status != null and status !=''">
  615. and a.status = #{status}
  616. </if>
  617. <if test="sex != null and sex !=''">
  618. and a.sex = #{sex}
  619. </if>
  620. <if test="personBuildingList != null and personBuildingList.size > 0">
  621. AND a.building_id in
  622. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  623. #{personBuilding.buildingId}
  624. </foreach>
  625. </if>
  626. </where>
  627. order by a.create_date desc
  628. </select>
  629. <select id="getCustomerExportList" resultType="com.huiju.estateagents.excel.PrivateCustomerExport">
  630. SELECT
  631. a.name AS name,
  632. a.phone as phone,
  633. if(a.sex = 1, '男', if(a.sex = 2, '女', '未知')) as sex,
  634. CASE
  635. WHEN b.NAME IS NULL THEN
  636. d.user_name ELSE b.NAME
  637. END AS consultantName,
  638. CASE
  639. WHEN b.tel IS NULL THEN
  640. d.phone ELSE b.tel
  641. END AS consultTel,
  642. t.building_name,
  643. z.intention,
  644. a.create_date,
  645. concat(a.country,a.province) as province,
  646. w.scene_alias as scene_type
  647. FROM
  648. ta_recommend_customer a
  649. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  650. LEFT JOIN ta_person c ON a.realty_consultant = c.user_id
  651. LEFT JOIN ta_user d on d.user_id = a.realty_consultant
  652. 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}
  653. left join ta_building t on a.building_id = t.building_id
  654. LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
  655. 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
  656. <where>
  657. a.status > 0
  658. and a.verify_status = 1
  659. and a.realty_consultant is not null
  660. and a.realty_consultant != ''
  661. <if test="orgId != null">
  662. and a.org_id = #{orgId}
  663. </if>
  664. <if test="building != null and building !=''">
  665. and a.building_id = #{building}
  666. </if>
  667. <if test="name != null and name !=''">
  668. and a.name like CONCAT('%',#{name}, '%')
  669. </if>
  670. <if test="tel != null and tel!=''">
  671. and a.phone like CONCAT('%',#{tel}, '%')
  672. </if>
  673. <if test="consultName != null and consultName !=''">
  674. and b.name like CONCAT('%',#{consultName}, '%')
  675. </if>
  676. <if test="consultTel != null and consultTel !=''">
  677. and b.tel like CONCAT('%',#{consultTel}, '%')
  678. </if>
  679. <if test="entryType != null and entryType !=''">
  680. and a.entry_type = #{entryType}
  681. </if>
  682. <if test="verifyStatus != null and verifyStatus !=''">
  683. and a.verify_status = #{verifyStatus}
  684. </if>
  685. <if test="status != null and status !=''">
  686. and a.status = #{status}
  687. </if>
  688. <if test="sex != null and sex !=''">
  689. and a.sex = #{sex}
  690. </if>
  691. <if test="personBuildingList != null and personBuildingList.size > 0">
  692. AND a.building_id in
  693. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  694. #{personBuilding.buildingId}
  695. </foreach>
  696. </if>
  697. <if test="sceneType !=null and sceneType !=''">
  698. and p.scene_type = #{sceneType}
  699. </if>
  700. </where>
  701. group by a.customer_id,a.building_id
  702. order by a.create_date desc
  703. </select>
  704. <!-- limit #{pageCode}, #{pageSize}-->
  705. <select id="getMyCustStatistics" resultType="java.util.Map">
  706. SELECT
  707. sum( IF ( STATUS = 4 AND verify_status = 1, 1, 0 ) ) AS clinchSum,
  708. sum( IF ( STATUS != 4 AND verify_status = 1, 1, 0 ) ) AS followSum
  709. FROM
  710. ta_recommend_customer
  711. WHERE
  712. org_id = #{orgId}
  713. AND ( realty_consultant = #{personId}
  714. <if test="userId != null and userId != ''">
  715. OR realty_consultant = #{userId}
  716. </if>
  717. )
  718. </select>
  719. <select id="getMyCustFollowOrClinch" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  720. SELECT
  721. *
  722. FROM
  723. ta_recommend_customer
  724. WHERE
  725. org_id = #{orgId}
  726. AND ( realty_consultant = #{personId} OR realty_consultant = #{userId} )
  727. <if test="type == 'follow'">
  728. AND STATUS != 4
  729. AND verify_status = 1
  730. <if test="name != null and name !=''">
  731. and (`name` like CONCAT('%',#{name}, '%') or phone like CONCAT('%',#{name}, '%'))
  732. </if>
  733. <if test="phone != null and phone !=''">
  734. and phone like CONCAT('%',#{phone}, '%')
  735. </if>
  736. <if test="status != null and status !=''">
  737. and status = #{status}
  738. </if>
  739. <if test="startReportDate != null and startReportDate !=''">
  740. and date_format( report_date, '%Y-%m-%d' ) >= #{startReportDate}
  741. </if>
  742. <if test="endReportDate != null and endReportDate !=''">
  743. and date_format( report_date, '%Y-%m-%d' ) &lt;= #{endReportDate}
  744. </if>
  745. <if test="startArrivalDate != null and startArrivalDate !=''">
  746. and date_format( arrival_date, '%Y-%m-%d' ) >= #{startArrivalDate}
  747. </if>
  748. <if test="endArrivalDate != null and endArrivalDate !=''">
  749. and date_format( arrival_date, '%Y-%m-%d' ) &lt;= #{endArrivalDate}
  750. </if>
  751. </if>
  752. <if test="type == 'clinch'">
  753. AND STATUS = 4
  754. </if>
  755. </select>
  756. <select id="getMyCustDetailById" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  757. SELECT
  758. *
  759. FROM
  760. ta_recommend_customer
  761. where customer_id = #{customerId}
  762. </select>
  763. <select id="getCustomerIntentions" resultType="com.huiju.estateagents.entity.PersonIntention">
  764. SELECT
  765. SUM( a.intention ) AS intention,
  766. a.building_id,
  767. b.building_name
  768. FROM
  769. ta_person_intention_record a
  770. left join ta_building b on a.building_id = b.building_id
  771. WHERE
  772. a.person_id = #{personId}
  773. <if test="personBuildingList != null and personBuildingList.size > 0">
  774. AND a.building_id in
  775. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  776. #{personBuilding.buildingId}
  777. </foreach>
  778. </if>
  779. GROUP BY
  780. a.building_id
  781. ORDER BY
  782. intention DESC
  783. </select>
  784. <select id="getCustomersIRecommended" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  785. select a.*,b.avatarurl from ta_recommend_customer a left join ta_person b on a.person_id = b.person_id
  786. where a.recommend_person = #{customerId}
  787. and a.status &gt;= #{status}
  788. and a.org_id = #{orgId}
  789. <if test="personBuildingList != null and personBuildingList.size > 0">
  790. AND a.building_id in
  791. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  792. #{personBuilding.buildingId}
  793. </foreach>
  794. </if>
  795. </select>
  796. </mapper>