| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- <?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 a.id ,a.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 group by aid)e
- on a.id=e.aid left join admin f
- on d.manager_id=f.id
- where 1=1
- and (c.role_name='营销员' or c.role_name='营销经理'or c.role_name='营销管理员')
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- order by a.name desc
- </select>
-
- <select id="marketingDepStatisticsList" parameterType="String" resultType="com.goafanti.report.bo.marketingESBo">
- select
- a.department_id as departmentId,
- b.name as departmentName,
- b.manager_id,
- c.name as departmentManagerName,
- a.count2 as privateCustomersCount,
- d.count3 as departmentNumber
- from
- (
- select
- z.department_id,
- sum( y.count1 ) as count2
- from
- (
- select
- a.id,
- count( a.id ) as count1
- from
- admin a left join user b on
- a.id = b.aid
- group by
- a.id
- ) y left join admin z on
- y.id = 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 1=1
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- order by b.name desc
-
- </select>
- <select id="privateCustomersCount" parameterType="string" resultType="com.goafanti.report.bo.CountMarketingStatisticsBo">
- select 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 department_management d
- on a.department_id=d.id left join (select aid,count(0) as privateCustomersCount from user group by aid)e
- on a.id=e.aid where 1=1
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- and (c.role_name='营销员' or c.role_name='营销经理'or c.role_name='营销管理员')
- </select>
-
- <select id="privateCustomersDepCount" parameterType="String" resultType="com.goafanti.report.bo.CountDepMarketingStatisticsBo">
- select
- sum(a.count2) as privateCustomersCount,
- sum(d.count3) as departmentNumber
- from
- (
- select
- z.department_id,
- sum( y.count1 ) as count2
- from
- (
- select
- a.id,
- count( a.id ) as count1
- from
- admin a left join user b on
- a.id = b.aid
- group by
- a.id
- ) y left join admin z on
- y.id = 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 1=1
- <if test="depId != null">
- and a.department_id = #{depId,jdbcType=VARCHAR}
- </if>
- </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">
- ,countFollowNo/datediff(#{endTime,jdbcType=VARCHAR},#{startTime,jdbcType=VARCHAR}) as AVG
- </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
- 1 = 1
- and(
- c.role_name = '营销员'
- or c.role_name = '营销经理'
- or c.role_name = '营销管理员'
- )
- <if test="depId != null">
- and a.department_id= #{depId,jdbcType=VARCHAR}
- </if>
- </select>
- <select id="sometimeMarketingDepStatistics" parameterType="String" resultType="com.goafanti.report.bo.SomeTimeMarketingBo">
- select
- a.department_id as departmentId,
- d.name as departmentName,
- f.name as departmentManagerName,
- d.manager_id,
- 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 AVG
- </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 admin f on
- d.manager_id=f.id left join (select
- b.department_id,
- 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 left join admin b on a.aid=b.id
- left join department_management c on b.department_id=c.id
- 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 b.department_id)e on a.department_id=e.department_id
- where
- 1 = 1
- and(
- c.role_name = '营销员'
- or c.role_name = '营销经理'
- or c.role_name = '营销管理员'
- )
- <if test="depId != null">
- and a.department_id= #{depId,jdbcType=VARCHAR}
- </if>
- group by a.department_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>
- </mapper>
|