123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.huiju.estateagents.mapper.TaRecommendCustomerMapper">
- <select id="getMyCutsomerNum" resultType="int">
- SELECT
- count(*) AS total
- FROM
- ta_recommend_customer t
- WHERE
- t.recommend_person = #{personId}
- AND t.status > -1
- </select>
- <select id="getCustomerPersonId" resultType="java.lang.String">
- SELECT
- person_id
- FROM
- ta_customer_person
- WHERE
- customer_id = #{customerId}
- </select>
-
- <select id="getCustomerDetail" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- a.*,
- (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,
- (SELECT SUM(d.visit_duration) FROM ta_person_visit_record d WHERE d.person_id= #{personId}) as duration
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person_visit_record c ON a.person_id = c.person_id
- where a.customer_id = #{customerId}
- GROUP BY a.customer_id
- </select>
-
- <select id="getRecCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- a.*,
- a.customer_id as customerId,
- c.phone as recommendTel,
- c.nickname as recommendName
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person c on a.recommend_person = c.person_id
- <where>
- a.status > 0
- and a.report_recommend_status = 2
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- <if test="building != null and building !=''">
- and a.building_id = #{building}
- </if>
- <if test="name != null and name !=''">
- and a.name like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="consultName != null and consultName !=''">
- and c.nickname like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and c.phone like CONCAT('%',#{consultTel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and a.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and a.verify_status = #{verifyStatus}
- </if>
- <if test="sex != null and sex !=''">
- and a.sex = #{sex}
- </if>
- </where>
- order by a.create_date desc
- </select>
-
- <select id="getIndependentAgents" resultType="com.huiju.estateagents.entity.TaPerson">
- SELECT
- a.*,
- tc.channel_name as channelName
- FROM
- ta_person a
- left join ta_channel_person tcp on a.person_id = tcp.person_id
- left join ta_channel tc on tc.channel_id = tcp.channel_id
- <where>
- a.person_type in ('estate agent', 'channel agent')
- and a.status >0
- <if test="name != null and name !=''">
- and a.nickname = #{name}
- </if>
- <if test="tel != null and tel!=''">
- and a.phone = #{tel}
- </if>
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
-
- </where>
-
- ORDER BY
- create_date DESC
- </select>
-
- <select id="getRepCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- a.*,
- a.customer_id AS customerId,
- b.NAME AS consultantName,
- b.tel AS consultTel,
- c.building_name as intentionName
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_building c ON a.building_id = c.building_id
- <where>
- a.status > 0
- and a.report_recommend_status = 1
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- <if test="building != null and building !=''">
- and a.building_id = #{building}
- </if>
- <if test="name != null and name !=''">
- and a.name = #{name}
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like concat(concat("%",#{tel}),"%")
- </if>
- <if test="consultName != null and consultName !=''">
- and b.name like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel = #{consultTel}
- </if>
- <if test="entryType != null and entryType !=''">
- and a.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and a.verify_status = #{verifyStatus}
- </if>
- <if test="sex != null and sex !=''">
- and a.sex = #{sex}
- and a.org_id = #{orgid}
- </if>
- </where>
- order by a.create_date desc
- </select>
- <select id="getCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- a.*,
- a.customer_id as customerId,
- IFNULL(b.name,d.user_name) as consultantName,
- IFNULL(b.tel,d.phone) as consultTel,
- c.nickname as recommendName,
- c.tel as recommendTel,
- IFNULL(c.name,c.nickname) AS sharePersonName
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_person c on a.recommend_person = c.person_id
- LEFT JOIN ta_user d on d.user_id = a.realty_consultant
- <where>
- a.status > 0
- and a.verify_status = 1
- and a.realty_consultant is not null
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- <if test="building != null and building !=''">
- and a.building_id = #{building}
- </if>
- <if test="name != null and name !=''">
- and a.name like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="consultName != null and consultName !=''">
- and IFNULL(b.name,d.user_name) like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and IFNULL(b.tel,d.phone) like CONCAT('%',#{consultTel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and a.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and a.verify_status = #{verifyStatus}
- </if>
- <if test="status != null and status !=''">
- and a.status = #{status}
- </if>
- <if test="sex != null and sex !=''">
- and a.sex = #{sex}
- </if>
- </where>
- order by a.create_date desc
- </select>
- <select id="getCustomerById" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- a.*,
- b.name as consultantName
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- WHERE a.customer_id = #{customerId}
- </select>
-
- <select id="getPublicCustomerList" resultType="com.huiju.estateagents.entity.TaPerson">
- SELECT
- b.*,
- (
- SELECT
- IF
- ( ifnull( tpp.NAME, '' ) != '', tpp.NAME, tpp.nickname )
- FROM
- ta_share_person_from tspf
- LEFT JOIN ta_person tpp ON tspf.share_person = tpp.person_id
- WHERE
- tspf.is_first_time = 1
- AND b.person_id = tspf.person_id
- ORDER BY
- tspf.create_date ASC
- LIMIT 1
- ) AS sharePersonName
- FROM
- ta_person b
- <where>
- b.status > 0
- and b.org_id = #{orgId}
- AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
- 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 != '' )
- <if test="name != null and name !=''">
- and b.nickname like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and b.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and b.entry_type = #{entryType}
- </if>
- <if test="sex != null and sex !=''">
- and b.sex = #{sex}
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel like CONCAT('%',#{consultTel}, '%')
- </if>
- and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
- </where>
- order by b.create_date desc
- </select>
-
- <select id="getRecCustomerExport" resultType="com.huiju.estateagents.excel.ExcelRecommendCustomer">
- SELECT
- a.name as name,
- a.phone as phone,
- a.intention as intention,
- a.create_date as createDate,
- if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
- c.nickname as recommend,
- c.phone as recommendTel,
- if(a.verify_status = 0, '待审核', if(a.verify_status = 1, '已通过', if(a.verify_status = 2, '未通过', ''))) as verifyStatusName
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person c on a.recommend_person = c.person_id
- <where>
- a.status > 0
- and a.report_recommend_status = 2
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- </where>
- order by a.create_date desc
- limit #{pageCode}, #{pageSize}
- </select>
-
- <select id="getRecCustomerExportCount" resultType="java.lang.Integer">
- SELECT
- count(*)
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person c on a.recommend_person = c.person_id
- <where>
- a.status > 0
- and a.report_recommend_status = 2
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- </where>
- </select>
-
- <select id="getRepCustomerReportCount" resultType="java.lang.Integer">
- SELECT
- count(*)
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_building c ON a.building_id = c.building_id
- <where>
- a.status > 0
- and a.report_recommend_status = 1
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- <if test="building != null and building !=''">
- and a.building_id = #{building}
- </if>
- <if test="name != null and name !=''">
- and a.name = #{name}
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like concat(concat("%",#{tel}),"%")
- </if>
- <if test="consultName != null and consultName !=''">
- and b.name like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel = #{consultTel}
- </if>
- <if test="entryType != null and entryType !=''">
- and a.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and a.verify_status = #{verifyStatus}
- </if>
- <if test="sex != null and sex !=''">
- and a.sex = #{sex}
- and a.org_id = #{orgid}
- </if>
- </where>
- order by a.create_date desc
- </select>
-
- <select id="getRepCustomerReportExport" resultType="com.huiju.estateagents.excel.ReporRecommendCustomer" >
- SELECT
- a.name as name,
- a.phone as phone,
- c.building_name as intentionName,
- if(a.sex = 1, '男',if(a.sex = 2, '女', '未知')) as sex,
- b.NAME AS consultantName,
- b.tel AS consultTel
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_building c ON a.building_id = c.building_id
- <where>
- a.status > 0
- and a.report_recommend_status = 1
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- <if test="building != null and building !=''">
- and a.building_id = #{building}
- </if>
- <if test="name != null and name !=''">
- and a.name = #{name}
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like concat(concat("%",#{tel}),"%")
- </if>
- <if test="consultName != null and consultName !=''">
- and b.name like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel = #{consultTel}
- </if>
- <if test="entryType != null and entryType !=''">
- and a.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and a.verify_status = #{verifyStatus}
- </if>
- <if test="sex != null and sex !=''">
- and a.sex = #{sex}
- and a.org_id = #{orgid}
- </if>
- </where>
- order by a.create_date desc
- limit #{pageCode}, #{pageSize}
- </select>
-
-
- <select id="getIndependentAgentsCount" resultType="java.lang.Integer">
- SELECT
- count(*)
- FROM
- ta_person a
- left join ta_channel_person tcp on a.person_id = tcp.person_id
- left join ta_channel tc on tc.channel_id = tcp.channel_id
- <where>
- a.person_type = 'estate agent'
- and a.status >0
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- </where>
-
- ORDER BY
- a.create_date DESC
- </select>
-
- <select id="getIndependentAgentsExport" resultType="com.huiju.estateagents.excel.AgentsRecommendCustomer">
- SELECT
- a.nickname as nickname,
- a.phone as phone,
- if(a.gender = '1', '男', if(a.gender = '2', '女', '未知')) as gender,
- if(ifnull(tc.channel_name, '') != '', '渠道经纪人', '独立经纪人') as personType,
- tc.channel_name as channelName,
- (
- SELECT
- count( 1 )
- FROM
- ta_person tp
- WHERE
- tp.recommend_agent = a.person_id
- ) AS agentCount,
- (
- SELECT
- count( 1 )
- FROM
- ta_recommend_customer tarc
- WHERE
- tarc.recommend_person = a.person_id
- and tarc.status = 1
- and tarc.org_id = #{orgId}
- ) AS recommedCount
- FROM
- ta_person a
- left join ta_channel_person tcp on a.person_id = tcp.person_id
- left join ta_channel tc on tc.channel_id = tcp.channel_id
- <where>
- ifnull(a.person_type, '') in ('channel agent', 'estate agent')
- and a.status >0
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
-
- </where>
-
- ORDER BY
- a.create_date DESC
- limit #{pageCode}, #{pageSize}
- </select>
-
-
- <select id="getPublicCustomerExportListCount" resultType="Integer">
- SELECT
- count(1)
- FROM
- ta_person b
- <where>
- b.status > 0
- AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
- <if test="name != null and name !=''">
- and b.nickname like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and b.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and b.entry_type = #{entryType}
- </if>
- <if test="sex != null and sex !=''">
- and b.sex = #{sex}
- </if>
- <if test="orgId != null">
- and b.org_id = #{orgId}
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel like CONCAT('%',#{consultTel}, '%')
- </if>
- and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
- </where>
- order by b.create_date desc
- </select>
-
- <select id="getPublicCustomerExportList" resultType="com.huiju.estateagents.excel.PublicCustomerExport">
- SELECT
- b.nickname as nickname,
- b.phone as phone,
- if(b.gender = 1, '男', if(b.gender = 2, '女', '未知')) as sex
- FROM
- ta_person b
- <where>
- b.status > 0
- AND IFNULL(b.person_type, '') in ('estate agent', 'customer')
- <if test="name != null and name !=''">
- and b.nickname like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and b.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and b.entry_type = #{entryType}
- </if>
- <if test="sex != null and sex !=''">
- and b.sex = #{sex}
- </if>
- <if test="orgId != null">
- and b.org_id = #{orgId}
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel like CONCAT('%',#{consultTel}, '%')
- </if>
- and NOT EXISTS ( select * from ta_recommend_customer a where a.recommend_person = b.person_id)
- </where>
- order by b.create_date desc
- limit #{pageCode}, #{pageSize}
- </select>
-
- <select id="getCustomerExportListCount" resultType="Integer" >
- SELECT
- count(1)
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_person c on a.recommend_person = c.person_id
- <where>
- a.status > 0
- and a.verify_status = 1
- and realty_consultant is not null
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- <if test="building != null and building !=''">
- and a.building_id = #{building}
- </if>
- <if test="name != null and name !=''">
- and a.name like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="consultName != null and consultName !=''">
- and b.name like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel like CONCAT('%',#{consultTel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and a.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and a.verify_status = #{verifyStatus}
- </if>
- <if test="status != null and status !=''">
- and a.status = #{status}
- </if>
- <if test="sex != null and sex !=''">
- and a.sex = #{sex}
- </if>
- </where>
- order by a.create_date desc
- </select>
-
-
- <select id="getCustomerExportList" resultType="com.huiju.estateagents.excel.PrivateCustomerExport">
- SELECT
- a.name AS name,
- a.phone as phone,
- if(a.sex = 1, '男', if(a.sex = 2, '女', '未知')) as sex,
- b.name as consultantName,
- b.tel as consultTel
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_person c on a.recommend_person = c.person_id
- <where>
- a.status > 0
- and a.verify_status = 1
- and realty_consultant is not null
- <if test="orgId != null">
- and a.org_id = #{orgId}
- </if>
- <if test="building != null and building !=''">
- and a.building_id = #{building}
- </if>
- <if test="name != null and name !=''">
- and a.name like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="consultName != null and consultName !=''">
- and b.name like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and b.tel like CONCAT('%',#{consultTel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and a.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and a.verify_status = #{verifyStatus}
- </if>
- <if test="status != null and status !=''">
- and a.status = #{status}
- </if>
- <if test="sex != null and sex !=''">
- and a.sex = #{sex}
- </if>
- </where>
- order by a.create_date desc
- limit #{pageCode}, #{pageSize}
- </select>
-
- <select id="getMyCustStatistics" resultType="java.util.Map">
- SELECT
- sum( IF ( STATUS = 4, 1, 0 ) ) AS clinchSum,
- sum( IF ( STATUS != 4 AND STATUS != 4, 1, 0 ) ) AS followSum
- FROM
- ta_recommend_customer
- WHERE
- org_id = #{orgId}
- AND ( realty_consultant = #{personId}
- <if test="userId != null and userId != ''">
- OR realty_consultant = #{userId}
- </if>
- )
- </select>
-
- <select id="getMyCustFollowOrClinch" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- *
- FROM
- ta_recommend_customer
- WHERE
- org_id = #{orgId}
- AND ( realty_consultant = #{personId} OR realty_consultant = #{userId} )
- <if test="type == 'follow'">
- AND STATUS != 4
- <if test="name != null and name !=''">
- and `name` like CONCAT('%',#{name}, '%')
- </if>
- <if test="phone != null and phone !=''">
- and phone like CONCAT('%',#{phone}, '%')
- </if>
- <if test="status != null and status !=''">
- and status = #{status}
- </if>
- <if test="startReportDate != null and startReportDate !=''">
- and date_format( report_date, '%Y-%m-%d' ) >= #{startReportDate}
- </if>
- <if test="endReportDate != null and endReportDate !=''">
- and date_format( report_date, '%Y-%m-%d' ) <= #{endReportDate}
- </if>
- <if test="startArrivalDate != null and startArrivalDate !=''">
- and date_format( arrival_date, '%Y-%m-%d' ) >= #{startArrivalDate}
- </if>
- <if test="endArrivalDate != null and endArrivalDate !=''">
- and date_format( arrival_date, '%Y-%m-%d' ) <= #{endArrivalDate}
- </if>
- </if>
- <if test="type == 'clinch'">
- AND STATUS = 4
- </if>
- </select>
-
- <select id="getMyCustDetailById" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- *
- FROM
- ta_recommend_customer
- where customer_id = #{customerId}
- </select>
-
- <select id="getCustomerIntentions" resultType="com.huiju.estateagents.entity.PersonIntention">
- SELECT
- SUM( intention ) AS intention,
- building_id,
- building_name
- FROM
- `ta_person_intention_record`
- WHERE
- person_id = #{personId}
- GROUP BY
- building_id
- ORDER BY
- intention DESC
- </select>
-
- </mapper>
|