123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- <?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.TaPersonMapper">
- <select id="selectCardList" resultType="java.util.HashMap">
- SELECT
- t.person_id AS id,
- t.name,
- t.company,
- t.department,
- t.post,
- t.tel AS phone,
- t.avatarurl AS avatar,
- t.photo
- FROM
- ta_person t
- LEFT JOIN ta_person_building p ON t.person_id = p.person_id
- WHERE
- t.person_type = #{personType}
- AND t.status = #{status}
- and t.org_id = #{orgId}
- <if test="buildingId != null and buildingId != ''">
- and p.building_id = #{buildingId}
- </if>
- ORDER BY
- t.create_date DESC
- </select>
-
- <select id="selectBuildingConsultants" resultType="java.util.HashMap">
- SELECT
- u.user_idAS id,
- u.user_name,
- u.org_name,
- u.department,
- u.position,
- u.phone,
- u.avatar,
- u.photo,
- u.description,
-
- FROM
- ta_person t
- JOIN ta_person_building s USING (user_id)
- left join ta_user u on t.user_id = u.user_id
- WHERE
- s.building_id = #{buildingId}
- AND t.person_type = #{personType}
- AND t. STATUS = #{status}
- ORDER BY
- t.create_date DESC
- </select>
-
- <select id="getSalesExecutive" resultType="com.huiju.estateagents.entity.TaPerson">
- SELECT
- *
- FROM
- ta_person t
- WHERE
- t.person_type = 'Sales Executive'
- AND t.status = 1
- LIMIT 1
- </select>
-
- <select id="getPersonByOpenId" resultType="com.huiju.estateagents.entity.TaPerson">
- SELECT
- *
- FROM
- ta_person t
- WHERE
- t.mini_openid = #{openId}
- AND IFNULL(t.status, 0) > -1
- </select>
-
- <update id="setFieldIncrement">
- UPDATE ta_person
- SET ${field} = IFNULL(${field}, 0) + #{increment}
- WHERE person_id = #{personId}
- </update>
-
- <select id="selectCustomer" resultType="com.huiju.estateagents.entity.TaPerson">
- SELECT
- a.*,
- b.event as event,
- b.activity as activity,
- b.data as data,
- (select b.visit_time FROM ta_person_visit_record b where a.person_id = b.person_id ORDER BY b.visit_time desc LIMIT 1) as visitTime
- FROM
- ta_person a
- LEFT JOIN ta_person_visit_record b ON a.person_id = b.person_id
- WHERE
- a.person_type IS NULL
- ORDER BY create_date desc
- </select>
-
- <select id="getById" resultType="com.huiju.estateagents.entity.TaPerson">
- SELECT
- a.*
- FROM
- ta_person a
- WHERE
- a.person_id = #{personId}
- </select>
-
- <select id="getUserProjects" resultType="java.lang.String">
- SELECT
- b.building_name
- FROM
- ta_person_building a
- LEFT JOIN ta_building b ON a.building_id = b.building_id
- WHERE a.person_id = #{personId}
- </select>
-
- <select id="selectByIdPerson" resultType="com.huiju.estateagents.entity.TaPerson">
- select * from ta_person where mini_openid = #{openid};
-
- </select>
-
- <select id="getConsultantByName" resultType="java.lang.String">
- select person_id from ta_person where name like CONCAT('%',#{name}, '%')
- </select>
-
- <select id="getConsultantByTel" resultType="java.lang.String">
- select person_id from ta_person where tel = #{tel}
- </select>
-
- <select id="selectCardListofMine" resultType="java.util.HashMap">
- SELECT
- t.person_id AS id,
- t.name,
- t.company,
- t.department,
- t.post,
- t.tel AS phone,
- t.avatarurl AS avatar,
- t.photo
- FROM
- ta_person t
- WHERE
- t.person_type = #{personType}
- AND t.status = #{status}
- <if test="personIds != null">
- and t.person_id in
- <foreach collection="personIds" item="personIds" index="index" open="(" close=")" separator=",">
- #{ordersId}
- </foreach>
- </if>
- ORDER BY
- t.create_date DESC
- </select>
-
-
- <select id="selectRecentlyCount" resultType="integer" >
- SELECT
- COUNT(1) as activity_count
- FROM
- ta_person tp
- where tp.org_id = #{org} AND
- ifnull(tp.person_type, '') != #{personType}
-
- <if test="startDate != null or endDate != null">
- AND tp.create_date BETWEEN #{startDate} and #{endDate}
- </if>
- <if test="startDate == null or endDate == null">
- AND tp.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
- </if>
- </select>
-
-
- <select id="selectUserBehavior" resultType="com.huiju.estateagents.po.PersonPO">
-
- SELECT
- temp_date.date as date,
- temp_date.type_name as activity,
- temp.activityCount as activityCount
- FROM
- (
- SELECT
- DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date, b.type_id, b.type_name
- from sequence a, td_biz_event_type b
-
- <trim prefix="where">
- <if test="startDate != null or endDate != null">
- a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
- </if>
- </trim>
-
- ) AS temp_date
-
- LEFT JOIN (
- SELECT
- COUNT(1) as activityCount,
- tpvr.event_type,
- DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' ) as date
- FROM
- ta_person tp
- INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
- where tp.org_id = #{org} AND ifnull(tp.person_type, '') != #{personType}
- <if test="buildingId != null and buildingId != ''">
- and tpvr.building_id = #{buildingId}
- </if>
- <if test="eventType != null and eventType != ''">
- and tpvr.event_type = #{eventType}
- </if>
- <if test="event != null and event != ''">
- and tpvr.event = #{event}
- </if>
- <if test="activity != null and activity != ''">
- and tpvr.activity = #{activity}
- </if>
-
- GROUP BY tpvr.event_type, DATE_FORMAT( tpvr.visit_time , '%Y-%m-%d' )
- ) AS temp ON temp_date.date = temp.date and temp_date.type_id = temp.event_type
- order by temp_date.date asc
- </select>
-
- <select id="selectActiveUserCount" resultType="map">
- SELECT
- temp_date.date as date,
- sum(temp.activity_count) as activity_count,
- temp.visit_time as visit_time
- FROM
- (
- SELECT
- <if test="dateType == 'day'.toString()">
- DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
- </if>
- <if test="dateType == 'week'.toString()">
- DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum WEEK ), '%Y-%m-%d' ) AS date
- </if>
- <if test="dateType == 'month'.toString()">
- DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum MONTH ), '%Y-%m' ) AS date
- </if>
- FROM
- sequence a
-
- <trim prefix="where">
- <if test="startDate != null or endDate != null">
- a.rownum <![CDATA[ < ]]> datediff(#{endDate}, #{startDate})
- </if>
- <if test="startDate == null or endDate == null">
- a.rownum <![CDATA[ < ]]> 7
- </if>
- </trim>
-
- ) AS temp_date
- LEFT JOIN (
- SELECT
- COUNT(1) as activity_count,
- tpvr.max_visit_time AS visit_time
- FROM
- ta_person tp
- LEFT JOIN
- ( SELECT *, MAX(visit_time) as max_visit_time FROM ta_person_visit_record GROUP BY person_id ) as tpvr
- ON tp.person_id = tpvr.person_id
- where tp.org_id = #{org} AND ifnull(tp.person_type, '') != #{personType}
- GROUP BY DATE_FORMAT( tpvr.max_visit_time , '%Y-%m-%d' )
- ) AS temp ON
- <if test="dateType == 'month'.toString()">
- temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m' ) GROUP BY temp_date.date ORDER BY temp_date.date
- </if>
- <if test="dateType == 'day'.toString()">
- temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' ) GROUP BY temp_date.date ORDER BY temp_date.date
- </if>
-
- </select>
-
- <select id="selectNewsUserCount" resultType="map">
- SELECT
- authorization_count_table.date as date,
- ifnull(authorization_count_table.authorization_count, 0) as authorization_count,
- ifnull(user_count_table.user_count, 0) as user_count
- FROM
- (
- SELECT
- *
- FROM
- (
- SELECT
- DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
- FROM
- sequence a
-
- <trim prefix="where">
- <if test="startDate != null or endDate != null">
- a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
- </if>
- </trim>
-
-
- ) AS temp_date
- LEFT JOIN (
-
- SELECT
- COUNT(1) as authorization_count,
- tp.create_date as create_date
- FROM
- ta_person tp
- where ifnull(tp.person_type, '') != #{personType}
- and tp.phone is NOT NULL
- <if test="startDate != null or endDate != null">
- AND tp.create_date BETWEEN #{startDate} and #{endDate}
- </if>
- <if test="startDate == null or endDate == null">
- AND tp.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
- </if>
- GROUP BY DATE_FORMAT( tp.create_date , '%Y-%m-%d' )
-
- ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
-
- ) as authorization_count_table
- ,
- (
- SELECT
- *
- FROM
- (
- SELECT
- DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
- FROM
- sequence a
-
- <trim prefix="where">
- <if test="startDate != null or endDate != null">
- a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
- </if>
- </trim>
-
- ) AS temp_date
- LEFT JOIN (
-
- SELECT
- COUNT(1) as user_count,
- tp.create_date as create_date
- FROM
- ta_person tp
- where tp.org_id = #{org} AND ifnull(tp.person_type, '') != #{personType}
- <if test="startDate != null or endDate != null">
- AND tp.create_date BETWEEN #{startDate} and #{endDate}
- </if>
- <if test="startDate == null or endDate == null">
- AND tp.create_date BETWEEN DATE_SUB(now(),INTERVAL 7 DAY) and now()
- </if>
- GROUP BY DATE_FORMAT( tp.create_date , '%Y-%m-%d' )
-
- ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
-
- ) as user_count_table
- where
- user_count_table.date = authorization_count_table.date
- GROUP BY date
- </select>
-
- <select id="selectUserSourcePie" resultType="integer">
- select count(1)
- FROM ta_person
- WHERE org_id = #{org} AND
- ifnull(person_type, '') != #{personType}
- <if test="recommendPersonType != null and recommendPersonType != ''">
- and recommend_person_type = #{recommendPersonType}
- </if>
- </select>
-
- <select id="selectUserSourceColumnar" resultType="map">
- SELECT
- tpf.from_name as from_name,
- (
- SELECT
- COUNT(1)
- FROM ta_person tps
- LEFT JOIN td_person_from tpfs
- ON tps.from_code = tpfs.from_code
- WHERE tpfs.from_code = tpf.from_code and tps.phone is NOT NULL
- AND tps.org_id = #{org}
- and ifnull(tps.person_type, '') != #{personType}
- <if test="startDate != null or endDate != null">
- and tps.create_date BETWEEN #{startDate} and #{endDate}
- </if>
- <if test="startDate == null or endDate == null">
- and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
- </if>
- ) as registered,
- (
- SELECT
- COUNT(1)
- FROM ta_person tps
- LEFT JOIN td_person_from tpfs
- ON tps.from_code = tpfs.from_code
- WHERE tpfs.from_code = tpf.from_code
- AND tps.org_id = #{org}
- and ifnull(tps.person_type, '') != #{personType}
- <if test="startDate != null or endDate != null">
- and tps.create_date BETWEEN #{startDate} and #{endDate}
- </if>
- <if test="startDate == null or endDate == null">
- and tps.create_date BETWEEN DATE_SUB( tps.create_date, INTERVAL 7 DAY ) and now()
- </if>
- ) as user_count
-
- FROM td_person_from tpf
- LEFT JOIN ta_person tp
- ON tp.from_code = tpf.from_code
- where tp.org_id = #{org} AND ifnull(tp.person_type, '') != #{personType}
- GROUP BY tpf.from_code
- </select>
-
- <select id="selectUserSourceData" resultType="map">
-
- select
- temp_date.date AS date,
- temp_date.from_name as from_name,
- temp_date.from_code as from_code,
- IFNULL(user_count.count, 0) as count,
- IFNULL(registered_count.count,0) as registered,
- user_count.create_date as create_date
- FROM
- (
- SELECT
- DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date,
- tempf.from_name as from_name,
- tempf.from_code as from_code
- FROM
- sequence a
- ,
- td_person_from tempf
-
- <trim prefix="where">
- <if test="startDate != null or endDate != null">
- a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
- </if>
- </trim>
-
- ) AS temp_date
-
- LEFT JOIN
- (
- SELECT
- ifnull(COUNT(1), 0) as count,
- tps.create_date as create_date,
- tpfs.from_code as from_code,
- tpfs.from_name as from_name
- FROM ta_person tps
- LEFT JOIN td_person_from tpfs
- ON tps.from_code = tpfs.from_code
- WHERE tpfs.from_code = tps.from_code
- AND tps.org_id = #{org}
- and ifnull(tps.person_type, '') != 'Realty Consultant'
- AND tps.create_date BETWEEN #{startDate} AND #{endDate}
-
- GROUP BY tpfs.from_code
- ) as user_count
- ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date and temp_date.from_code = user_count.from_code
- LEFT JOIN
- (
- SELECT
- ifnull(COUNT(1), 0) as count,
- tps.create_date as create_date,
- tpfs.from_code as from_code,
- tpfs.from_name as from_name
- FROM ta_person tps
- LEFT JOIN td_person_from tpfs
- ON tps.from_code = tpfs.from_code
- WHERE tpfs.from_code = tps.from_code
- AND tps.org_id = #{org}
- and ifnull(tps.person_type, '') != 'Realty Consultant'
- AND tps.create_date BETWEEN #{startDate} AND #{endDate}
- and tps.phone is not null
- GROUP BY tpfs.from_code
- ) as registered_count
- ON DATE_FORMAT(user_count.create_date,'%Y-%m-%d') = temp_date.date and temp_date.from_code = registered_count.from_code
- order by temp_date.date DESC
- </select>
-
- <select id="getPersonList" resultType="com.huiju.estateagents.entity.TaPerson">
- SELECT
- a.*
- FROM
- ta_person a
- LEFT JOIN ta_person_building b ON a.person_id = b.person_id
- <where>
- 1=1
- <if test="personType != null and personType!= ''">
- and a.person_type = #{personType}
- </if>
- <if test="name != null and name!= ''">
- and a.name like CONCAT('%',#{name}, '%')
- </if>
- <if test="personTags != null and personTags!= ''">
- and a.person_tags like CONCAT('%',#{personTags}, '%')
- </if>
- <if test="phone != null and phone!= ''">
- and a.tel = #{phone}
- </if>
- <if test="buildingId != null and buildingId!= ''">
- and b.building_id = #{buildingId}
- </if>
- <if test="status != null">
- and a.status = #{status}
- </if>
- </where>
- GROUP BY a.person_id
- </select>
-
- <select id="channelBrokerList" resultType="com.huiju.estateagents.entity.TaPerson">
- select
- p.person_id,
- p.avatarurl,
- p.tel,
- p.sex,
- rc.`name`,
- rc.phone,
- COUNT(rc.person_id) as recommendCount
- from ta_channel_person tch
- left join ta_person p on tch.person_id = p.person_id
- LEFT JOIN ta_recommend_customer rc ON p.person_id = rc.person_id and rc.report_recommend_status = 1
- <where>
- <if test="name !=null and name !=''">
- and rc.`name` = #{name}
- </if>
- <if test="phone !=null and phone !=''">
- and rc.phone = #{phone}
- </if>
- and p.org_id= #{orgid}
- and tch.channel_id = #{channelId}
- </where>
- GROUP BY tch.person_id
- </select>
-
- <select id="InviteClientsList" resultType="com.huiju.estateagents.entity.TaPerson">
- select * from ta_person WHERE recommend_agent = #{id}
- </select>
- </mapper>
|