TaRecommendCustomerMapper.xml 35KB

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