TaRecommendCustomerMapper.xml 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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 desc 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 = #{name}
  52. </if>
  53. <if test="tel != null and tel!=''">
  54. and a.phone = #{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 = #{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. </where>
  72. order by a.create_date desc
  73. </select>
  74. <select id="getIndependentAgents" resultType="com.huiju.estateagents.entity.TaPerson">
  75. SELECT
  76. a.*,
  77. tc.channel_name as channelName
  78. FROM
  79. ta_person a
  80. left join ta_channel_person tcp on a.person_id = tcp.person_id
  81. left join ta_channel tc on tc.channel_id = tcp.channel_id
  82. <where>
  83. a.person_type in ('estate agent', 'channel agent')
  84. and a.status >0
  85. <if test="name != null and name !=''">
  86. and a.nickname = #{name}
  87. </if>
  88. <if test="tel != null and tel!=''">
  89. and a.phone = #{tel}
  90. </if>
  91. <if test="orgId != null">
  92. and a.org_id = #{orgId}
  93. </if>
  94. </where>
  95. ORDER BY
  96. create_date DESC
  97. </select>
  98. <select id="getRepCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  99. SELECT
  100. a.*,
  101. a.customer_id AS customerId,
  102. b.NAME AS consultantName,
  103. b.tel AS consultTel
  104. FROM
  105. ta_recommend_customer a
  106. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  107. <where>
  108. a.status > 0
  109. and a.report_recommend_status = 1
  110. <if test="orgId != null">
  111. and a.org_id = #{orgId}
  112. </if>
  113. <if test="building != null and building !=''">
  114. and a.building_id = #{building}
  115. </if>
  116. <if test="name != null and name !=''">
  117. and a.name = #{name}
  118. </if>
  119. <if test="tel != null and tel!=''">
  120. and a.phone like concat(concat("%",#{tel}),"%")
  121. </if>
  122. <if test="consultName != null and consultName !=''">
  123. and b.name like CONCAT('%',#{consultName}, '%')
  124. </if>
  125. <if test="consultTel != null and consultTel !=''">
  126. and b.tel = #{consultTel}
  127. </if>
  128. <if test="entryType != null and entryType !=''">
  129. and a.entry_type = #{entryType}
  130. </if>
  131. <if test="verifyStatus != null and verifyStatus !=''">
  132. and a.verify_status = #{verifyStatus}
  133. </if>
  134. <if test="sex != null and sex !=''">
  135. and a.sex = #{sex}
  136. and a.org_id = #{orgid}
  137. </if>
  138. </where>
  139. order by a.create_date desc
  140. </select>
  141. <select id="getCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  142. SELECT
  143. a.*,
  144. a.customer_id as customerId,
  145. b.name as consultantName,
  146. b.tel as consultTel,
  147. c.nickname as recommendName,
  148. c.tel as recommendTel,
  149. (select tpp.name from ta_share_person_from tspf left join ta_person tpp on tspf.share_person = tpp.person_id where tspf.building_id = #{building} and tspf.is_first_time = 1 and a.person_id = tspf.person_id) as sharePersonName
  150. FROM
  151. ta_recommend_customer a
  152. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  153. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  154. <where>
  155. a.status > 0
  156. and a.realty_consultant is not null
  157. <if test="orgId != null">
  158. and a.org_id = #{orgId}
  159. </if>
  160. <if test="building != null and building !=''">
  161. and a.building_id = #{building}
  162. </if>
  163. <if test="name != null and name !=''">
  164. and a.name like CONCAT('%',#{name}, '%')
  165. </if>
  166. <if test="tel != null and tel!=''">
  167. and a.phone like CONCAT('%',#{tel}, '%')
  168. </if>
  169. <if test="consultName != null and consultName !=''">
  170. and b.name like CONCAT('%',#{consultName}, '%')
  171. </if>
  172. <if test="consultTel != null and consultTel !=''">
  173. and b.tel like CONCAT('%',#{consultTel}, '%')
  174. </if>
  175. <if test="entryType != null and entryType !=''">
  176. and a.entry_type = #{entryType}
  177. </if>
  178. <if test="verifyStatus != null and verifyStatus !=''">
  179. and a.verify_status = #{verifyStatus}
  180. </if>
  181. <if test="status != null and status !=''">
  182. and a.status = #{status}
  183. </if>
  184. <if test="sex != null and sex !=''">
  185. and a.sex = #{sex}
  186. </if>
  187. </where>
  188. order by a.create_date desc
  189. </select>
  190. <select id="getCustomerById" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  191. SELECT
  192. a.*,
  193. b.name as consultantName
  194. FROM
  195. ta_recommend_customer a
  196. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  197. WHERE a.customer_id = #{customerId}
  198. </select>
  199. <select id="getPublicCustomerList" resultType="com.huiju.estateagents.entity.TaPerson">
  200. SELECT
  201. b.*
  202. FROM
  203. ta_person b
  204. <where>
  205. b.status > 0
  206. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  207. <if test="name != null and name !=''">
  208. and b.nickname like CONCAT('%',#{name}, '%')
  209. </if>
  210. <if test="tel != null and tel!=''">
  211. and b.phone like CONCAT('%',#{tel}, '%')
  212. </if>
  213. <if test="entryType != null and entryType !=''">
  214. and b.entry_type = #{entryType}
  215. </if>
  216. <if test="sex != null and sex !=''">
  217. and b.sex = #{sex}
  218. </if>
  219. <if test="orgId != null">
  220. and b.org_id = #{orgId}
  221. </if>
  222. <if test="consultTel != null and consultTel !=''">
  223. and b.tel like CONCAT('%',#{consultTel}, '%')
  224. </if>
  225. and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
  226. </where>
  227. order by b.create_date desc
  228. </select>
  229. <select id="getRecCustomerExport" resultType="com.huiju.estateagents.excel.ExcelRecommendCustomer">
  230. SELECT
  231. a.name as name,
  232. a.phone as phone,
  233. a.intention as intention,
  234. a.create_date as createDate,
  235. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  236. c.nickname as recommend,
  237. c.phone as recommendTel,
  238. if(a.verify_status = 0, '未通过', if(a.verify_status = 1, '已通过', if(a.verify_status = 2, '已驳回', ''))) as verifyStatusName
  239. FROM
  240. ta_recommend_customer a
  241. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  242. <where>
  243. a.status > 0
  244. and a.report_recommend_status = 2
  245. <if test="orgId != null">
  246. and a.org_id = #{orgId}
  247. </if>
  248. </where>
  249. order by a.create_date desc
  250. limit #{pageCode}, #{pageSize}
  251. </select>
  252. <select id="getRecCustomerExportCount" resultType="java.lang.Integer">
  253. SELECT
  254. count(*)
  255. FROM
  256. ta_recommend_customer a
  257. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  258. <where>
  259. a.status > 0
  260. and a.report_recommend_status = 2
  261. <if test="orgId != null">
  262. and a.org_id = #{orgId}
  263. </if>
  264. </where>
  265. </select>
  266. <select id="getRepCustomerReportCount" resultType="java.lang.Integer">
  267. SELECT
  268. count(*)
  269. FROM
  270. ta_recommend_customer a
  271. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  272. <where>
  273. a.status > 0
  274. and a.report_recommend_status = 1
  275. <if test="orgId != null">
  276. and a.org_id = #{orgId}
  277. </if>
  278. </where>
  279. </select>
  280. <select id="getRepCustomerReportExport" resultType="com.huiju.estateagents.excel.ReporRecommendCustomer" >
  281. SELECT
  282. a.name as name,
  283. a.phone as phone,
  284. a.intention as intention,
  285. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  286. b.NAME AS consultantName,
  287. b.tel AS consultTel
  288. FROM
  289. ta_recommend_customer a
  290. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  291. <where>
  292. a.status > 0
  293. and a.report_recommend_status = 1
  294. <if test="orgId != null">
  295. and a.org_id = #{orgId}
  296. </if>
  297. </where>
  298. order by a.create_date desc
  299. limit #{pageCode}, #{pageSize}
  300. </select>
  301. <select id="getIndependentAgentsCount" resultType="java.lang.Integer">
  302. SELECT
  303. count(*)
  304. FROM
  305. ta_person a
  306. left join ta_channel_person tcp on a.person_id = tcp.person_id
  307. left join ta_channel tc on tc.channel_id = tcp.channel_id
  308. <where>
  309. a.person_type = 'estate agent'
  310. and a.status >0
  311. <if test="orgId != null">
  312. and a.org_id = #{orgId}
  313. </if>
  314. </where>
  315. ORDER BY
  316. a.create_date DESC
  317. </select>
  318. <select id="getIndependentAgentsExport" resultType="com.huiju.estateagents.excel.AgentsRecommendCustomer">
  319. SELECT
  320. a.nickname as nickname,
  321. a.phone as phone,
  322. if(a.gender = '1', '男', if(a.gender = '2', '女', '未知')) as gender,
  323. if(ifnull(tc.channel_name, '') != '', '渠道经纪人', '独立经纪人') as personType,
  324. tc.channel_name as channelName,
  325. (
  326. SELECT
  327. count( 1 )
  328. FROM
  329. ta_recommend_customer tarc
  330. LEFT JOIN ta_person tp ON tarc.recommend_person = tp.person_id
  331. WHERE
  332. tarc.recommend_person = a.person_id and ifnull(tp.person_type, '') = 'customer'
  333. ) AS recommedCount,
  334. (
  335. SELECT
  336. count( 1 )
  337. FROM
  338. ta_recommend_customer tarc
  339. LEFT JOIN ta_person tp ON tarc.recommend_person = tp.person_id
  340. WHERE
  341. tarc.recommend_person = a.person_id and ifnull(tp.person_type, '') in ('channel agent', 'estate agent')
  342. ) AS agentCount
  343. FROM
  344. ta_person a
  345. left join ta_channel_person tcp on a.person_id = tcp.person_id
  346. left join ta_channel tc on tc.channel_id = tcp.channel_id
  347. <where>
  348. ifnull(a.person_type, '') in ('channel agent', 'estate agent')
  349. and a.status >0
  350. <if test="orgId != null">
  351. and a.org_id = #{orgId}
  352. </if>
  353. </where>
  354. ORDER BY
  355. a.create_date DESC
  356. limit #{pageCode}, #{pageSize}
  357. </select>
  358. <select id="getPublicCustomerExportListCount" resultType="Integer">
  359. SELECT
  360. count(1)
  361. FROM
  362. ta_person b
  363. <where>
  364. b.status > 0
  365. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  366. <if test="name != null and name !=''">
  367. and b.nickname like CONCAT('%',#{name}, '%')
  368. </if>
  369. <if test="tel != null and tel!=''">
  370. and b.phone like CONCAT('%',#{tel}, '%')
  371. </if>
  372. <if test="entryType != null and entryType !=''">
  373. and b.entry_type = #{entryType}
  374. </if>
  375. <if test="sex != null and sex !=''">
  376. and b.sex = #{sex}
  377. </if>
  378. <if test="orgId != null">
  379. and b.org_id = #{orgId}
  380. </if>
  381. <if test="consultTel != null and consultTel !=''">
  382. and b.tel like CONCAT('%',#{consultTel}, '%')
  383. </if>
  384. and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
  385. </where>
  386. order by b.create_date desc
  387. </select>
  388. <select id="getPublicCustomerExportList" resultType="com.huiju.estateagents.excel.PublicCustomerExport">
  389. SELECT
  390. b.nickname as nickname,
  391. b.phone as phone,
  392. if(b.sex = 1, '男', if(b.sex = 2, '女', '未知')) as sex
  393. FROM
  394. ta_person b
  395. <where>
  396. b.status > 0
  397. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  398. <if test="name != null and name !=''">
  399. and b.nickname like CONCAT('%',#{name}, '%')
  400. </if>
  401. <if test="tel != null and tel!=''">
  402. and b.phone like CONCAT('%',#{tel}, '%')
  403. </if>
  404. <if test="entryType != null and entryType !=''">
  405. and b.entry_type = #{entryType}
  406. </if>
  407. <if test="sex != null and sex !=''">
  408. and b.sex = #{sex}
  409. </if>
  410. <if test="orgId != null">
  411. and b.org_id = #{orgId}
  412. </if>
  413. <if test="consultTel != null and consultTel !=''">
  414. and b.tel like CONCAT('%',#{consultTel}, '%')
  415. </if>
  416. and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
  417. </where>
  418. order by b.create_date desc
  419. limit #{pageCode}, #{pageSize}
  420. </select>
  421. <select id="getCustomerExportListCount" resultType="Integer" >
  422. SELECT
  423. count(1)
  424. FROM
  425. ta_recommend_customer a
  426. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  427. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  428. <where>
  429. a.status > 0
  430. and realty_consultant is not null
  431. <if test="orgId != null">
  432. and a.org_id = #{orgId}
  433. </if>
  434. <if test="building != null and building !=''">
  435. and a.building_id = #{building}
  436. </if>
  437. <if test="name != null and name !=''">
  438. and a.name like CONCAT('%',#{name}, '%')
  439. </if>
  440. <if test="tel != null and tel!=''">
  441. and a.phone like CONCAT('%',#{tel}, '%')
  442. </if>
  443. <if test="consultName != null and consultName !=''">
  444. and b.name like CONCAT('%',#{consultName}, '%')
  445. </if>
  446. <if test="consultTel != null and consultTel !=''">
  447. and b.tel like CONCAT('%',#{consultTel}, '%')
  448. </if>
  449. <if test="entryType != null and entryType !=''">
  450. and a.entry_type = #{entryType}
  451. </if>
  452. <if test="verifyStatus != null and verifyStatus !=''">
  453. and a.verify_status = #{verifyStatus}
  454. </if>
  455. <if test="status != null and status !=''">
  456. and a.status = #{status}
  457. </if>
  458. <if test="sex != null and sex !=''">
  459. and a.sex = #{sex}
  460. </if>
  461. </where>
  462. order by a.create_date desc
  463. </select>
  464. <select id="getCustomerExportList" resultType="com.huiju.estateagents.excel.PrivateCustomerExport">
  465. SELECT
  466. a.name AS name,
  467. a.phone as phone,
  468. if(a.sex = 1, '男', if(a.sex = 2, '女', '未知')) as sex,
  469. b.name as consultantName,
  470. b.tel as consultTel
  471. FROM
  472. ta_recommend_customer a
  473. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  474. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  475. <where>
  476. a.status > 0
  477. and realty_consultant is not null
  478. <if test="orgId != null">
  479. and a.org_id = #{orgId}
  480. </if>
  481. <if test="building != null and building !=''">
  482. and a.building_id = #{building}
  483. </if>
  484. <if test="name != null and name !=''">
  485. and a.name like CONCAT('%',#{name}, '%')
  486. </if>
  487. <if test="tel != null and tel!=''">
  488. and a.phone like CONCAT('%',#{tel}, '%')
  489. </if>
  490. <if test="consultName != null and consultName !=''">
  491. and b.name like CONCAT('%',#{consultName}, '%')
  492. </if>
  493. <if test="consultTel != null and consultTel !=''">
  494. and b.tel like CONCAT('%',#{consultTel}, '%')
  495. </if>
  496. <if test="entryType != null and entryType !=''">
  497. and a.entry_type = #{entryType}
  498. </if>
  499. <if test="verifyStatus != null and verifyStatus !=''">
  500. and a.verify_status = #{verifyStatus}
  501. </if>
  502. <if test="status != null and status !=''">
  503. and a.status = #{status}
  504. </if>
  505. <if test="sex != null and sex !=''">
  506. and a.sex = #{sex}
  507. </if>
  508. </where>
  509. order by a.create_date desc
  510. limit #{pageCode}, #{pageSize}
  511. </select>
  512. </mapper>