TaRecommendCustomerMapper.xml 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 = 'estate 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 = #{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. FROM
  150. ta_recommend_customer a
  151. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  152. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  153. <where>
  154. a.status > 0
  155. and realty_consultant is not null
  156. <if test="orgId != null">
  157. and a.org_id = #{orgId}
  158. </if>
  159. <if test="building != null and building !=''">
  160. and a.building_id = #{building}
  161. </if>
  162. <if test="name != null and name !=''">
  163. and a.name = #{name}
  164. </if>
  165. <if test="tel != null and tel!=''">
  166. and a.phone = #{tel}
  167. </if>
  168. <if test="consultName != null and consultName !=''">
  169. and b.name like CONCAT('%',#{consultName}, '%')
  170. </if>
  171. <if test="consultTel != null and consultTel !=''">
  172. and b.tel = #{consultTel}
  173. </if>
  174. <if test="entryType != null and entryType !=''">
  175. and a.entry_type = #{entryType}
  176. </if>
  177. <if test="verifyStatus != null and verifyStatus !=''">
  178. and a.verify_status = #{verifyStatus}
  179. </if>
  180. <if test="sex != null and sex !=''">
  181. and a.sex = #{sex}
  182. </if>
  183. </where>
  184. order by a.create_date desc
  185. </select>
  186. <select id="getCustomerById" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
  187. SELECT
  188. a.*,
  189. b.name as consultantName
  190. FROM
  191. ta_recommend_customer a
  192. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  193. WHERE a.customer_id = #{customerId}
  194. </select>
  195. <select id="getPublicCustomerList" resultType="com.huiju.estateagents.entity.TaPerson">
  196. SELECT
  197. b.*
  198. FROM
  199. ta_person b
  200. <where>
  201. b.status > 0
  202. AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
  203. <if test="name != null and name !=''">
  204. and b.nickname = #{name}
  205. </if>
  206. <if test="tel != null and tel!=''">
  207. and b.phone = #{tel}
  208. </if>
  209. <if test="entryType != null and entryType !=''">
  210. and b.entry_type = #{entryType}
  211. </if>
  212. <if test="sex != null and sex !=''">
  213. and b.sex = #{sex}
  214. </if>
  215. <if test="orgId != null">
  216. and b.org_id = #{orgId}
  217. </if>
  218. and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
  219. </where>
  220. order by b.create_date desc
  221. </select>
  222. <select id="getRecCustomerExport" resultType="com.huiju.estateagents.excel.ExcelRecommendCustomer">
  223. SELECT
  224. a.name as name,
  225. a.phone as phone,
  226. a.intention as intention,
  227. a.create_date as createDate,
  228. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  229. concat(c.nickname, c.phone) as recommend
  230. FROM
  231. ta_recommend_customer a
  232. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  233. <where>
  234. a.status > 0
  235. and a.report_recommend_status = 2
  236. <if test="orgId != null">
  237. and a.org_id = #{orgId}
  238. </if>
  239. </where>
  240. order by a.create_date desc
  241. limit #{pageCode}, #{pageSize}
  242. </select>
  243. <select id="getRecCustomerExportCount" resultType="java.lang.Integer">
  244. SELECT
  245. count(*)
  246. FROM
  247. ta_recommend_customer a
  248. LEFT JOIN ta_person c on a.recommend_person = c.person_id
  249. <where>
  250. a.status > 0
  251. and a.report_recommend_status = 2
  252. <if test="orgId != null">
  253. and a.org_id = #{orgId}
  254. </if>
  255. </where>
  256. </select>
  257. <select id="getRepCustomerReportCount" resultType="java.lang.Integer">
  258. SELECT
  259. count(*)
  260. FROM
  261. ta_recommend_customer a
  262. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  263. <where>
  264. a.status > 0
  265. and a.report_recommend_status = 1
  266. <if test="orgId != null">
  267. and a.org_id = #{orgId}
  268. </if>
  269. </where>
  270. </select>
  271. <select id="getRepCustomerReportExport" resultType="com.huiju.estateagents.excel.ReporRecommendCustomer" >
  272. SELECT
  273. a.name as name,
  274. a.phone as phone,
  275. a.intention as intention,
  276. if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
  277. b.NAME AS consultantName,
  278. b.tel AS consultTel
  279. FROM
  280. ta_recommend_customer a
  281. LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
  282. <where>
  283. a.status > 0
  284. and a.report_recommend_status = 1
  285. <if test="orgId != null">
  286. and a.org_id = #{orgId}
  287. </if>
  288. </where>
  289. order by a.create_date desc
  290. limit #{pageCode}, #{pageSize}
  291. </select>
  292. <select id="getIndependentAgentsCount" resultType="java.lang.Integer">
  293. SELECT
  294. count(*)
  295. FROM
  296. ta_person a
  297. left join ta_channel_person tcp on a.person_id = tcp.person_id
  298. left join ta_channel tc on tc.channel_id = tcp.channel_id
  299. <where>
  300. a.person_type = 'estate agent'
  301. and a.status >0
  302. <if test="orgId != null">
  303. and a.org_id = #{orgId}
  304. </if>
  305. </where>
  306. ORDER BY
  307. create_date DESC
  308. </select>
  309. <select id="getIndependentAgentsExport" resultType="com.huiju.estateagents.excel.AgentsRecommendCustomer">
  310. SELECT
  311. a.nickname as nickname,
  312. a.phone as phone,
  313. if(a.gender = '1', '男', if(a.gender = '2', '女', '未知')) as gender,
  314. a.personType as personType,
  315. if(ifnull(tc.channel_name, '') != '', '渠道经纪人', '独立经纪人') as channelName
  316. FROM
  317. ta_person a
  318. left join ta_channel_person tcp on a.person_id = tcp.person_id
  319. left join ta_channel tc on tc.channel_id = tcp.channel_id
  320. <where>
  321. a.person_type = 'estate agent'
  322. and a.status >0
  323. <if test="orgId != null">
  324. and a.org_id = #{orgId}
  325. </if>
  326. </where>
  327. ORDER BY
  328. a.create_date DESC
  329. </select>
  330. </mapper>