123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896 |
- <?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 asc 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>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </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 like concat('%', #{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and a.phone like concat('%', #{tel}, '%')
- </if>
- <if test="channelId != null and channelId != '' ">
- and tc.channel_id = #{channelId}
- </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,
- IFNULL(d.user_name, b.name) as consultantName,
- IFNULL(d.phone, 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_user d on a.realty_consultant = d.user_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 IFNULL(d.user_name, b.name) like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and IFNULL(d.phone, 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 a.sex = #{sex}
- </if>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- </where>
- order by a.create_date desc
- </select>
- <select id="getCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- a.*,
- IFNULL( t2.building_name, '暂无' ) AS buildingName,
- 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_user d on d.user_id = a.realty_consultant
- LEFT JOIN ta_person_from_record p ON a.person_id = p.person_id AND p.is_first_time = 1
- <if test="orgId != null">
- and p.org_id = #{orgId}
- </if>
- -- LEFT JOIN ta_person c on p.share_person_id = c.person_id
- -- LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
- LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
- LEFT JOIN ta_person p2 ON a.person_id = p2.person_id
- LEFT JOIN ta_person c ON p2.recommend_person = c.person_id
- LEFT JOIN ta_building t2 ON a.building_id = t2.building_id
- <where>
- a.status > 0
- and a.verify_status = 1
- and a.realty_consultant is not null
- and a.realty_consultant != ''
- <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>
- <if test="startCreateDate != null and startCreateDate !=''">
- and a.create_Date >= #{startCreateDate}
- </if>
- <if test="endCreateDate != null and endCreateDate !=''">
- and a.create_Date <= #{endCreateDate}
- </if>
- <if test="sharePersonName != null and sharePersonName !=''">
- and (c.nickName like CONCAT('%',#{sharePersonName}, '%') or c.name like CONCAT('%',#{sharePersonName},
- '%'))
- </if>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- <if test="sceneType !=null and sceneType !=''">
- and p.scene_type = #{sceneType}
- </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.TaRecommendCustomer">
- SELECT
- t.*,
- IFNULL( t2.building_name, '暂无' ) AS buildingName,
- ifnull( t3.nickname, t3.NAME ) AS sharePersonName
- FROM
- ta_recommend_customer t
- LEFT JOIN ta_building t2 ON t.building_id = t2.building_id
- LEFT JOIN ta_person t6 ON t.person_id = t6.person_id
- LEFT JOIN ta_person t3 ON t6.recommend_person = t3.person_id
- 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}
- LEFT JOIN td_wx_dict t5 ON t4.scene_id = t5.scene_id
- <where>
- t.`status` > 0
- AND t.verify_status = 1
- AND ( t.realty_consultant IS NULL OR t.realty_consultant = '' )
- AND t.org_id = #{orgId}
- <if test="buildingId != null and buildingId !=''">
- and t.building_id = #{buildingId}
- </if>
- <if test="name != null and name !=''">
- and t.name like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and t.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and t.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and t.verify_status = #{verifyStatus}
- </if>
- <if test="sex != null and sex !=''">
- and t.sex = #{sex}
- </if>
- <if test="startCreateDate != null and startCreateDate !=''">
- and t.create_Date >= #{startCreateDate}
- </if>
- <if test="endCreateDate != null and endCreateDate !=''">
- and t.create_Date <= #{endCreateDate}
- </if>
- <if test="sharePersonName != null and sharePersonName !=''">
- and (t3.nickName like CONCAT('%',#{sharePersonName}, '%') or t3.name like CONCAT('%',#{sharePersonName},
- '%'))
- </if>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND t.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- <if test="sceneType !=null and sceneType !=''">
- and t4.scene_type = #{sceneType}
- </if>
- <if test="belongStatus == 0">
- and (t.building_id = '' OR t.building_id is null )
- </if>
- </where>
- order by t.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>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </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>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </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>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </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,
- IFNULL(d.user_name, b.name) as consultantName,
- IFNULL(d.phone, b.tel) as consultTel
- FROM
- ta_recommend_customer a
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_user d on a.realty_consultant = d.user_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 IFNULL(d.user_name, b.name) like CONCAT('%',#{consultName}, '%')
- </if>
- <if test="consultTel != null and consultTel !=''">
- and IFNULL(d.phone, 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>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </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.org_id = #{orgId} and a.recommend_person =
- b.person_id)
- </where>
- order by b.create_date desc
- </select>
-
- <select id="getPublicCustomerExportList" resultType="com.huiju.estateagents.excel.PublicCustomerExport">
- SELECT
- t.NAME AS nickname,
- t.phone,
- IF( t.sex = 1, '男', IF ( t.sex = 2, '女', '未知' ) ) AS sex,
- t.create_date,
- concat( t.country, t.province ) AS province,
- t.intention,
- IF(t.building_id = null or t.building_id = '','否','是') AS belongStatus,
- IFNULL( t2.building_name, '暂无' ) AS buildingName,
- t5.scene_alias as sceneType,
- ifnull( t3.nickname, t3.NAME ) AS sharePersonName ,
- t6.points
- FROM
- ta_recommend_customer t
- LEFT JOIN ta_building t2 ON t.building_id = t2.building_id
- LEFT JOIN ta_person t7 ON t.person_id = t7.person_id
- LEFT JOIN ta_person t3 ON t7.recommend_person = t3.person_id
- 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}
- LEFT JOIN td_wx_dict t5 ON t4.scene_id = t5.scene_id
- LEFT JOIN (select sum(points_amount) as points,person_id from ta_points_records where org_id = #{orgId} GROUP BY
- person_id) t6 on t.person_id = t6.person_id
- WHERE
- t.`status` > 0
- AND t.verify_status = 1
- AND ( t.realty_consultant IS NULL OR t.realty_consultant = '' )
- AND t.org_id = #{orgId}
- <if test="buildingId != null and buildingId !=''">
- and t.building_id = #{buildingId}
- </if>
- <if test="name != null and name !=''">
- and t.name like CONCAT('%',#{name}, '%')
- </if>
- <if test="tel != null and tel!=''">
- and t.phone like CONCAT('%',#{tel}, '%')
- </if>
- <if test="entryType != null and entryType !=''">
- and t.entry_type = #{entryType}
- </if>
- <if test="verifyStatus != null and verifyStatus !=''">
- and t.verify_status = #{verifyStatus}
- </if>
- <if test="sex != null and sex !=''">
- and t.sex = #{sex}
- </if>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND t.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- <if test="sceneType !=null and sceneType !=''">
- and t4.scene_type = #{sceneType}
- </if>
- <if test="belongStatus == 0">
- and (t.building_id = '' OR t.building_id is null )
- </if>
- </select>
- <!-- limit #{pageCode}, #{pageSize}-->
-
- <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>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </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,
- CASE
- WHEN b.NAME IS NULL THEN
- d.user_name ELSE b.NAME
- END AS consultantName,
- CASE
- WHEN b.tel IS NULL THEN
- d.phone ELSE b.tel
- END AS consultTel,
- t.building_name,
- z.intention,
- a.create_date,
- concat(tp.country, tp.province) as province,
- w.scene_alias as scene_type,
- IFNULL( c.NAME, c.nickname ) AS sharePersonName,
- s.points
- FROM
- ta_recommend_customer a
- left join ta_person tp on tp.person_id = a.person_id
- LEFT JOIN ta_person b ON a.realty_consultant = b.person_id
- LEFT JOIN ta_user d on d.user_id = a.realty_consultant
- 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}
- LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
- LEFT JOIN ta_person p2 ON a.person_id = p2.person_id
- LEFT JOIN ta_person c ON p2.recommend_person = c.person_id
- left join ta_building t on a.building_id = t.building_id
- -- LEFT JOIN ta_person c ON p.share_person_id = c.person_id
- -- left join ta_building t on a.building_id = t.building_id
- -- LEFT JOIN td_wx_dict w ON p.scene_id = w.scene_id
- left JOIN (select sum(points_amount) as points,person_id from ta_points_records where org_id = #{orgId} GROUP BY
- person_id) s on a.person_id = s.person_id
- 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
- <where>
- a.status > 0
- and a.verify_status = 1
- and a.realty_consultant is not null
- and a.realty_consultant != ''
- <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>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- <if test="sceneType !=null and sceneType !=''">
- and p.scene_type = #{sceneType}
- </if>
- </where>
- group by a.customer_id,a.building_id
- order by a.create_date desc
- </select>
- <!-- limit #{pageCode}, #{pageSize}-->
-
- <select id="getMyCustStatistics" resultType="java.util.Map">
- SELECT
- sum( IF ( STATUS = 4 AND verify_status = 1, 1, 0 ) ) AS clinchSum,
- sum( IF ( STATUS != 4 AND verify_status = 1, 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
- AND verify_status = 1
- <if test="name != null and name !=''">
- and (`name` like CONCAT('%',#{name}, '%') or phone 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( a.intention ) AS intention,
- a.building_id,
- b.building_name
- FROM
- ta_person_intention_record a
- left join ta_building b on a.building_id = b.building_id
- WHERE
- a.person_id = #{personId}
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- GROUP BY
- a.building_id
- ORDER BY
- intention DESC
- </select>
-
- <select id="getCustomersIRecommended" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- select a.*,b.avatarurl from ta_recommend_customer a left join ta_person b on a.person_id = b.person_id
- where a.recommend_person = #{customerId}
- and a.status >= #{status}
- and a.org_id = #{orgId}
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND a.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- </select>
-
- <select id="getCustomerListOfConsultant" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- select s.*, t.avatarurl, s.report_date as visit_time
- from ta_recommend_customer s
- left join ta_person t on t.person_id = s.person_id
- where s.org_id = #{orgId}
- and (s.realty_consultant = #{userId}
- <if test="personId != null">
- or s.realty_consultant = #{personId}
- </if>
- )
- <if test="startDate != null">
- and s.create_date BETWEEN #{startDate} and #{endDate}
- </if>
- <if test="buildingId != null and buildingId !=''">
- and s.building_id = #{buildingId}
- </if>
- and s.status > 0
- order by s.report_date desc
- </select>
-
- <select id="getConsultantCustomerList" resultType="com.huiju.estateagents.entity.TaRecommendCustomer">
- SELECT
- *
- FROM
- ta_recommend_customer t
- WHERE
- t.org_id = #{orgId}
- AND t.STATUS > 0
- AND t.verify_status = 1
- AND t.realty_consultant IN ( #{userId}, #{personId})
- </select>
-
-
- </mapper>
|