| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- <?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.goafanti.common.dao.DailySalesReportMapper">
- <resultMap id="BaseResultMap" type="com.goafanti.common.model.DailySalesReport">
- <id column="id" jdbcType="INTEGER" property="id" />
- <result column="admin_id" jdbcType="VARCHAR" property="adminId" />
- <result column="dep_id" jdbcType="VARCHAR" property="depId" />
- <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
- <result column="order_count" jdbcType="INTEGER" property="orderCount" />
- <result column="order_amount" jdbcType="DECIMAL" property="orderAmount" />
- </resultMap>
- <sql id="Base_Column_List">
- id, admin_id, dep_id, create_time, order_count, order_amount
- </sql>
- <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from daily_sales_report
- where id = #{id,jdbcType=INTEGER}
- </select>
-
- <select id="selectAdmins" resultMap="BaseResultMap">
- select a.id as admin_id, dm.id as dep_id
- from admin a
- left join department_management dm on dm.id = a.department_id
- </select>
-
- <select id="selectPersonalByPage" resultType="com.goafanti.report.bo.PersonalSalesReportBO">
- SELECT a.id, a.name, dm.name as departmentName, a.position, a.create_time as enrollTime
- FROM admin a
- left join department_management dm on dm.id = a.department_id
- where 1=1
- <if test="depName != null">
- and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
- </if>
- <if test="name != null">
- and a.name like concat(#{name,jdbcType=VARCHAR},'%')
- </if>
- <if test="position != null">
- and a.position like concat(#{position,jdbcType=VARCHAR},'%')
- </if>
- order by a.name asc
- <if test="pageNo != null and pageSize != null">
- limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
- </if>
- </select>
-
- <select id="selectDailySalesReports" resultMap="BaseResultMap">
- SELECT o.salesman_id as admin_id, a.department_id as dep_id,
- count(o.order_no) as order_count, sum(o.sign_total_amount) as order_amount
- FROM aft.t_order o
- left join aft.admin a on o.salesman_id=a.id
- where o.order_status=3 and o.sign_time >= #{startTime,jdbcType=TIMESTAMP} and o.sign_time < #{endTime,jdbcType=TIMESTAMP}
- group by o.salesman_id, a.department_id;
- </select>
-
- <delete id="deleteByDate">
- delete from daily_sales_report
- where create_time = #{createTime,jdbcType=TIMESTAMP}
- </delete>
-
- <insert id="insertBatch" parameterType="com.goafanti.common.model.DailySalesReport" >
- insert into daily_sales_report (admin_id, dep_id, order_count, order_amount, create_time)
- values
- <foreach item="item" index="index" collection="list" separator=",">
- (#{item.adminId,jdbcType=VARCHAR},
- #{item.depId,jdbcType=VARCHAR},
- #{item.orderCount,jdbcType=INTEGER},
- #{item.orderAmount,jdbcType=DECIMAL},
- #{item.createTime,jdbcType=TIMESTAMP})
- </foreach>
- </insert>
-
- <select id="selectSalesPersonalReports" resultType="com.goafanti.report.bo.PersonalSalesReportBO">
- SELECT a.id, a.name, dm.name as departmentName, a.position, a.create_time as enrollTime,
- sum(dsr.order_count) as ${countField}, sum(dsr.order_amount) as ${amountField}
- FROM admin a
- left join daily_sales_report dsr on dsr.admin_id = a.id
- left join department_management dm on dm.id = dsr.dep_id
- where dsr.create_time >= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time < #{endTime,jdbcType=TIMESTAMP}
- <if test="depName != null">
- and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
- </if>
- <if test="name != null">
- and a.name like concat(#{name,jdbcType=VARCHAR},'%')
- </if>
- <if test="position != null">
- and a.position like concat(#{position,jdbcType=VARCHAR},'%')
- </if>
- group by a.id, dsr.dep_id, dm.id
- order by ${orderField} ${order}, a.name asc
- <if test="pageNo != null and pageSize != null">
- limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
- </if>
- </select>
-
- <select id="selectSalesPersonalReportsCount" resultType="java.lang.Long">
- SELECT count(distinct(a.id))
- FROM admin a
- <if test="startTime != null and endTime != null">
- left join daily_sales_report dsr on dsr.admin_id = a.id
- </if>
- <if test="depName != null">
- left join department_management dm on dm.id = a.department_id
- </if>
- where 1=1
- <if test="startTime != null and endTime != null">
- and dsr.create_time >= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time < #{endTime,jdbcType=TIMESTAMP}
- </if>
- <if test="depName != null">
- and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
- </if>
- <if test="name != null">
- and a.name like concat(#{name,jdbcType=VARCHAR},'%')
- </if>
- <if test="position != null">
- and a.position like concat(#{position,jdbcType=VARCHAR},'%')
- </if>
- </select>
-
- <select id="selectSalesPersonalExtraReports" resultType="org.springframework.ui.ModelMap">
- SELECT dsr.admin_id as id, sum(dsr.order_count) as order_count, sum(dsr.order_amount) as order_amount
- FROM daily_sales_report dsr
- where dsr.create_time >= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time < #{endTime,jdbcType=TIMESTAMP}
- <if test="ids != null">
- and dsr.admin_id in
- <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- group by dsr.admin_id
- </select>
-
- <select id="selectSalesDepartmentReports" resultType="com.goafanti.report.bo.DepartmentSalesReportBO">
- SELECT dm.id, a.name as managerName, dm.name as departmentName, count(a2.id) as memberCount, dm.super_id as superId
- FROM department_management dm
- left join admin a2 on a2.department_id = dm.id
- left join admin a on a.id = dm.manager_id
- group by dm.id, a.id
- order by dm.name asc
- </select>
-
- <select id="selectSalesDepartmentExtraReports" resultType="org.springframework.ui.ModelMap">
- SELECT dsr.dep_id as id, sum(dsr.order_count) as order_count, sum(dsr.order_amount) as order_amount
- FROM daily_sales_report dsr
- where dsr.create_time >= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time < #{endTime,jdbcType=TIMESTAMP}
- group by dsr.dep_id
- </select>
-
- <select id="selectTotalReports" resultType="org.springframework.ui.ModelMap">
- SELECT sum(dsr.order_count) as totalCount, sum(dsr.order_amount) as totalAmount
- FROM admin a
- left join daily_sales_report dsr on dsr.admin_id = a.id
- <if test="depName != null">
- left join department_management dm on dm.id = a.department_id
- </if>
- where dsr.create_time >= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time < #{endTime,jdbcType=TIMESTAMP}
- <if test="depName != null">
- and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
- </if>
- <if test="name != null">
- and a.name like concat(#{name,jdbcType=VARCHAR},'%')
- </if>
- <if test="position != null">
- and a.position like concat(#{position,jdbcType=VARCHAR},'%')
- </if>
- </select>
-
- <select id="findmarketingStatisticsList" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
- select t1.id,t1.name,t1.departmentId,t1.departmentName,t1.manager_id,t1.departmentManagerName,
- t1.roleName,t1.privateCustomersCount,t1.entryTime,
- t2.yearFollowNo,t2.yearVisitNo,t2.yearTelNo,
- t2.monthFollowNo,t2.monthVisitNo,t2.monthTelNo,
- t2.weeklyFollowNo,t2.weeklyVisitNo,t2.weeklyTelNo,
- t2.dayFollowNo,t2.dayVisitNo,t2.dayTelNo
- from(
- select a.id as id,a.name as name,a.department_id as departmentId,d.name as departmentName,d.manager_id,f.name as departmentManagerName,
- c.role_name as roleName,ifnull(e.privateCustomersCount,0)as privateCustomersCount,a.create_time as entryTime
- from admin a left join user_role b
- on a.id=b.uid left join role c
- on b.rid=c.id left join department_management d
- on a.department_id=d.id left join (select aid,count(0) as privateCustomersCount from user where aid is not null and aid != '' group by aid)e
- on a.id=e.aid left join admin f
- on d.manager_id=f.id
- where c.role_name in ('营销员' ,'营销经理','营销管理员')
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- )t1
- left join (
- select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
- y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
- z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
- w.dayFollowNo,w.dayVisitNo,dayTelNo
- from (
- select
- aid,
- count(0) as yearFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
- from user_follow where 1=1
- and create_time > #{yearStart,jdbcType=VARCHAR}
- and create_time < #{yearEnd,jdbcType=VARCHAR}
- group by aid
- )x left join (
- select
- aid,
- count(0) as monthFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
- from user_follow where 1=1
- and create_time > #{monthStart,jdbcType=VARCHAR}
- and create_time < #{monthEnd,jdbcType=VARCHAR}
- group by aid
- )y on x.aid = y.aid
- left join (
- select
- aid,
- count(0) as weeklyFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
- from user_follow where 1=1
- and create_time > #{weeklyStart,jdbcType=VARCHAR}
- and create_time < #{weeklyEnd,jdbcType=VARCHAR}
- group by aid
- )z on y.aid = z.aid
- left join (
- select
- aid,
- count(0) as dayFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
- from user_follow where 1=1
- and create_time > #{dayStart,jdbcType=VARCHAR}
- and create_time < #{dayEnd,jdbcType=VARCHAR}
- group by aid
- )w on y.aid = w.aid
- )t2 on t1.id = t2.aid
- </select>
-
- <select id="marketingDepStatisticsList" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
- select t1.departmentId,t1.departmentName,t1.departmentManagerName,t1.privateCustomersCount,t1.departmentNumber,
- t2.yearFollowNo,t2.yearVisitNo,t2.yearTelNo,
- t2.monthFollowNo,t2.monthVisitNo,t2.monthTelNo,
- t2.weeklyFollowNo,t2.weeklyVisitNo,t2.weeklyTelNo,
- t2.dayFollowNo,t2.dayVisitNo,t2.dayTelNo ,
- t2.dayFollowNo/t1.departmentNumber as dayAVG
- from(select
- a.department_id as departmentId,
- b.name as departmentName,
- c.name as departmentManagerName,
- a.count2 as privateCustomersCount,
- d.count3 as departmentNumber
- from ( select
- z.department_id,
- sum( y.count1 ) as count2 from
- ( select aid, count( aid ) as count1
- from user
- where aid is not null and aid !=''
- group by aid
- ) y left join admin z on
- y.aid = z.id
- group by
- z.department_id
- ) a left join department_management b
- on a.department_id = b.id left join admin c
- on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
- on a.department_id = d.department_id
- where a.department_id is not null
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- )t1
- left join (
- select m.department_id as departmentId,sum(n.dayFollowNo)as dayFollowNo,sum(n.dayVisitNo)as dayVisitNo,sum(n.dayTelNo) as dayTelNo
- ,sum(n.weeklyFollowNo)as weeklyFollowNo,sum(n.weeklyVisitNo)as weeklyVisitNo,sum(n.weeklyTelNo) as weeklyTelNo
- ,sum(n.monthFollowNo)as monthFollowNo,sum(n.monthVisitNo)as monthVisitNo,sum(n.monthTelNo) as monthTelNo
- ,sum(n.yearFollowNo)as yearFollowNo,sum(n.yearVisitNo)as yearVisitNo,sum(n.yearTelNo) as yearTelNo
- from admin m left join
- (select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
- y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
- z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
- w.dayFollowNo,w.dayVisitNo,dayTelNo
- from (
- select
- aid,
- count(0) as yearFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
- from user_follow where 1=1
- and create_time > #{yearStart,jdbcType=VARCHAR}
- and create_time < #{yearEnd,jdbcType=VARCHAR}
- group by aid
- )x left join (
- select
- aid,
- count(0) as monthFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
- from user_follow where 1=1
- and create_time > #{monthStart,jdbcType=VARCHAR}
- and create_time < #{monthEnd,jdbcType=VARCHAR}
- group by aid
- )y on x.aid = y.aid
- left join (
- select
- aid,
- count(0) as weeklyFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
- from user_follow where 1=1
- and create_time > #{weeklyStart,jdbcType=VARCHAR}
- and create_time < #{weeklyEnd,jdbcType=VARCHAR}
- group by aid
- )z on y.aid = z.aid
- left join (
- select
- aid,
- count(0) as dayFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
- from user_follow where 1=1
- and create_time > #{dayStart,jdbcType=VARCHAR}
- and create_time < #{dayEnd,jdbcType=VARCHAR}
- group by aid
- )w on y.aid = w.aid) n on m.id=n.aid
- where m.department_id is not null and m.department_id !=''
- group by m.department_id
- )t2 on t1.departmentId = t2.departmentId
- ORDER by t1.departmentName
- </select>
- <select id="privateCustomersCount" parameterType="string" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
- select SUM( n.privateCustomersCount )as privateCustomersCount,
- SUM( m.dayFollowNo )as dayFollowNo,
- SUM( m.dayVisitNo )as dayVisitNo,
- SUM( m.dayTelNo )as dayTelNo,
- SUM( m.weeklyFollowNo )as weeklyFollowNo,
- SUM( m.weeklyVisitNo )as weeklyVisitNo,
- SUM( m.weeklyTelNo )as weeklyTelNo,
- SUM( m.monthFollowNo )as monthFollowNo,
- SUM( m.monthVisitNo )as monthVisitNo,
- SUM( m.monthTelNo )as monthTelNo,
- SUM( m.yearFollowNo )as yearFollowNo,
- SUM( m.yearVisitNo )as yearVisitNo,
- SUM( m.yearTelNo )as yearTelNo
-
- from(
- select a.id,sum(e.privateCustomersCount) as privateCustomersCount
- from admin a left join user_role b
- on a.id=b.uid left join role c
- on b.rid=c.id left join (select aid,count(0) as privateCustomersCount from user group by aid)e
- on a.id=e.aid where c.role_name in ('营销员','营销经理','营销管理员')
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- GROUP by a.id
- ) n left join (
- select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
- y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
- z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
- w.dayFollowNo,w.dayVisitNo,w.dayTelNo
- from (
- select
- aid,
- count(0) as yearFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
- from user_follow where 1=1
- and create_time > #{yearStart,jdbcType=VARCHAR}
- and create_time < #{yearEnd,jdbcType=VARCHAR}
- group by aid
- )x left join (
- select
- aid,
- count(0) as monthFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
- from user_follow where 1=1
- and create_time > #{monthStart,jdbcType=VARCHAR}
- and create_time < #{monthEnd,jdbcType=VARCHAR}
- group by aid
- )y on x.aid = y.aid
- left join (
- select
- aid,
- count(0) as weeklyFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
- from user_follow where 1=1
- and create_time > #{weeklyStart,jdbcType=VARCHAR}
- and create_time < #{weeklyEnd,jdbcType=VARCHAR}
- group by aid
- )z on y.aid = z.aid
- left join (
- select
- aid,
- count(0) as dayFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
- from user_follow where 1=1
- and create_time > #{dayStart,jdbcType=VARCHAR}
- and create_time < #{dayEnd,jdbcType=VARCHAR}
- group by aid
- )w on y.aid = w.aid
- )m on n.id=m.aid
- </select>
-
- <select id="privateCustomersDepCount" parameterType="String" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
- select sum(t1.privateCustomersCount) as privateCustomersCount,sum(t1.departmentNumber) as departmentNumber,
- sum(t2.yearFollowNo) as yearFollowNo,sum(t2.yearVisitNo) as yearVisitNo,sum(t2.yearTelNo) as yearTelNo,
- sum(t2.monthFollowNo) as monthFollowNo,sum(t2.monthVisitNo) as monthVisitNo,sum(t2.monthTelNo) as monthTelNo,
- sum(t2.weeklyFollowNo) as weeklyFollowNo,sum(t2.weeklyVisitNo) as weeklyVisitNo,sum(t2.weeklyTelNo) as weeklyTelNo,
- sum(t2.dayFollowNo) as dayFollowNo,sum(t2.dayVisitNo) as dayVisitNo,sum(t2.dayTelNo) as dayTelNo
- ,sum(t2.dayFollowNo)/sum(t1.departmentNumber) as dayAVG
- from(select
- a.department_id as departmentId,
- b.name as departmentName,
- c.name as departmentManagerName,
- a.count2 as privateCustomersCount,
- d.count3 as departmentNumber
- from ( select
- z.department_id,
- sum( y.count1 ) as count2 from
- ( select aid, count( aid ) as count1
- from user
- where aid is not null and aid !=''
- group by aid
- ) y left join admin z on
- y.aid = z.id
- group by
- z.department_id
- ) a left join department_management b
- on a.department_id = b.id left join admin c
- on b.manager_id=c.id left join (select department_id,count(0) as count3 from admin group by department_id)d
- on a.department_id = d.department_id
- where a.department_id is not null
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- )t1
- left join (
- select m.department_id as departmentId,sum(n.dayFollowNo)as dayFollowNo,sum(n.dayVisitNo)as dayVisitNo,sum(n.dayTelNo) as dayTelNo
- ,sum(n.weeklyFollowNo)as weeklyFollowNo,sum(n.weeklyVisitNo)as weeklyVisitNo,sum(n.weeklyTelNo) as weeklyTelNo
- ,sum(n.monthFollowNo)as monthFollowNo,sum(n.monthVisitNo)as monthVisitNo,sum(n.monthTelNo) as monthTelNo
- ,sum(n.yearFollowNo)as yearFollowNo,sum(n.yearVisitNo)as yearVisitNo,sum(n.yearTelNo) as yearTelNo
- from admin m left join
- (select x.aid,x.yearFollowNo,x.yearVisitNo,x.yearTelNo,
- y.monthFollowNo,y.monthVisitNo,y.monthTelNo,
- z.weeklyFollowNo,z.weeklyVisitNo,z.weeklyTelNo,
- w.dayFollowNo,w.dayVisitNo,dayTelNo
- from (
- select
- aid,
- count(0) as yearFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as yearVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as yearTelNo
- from user_follow where 1=1
- and create_time > #{yearStart,jdbcType=VARCHAR}
- and create_time < #{yearEnd,jdbcType=VARCHAR}
- group by aid
- )x left join (
- select
- aid,
- count(0) as monthFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as monthVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as monthTelNo
- from user_follow where 1=1
- and create_time > #{monthStart,jdbcType=VARCHAR}
- and create_time < #{monthEnd,jdbcType=VARCHAR}
- group by aid
- )y on x.aid = y.aid
- left join (
- select
- aid,
- count(0) as weeklyFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as weeklyVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as weeklyTelNo
- from user_follow where 1=1
- and create_time > #{weeklyStart,jdbcType=VARCHAR}
- and create_time < #{weeklyEnd,jdbcType=VARCHAR}
- group by aid
- )z on y.aid = z.aid
- left join (
- select
- aid,
- count(0) as dayFollowNo,
- ifnull(sum(case when contact_type = 0 then 1 else 0 end) ,0)as dayVisitNo,
- ifnull(sum(case when contact_type = 1 then 1 else 0 end) ,0)as dayTelNo
- from user_follow where 1=1
- and create_time > #{dayStart,jdbcType=VARCHAR}
- and create_time < #{dayEnd,jdbcType=VARCHAR}
- group by aid
- )w on y.aid = w.aid) n on m.id=n.aid
- where m.department_id is not null and m.department_id !=''
- group by m.department_id
- )t2 on t1.departmentId = t2.departmentId
- </select>
- <select id="sometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
- select a.id,a.name,d.name as departmentName,role_name as roleName,ifnull(e.telNo,0)as countTelNo,
- ifnull(e.visitNo,0)as countVisitNo,ifnull(e.followNo,0)as countFollowNo
- <if test="startTime !=null and endTime !=null">
- ,e.followNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as dayAVG
- </if>
- from admin a left join user_role b on
- a.id = b.uid left join role c on
- b.rid = c.id left join department_management d on
- a.department_id = d.id left join ( select
- a.aid,
- count( 0 ) as followNo,
- ifnull(
- sum( case when a.contact_type = 0 then 1 else 0 end ),
- 0
- ) as visitNo,
- ifnull(
- sum( case when a.contact_type = 1 then 1 else 0 end ),
- 0
- ) as telNo
- from user_follow a
- where
- 1 = 1
- <if test="startTime !=null">
- and a.create_time > #{startTime,jdbcType=VARCHAR}
- </if>
- <if test="endTime !=null">
- and a.create_time < #{endTime,jdbcType=VARCHAR}
- </if>
- GROUP BY a.aid)e on a.id=e.aid
- where c.role_name in ('营销员','营销经理','营销管理员')
- <if test="depId != null">
- and a.department_id= #{depId,jdbcType=VARCHAR}
- </if>
- order by a.name
- </select>
- <select id="sometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
- select z.id,z.name as departmentName,y.name as departmentManagerName,
- x.followNo as countFollowNo,x.visitNo as countVisitNo,x.telNo as countTelNo
- <if test="startTime !=null and endTime !=null">
- ,x.followNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as dayAVG
- </if>
- from (select b.department_id as departmentId,sum(a.followNo) as followNo,sum(a.visitNo)as visitNo,sum(a.telNo)as telNo
- from (select
- aid,
- count( 0 ) as followNo,
- ifnull(
- sum( case when contact_type = 0 then 1 else 0 end ),
- 0
- ) as visitNo,
- ifnull(
- sum( case when contact_type = 1 then 1 else 0 end ),
- 0
- ) as telNo
- from user_follow a where 1 = 1
- <if test="startTime !=null">
- and a.create_time > #{startTime,jdbcType=VARCHAR}
- </if>
- <if test="endTime !=null">
- and a.create_time < #{endTime,jdbcType=VARCHAR}
- </if>
- GROUP BY aid)a left join admin b on a.aid=b.id
- left join department_management c on b.department_id=c.id
- where b.department_id is not null and b.department_id !=''
- <if test="depId != null">
- and b.department_id=#{depId,jdbcType=VARCHAR}
- </if>
- GROUP by b.department_id
- ) x left join department_management z on x.departmentId=z.id
- left join admin y on z.manager_id=y.id
- </select>
- <select id="countsometimeMarketingStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
- select
- count( 0 ) as countFollowNo,
- ifnull(
- sum( case when a.contact_type = 0 then 1 else 0 end ),
- 0
- ) as countVisitNo,
- ifnull(
- sum( case when a.contact_type = 1 then 1 else 0 end ),
- 0
- ) as countTelNo
- <if test="startTime !=null and endTime !=null">
- ,count( 0 )/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as A
- </if>
- from
- user_follow a left join admin b on
- a.aid = b.id left join department_management c on
- b.department_id = c.id left join user_role d on
- b.id = d.uid left join role e on
- d.rid = e.id
- where 1 = 1
- and( e.role_name = '营销员' or e.role_name = '营销经理' or e.role_name = '营销管理员')
- <if test="depId != null">
- and a.department_id= #{depId,jdbcType=VARCHAR}
- </if>
- </select>
-
- <select id="countsometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
- select
- count( 0 ) as countFollowNo,
- ifnull(
- sum( case when a.contact_type = 0 then 1 else 0 end ),
- 0
- ) as countVisitNo,
- ifnull(
- sum( case when a.contact_type = 1 then 1 else 0 end ),
- 0
- ) as countTelNo
- <if test="startTime !=null and endTime !=null">
- ,count( 0 )/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as A
- </if>
- from
- user_follow a left join admin b on
- a.aid = b.id left join department_management c on
- b.department_id = c.id left join user_role d on
- b.id = d.uid left join role e on
- d.rid = e.id
- where 1 = 1
- and( e.role_name = '营销员' or e.role_name = '营销经理' or e.role_name = '营销管理员')
- <if test="depId != null">
- and a.department_id= #{depId,jdbcType=VARCHAR}
- </if>
- </select>
- </mapper>
|