123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- <?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.fs.statis.mapper.FsStatisQwWatchMapper">
- <resultMap id="BaseResultMap" type="com.fs.statis.domain.FsStatisQwWatch">
- <id column="id" jdbcType="BIGINT" property="id" />
- <result column="dept_id" jdbcType="BIGINT" property="deptId" />
- <result column="company_user_id" jdbcType="BIGINT" property="companyUserId" />
- <result column="qw_user_id" jdbcType="VARCHAR" property="qwUserId" />
- <result column="sop_task_num" jdbcType="BIGINT" property="sopTaskNum" />
- <result column="period_num" jdbcType="BIGINT" property="periodNum" />
- <result column="period_person_num" jdbcType="BIGINT" property="periodPersonNum" />
- <result column="completed_num" jdbcType="BIGINT" property="completedNum" />
- <result column="data_date" jdbcType="DATE" property="dataDate" />
- <result column="send_num" jdbcType="BIGINT" property="sendNum" />
- <result column="not_registered_num" jdbcType="BIGINT" property="notRegisteredNum" />
- <result column="interrupt_num" jdbcType="BIGINT" property="interruptNum" />
- <result column="registered_num" jdbcType="BIGINT" property="registeredNum" />
- <result column="qw_repeat_num" jdbcType="BIGINT" property="qwRepeatNum" />
- <result column="user_repeat_num" jdbcType="BIGINT" property="userRepeatNum" />
- <result column="black_num" jdbcType="BIGINT" property="blackNum" />
- <result column="deleted_num" jdbcType="BIGINT" property="deletedNum" />
- <result column="order_num" jdbcType="BIGINT" property="orderNum" />
- <result column="order_money_total" jdbcType="DECIMAL" property="orderMoneyTotal" />
- <result column="red_package_money_total" jdbcType="DECIMAL" property="redPackageMoneyTotal" />
- <result column="call_num" jdbcType="BIGINT" property="callNum" />
- <result column="receive_pass_num" jdbcType="BIGINT" property="receivePassNum" />
- <result column="receive_not_num" jdbcType="BIGINT" property="receiveNotNum" />
- <result column="call_time_total" jdbcType="BIGINT" property="callTimeTotal" />
- <result column="remind_pending_num" jdbcType="BIGINT" property="remindPendingNum" />
- <result column="remind_processed_num" jdbcType="BIGINT" property="remindProcessedNum" />
- <result column="reg_rate" jdbcType="DECIMAL" property="regRate" />
- <result column="finished_rate" jdbcType="DECIMAL" property="finishedRate" />
- </resultMap>
- <sql id="Base_Column_List">
- id, dept_id, company_user_id, qw_user_id, sop_task_num, period_num, period_person_num,
- completed_num, data_date, send_num, not_registered_num, interrupt_num, registered_num,
- qw_repeat_num, user_repeat_num, black_num, deleted_num, order_num, order_money_total,
- red_package_money_total, call_num, receive_pass_num, receive_not_num, call_time_total,
- remind_pending_num, remind_processed_num, reg_rate, finished_rate
- </sql>
- <!-- Columns that can be inserted (excludes auto-increment and generated columns) -->
- <sql id="Insert_Column_List">
- dept_id, company_user_id, qw_user_id, sop_task_num, period_num, period_person_num,
- completed_num, data_date, send_num, not_registered_num, interrupt_num, qw_repeat_num,
- user_repeat_num, black_num, deleted_num, order_num, order_money_total,
- red_package_money_total, call_num, receive_pass_num, receive_not_num, call_time_total,
- remind_pending_num, remind_processed_num
- </sql>
- <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from fs_statis_qw_watch
- where id = #{id,jdbcType=BIGINT}
- </select>
- <select id="selectByUniqueKey" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from fs_statis_qw_watch
- where dept_id = #{deptId,jdbcType=BIGINT}
- and company_user_id = #{companyUserId,jdbcType=BIGINT}
- and qw_user_id = #{qwUserId,jdbcType=VARCHAR}
- and data_date = #{dataDate,jdbcType=DATE}
- </select>
- <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
- delete from fs_statis_qw_watch
- where id = #{id,jdbcType=BIGINT}
- </delete>
- <insert id="insert" keyProperty="id" useGeneratedKeys="true" parameterType="com.fs.statis.domain.FsStatisQwWatch">
- insert into fs_statis_qw_watch (
- <include refid="Insert_Column_List" />
- )
- values (
- #{deptId,jdbcType=BIGINT}, #{companyUserId,jdbcType=BIGINT}, #{qwUserId,jdbcType=VARCHAR},
- #{sopTaskNum,jdbcType=BIGINT}, #{periodNum,jdbcType=BIGINT}, #{periodPersonNum,jdbcType=BIGINT},
- #{completedNum,jdbcType=BIGINT}, #{dataDate,jdbcType=DATE}, #{sendNum,jdbcType=BIGINT},
- #{notRegisteredNum,jdbcType=BIGINT}, #{interruptNum,jdbcType=BIGINT},
- #{qwRepeatNum,jdbcType=BIGINT}, #{userRepeatNum,jdbcType=BIGINT}, #{blackNum,jdbcType=BIGINT},
- #{deletedNum,jdbcType=BIGINT}, #{orderNum,jdbcType=BIGINT}, #{orderMoneyTotal,jdbcType=DECIMAL},
- #{redPackageMoneyTotal,jdbcType=DECIMAL}, #{callNum,jdbcType=BIGINT}, #{receivePassNum,jdbcType=BIGINT},
- #{receiveNotNum,jdbcType=BIGINT}, #{callTimeTotal,jdbcType=BIGINT}, #{remindPendingNum,jdbcType=BIGINT},
- #{remindProcessedNum,jdbcType=BIGINT}
- )
- </insert>
- <insert id="insertSelective" keyProperty="id" useGeneratedKeys="true" parameterType="com.fs.statis.domain.FsStatisQwWatch">
- insert into fs_statis_qw_watch
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="deptId != null">dept_id,</if>
- <if test="companyUserId != null">company_user_id,</if>
- <if test="qwUserId != null">qw_user_id,</if>
- <if test="sopTaskNum != null">sop_task_num,</if>
- <if test="periodNum != null">period_num,</if>
- <if test="periodPersonNum != null">period_person_num,</if>
- <if test="completedNum != null">completed_num,</if>
- <if test="dataDate != null">data_date,</if>
- <if test="sendNum != null">send_num,</if>
- <if test="notRegisteredNum != null">not_registered_num,</if>
- <if test="interruptNum != null">interrupt_num,</if>
- <if test="qwRepeatNum != null">qw_repeat_num,</if>
- <if test="userRepeatNum != null">user_repeat_num,</if>
- <if test="blackNum != null">black_num,</if>
- <if test="deletedNum != null">deleted_num,</if>
- <if test="orderNum != null">order_num,</if>
- <if test="orderMoneyTotal != null">order_money_total,</if>
- <if test="redPackageMoneyTotal != null">red_package_money_total,</if>
- <if test="callNum != null">call_num,</if>
- <if test="receivePassNum != null">receive_pass_num,</if>
- <if test="receiveNotNum != null">receive_not_num,</if>
- <if test="callTimeTotal != null">call_time_total,</if>
- <if test="remindPendingNum != null">remind_pending_num,</if>
- <if test="remindProcessedNum != null">remind_processed_num,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="deptId != null">#{deptId,jdbcType=BIGINT},</if>
- <if test="companyUserId != null">#{companyUserId,jdbcType=BIGINT},</if>
- <if test="qwUserId != null">#{qwUserId,jdbcType=VARCHAR},</if>
- <if test="sopTaskNum != null">#{sopTaskNum,jdbcType=BIGINT},</if>
- <if test="periodNum != null">#{periodNum,jdbcType=BIGINT},</if>
- <if test="periodPersonNum != null">#{periodPersonNum,jdbcType=BIGINT},</if>
- <if test="completedNum != null">#{completedNum,jdbcType=BIGINT},</if>
- <if test="dataDate != null">#{dataDate,jdbcType=DATE},</if>
- <if test="sendNum != null">#{sendNum,jdbcType=BIGINT},</if>
- <if test="notRegisteredNum != null">#{notRegisteredNum,jdbcType=BIGINT},</if>
- <if test="interruptNum != null">#{interruptNum,jdbcType=BIGINT},</if>
- <if test="qwRepeatNum != null">#{qwRepeatNum,jdbcType=BIGINT},</if>
- <if test="userRepeatNum != null">#{userRepeatNum,jdbcType=BIGINT},</if>
- <if test="blackNum != null">#{blackNum,jdbcType=BIGINT},</if>
- <if test="deletedNum != null">#{deletedNum,jdbcType=BIGINT},</if>
- <if test="orderNum != null">#{orderNum,jdbcType=BIGINT},</if>
- <if test="orderMoneyTotal != null">#{orderMoneyTotal,jdbcType=DECIMAL},</if>
- <if test="redPackageMoneyTotal != null">#{redPackageMoneyTotal,jdbcType=DECIMAL},</if>
- <if test="callNum != null">#{callNum,jdbcType=BIGINT},</if>
- <if test="receivePassNum != null">#{receivePassNum,jdbcType=BIGINT},</if>
- <if test="receiveNotNum != null">#{receiveNotNum,jdbcType=BIGINT},</if>
- <if test="callTimeTotal != null">#{callTimeTotal,jdbcType=BIGINT},</if>
- <if test="remindPendingNum != null">#{remindPendingNum,jdbcType=BIGINT},</if>
- <if test="remindProcessedNum != null">#{remindProcessedNum,jdbcType=BIGINT},</if>
- </trim>
- </insert>
- <update id="updateByPrimaryKeySelective" parameterType="com.fs.statis.domain.FsStatisQwWatch">
- update fs_statis_qw_watch
- <set>
- <if test="deptId != null">dept_id = #{deptId,jdbcType=BIGINT},</if>
- <if test="companyUserId != null">company_user_id = #{companyUserId,jdbcType=BIGINT},</if>
- <if test="qwUserId != null">qw_user_id = #{qwUserId,jdbcType=VARCHAR},</if>
- <if test="sopTaskNum != null">sop_task_num = #{sopTaskNum,jdbcType=BIGINT},</if>
- <if test="periodNum != null">period_num = #{periodNum,jdbcType=BIGINT},</if>
- <if test="periodPersonNum != null">period_person_num = #{periodPersonNum,jdbcType=BIGINT},</if>
- <if test="completedNum != null">completed_num = #{completedNum,jdbcType=BIGINT},</if>
- <if test="dataDate != null">data_date = #{dataDate,jdbcType=DATE},</if>
- <if test="sendNum != null">send_num = #{sendNum,jdbcType=BIGINT},</if>
- <if test="notRegisteredNum != null">not_registered_num = #{notRegisteredNum,jdbcType=BIGINT},</if>
- <if test="interruptNum != null">interrupt_num = #{interruptNum,jdbcType=BIGINT},</if>
- <if test="qwRepeatNum != null">qw_repeat_num = #{qwRepeatNum,jdbcType=BIGINT},</if>
- <if test="userRepeatNum != null">user_repeat_num = #{userRepeatNum,jdbcType=BIGINT},</if>
- <if test="blackNum != null">black_num = #{blackNum,jdbcType=BIGINT},</if>
- <if test="deletedNum != null">deleted_num = #{deletedNum,jdbcType=BIGINT},</if>
- <if test="orderNum != null">order_num = #{orderNum,jdbcType=BIGINT},</if>
- <if test="orderMoneyTotal != null">order_money_total = #{orderMoneyTotal,jdbcType=DECIMAL},</if>
- <if test="redPackageMoneyTotal != null">red_package_money_total = #{redPackageMoneyTotal,jdbcType=DECIMAL},</if>
- <if test="callNum != null">call_num = #{callNum,jdbcType=BIGINT},</if>
- <if test="receivePassNum != null">receive_pass_num = #{receivePassNum,jdbcType=BIGINT},</if>
- <if test="receiveNotNum != null">receive_not_num = #{receiveNotNum,jdbcType=BIGINT},</if>
- <if test="callTimeTotal != null">call_time_total = #{callTimeTotal,jdbcType=BIGINT},</if>
- <if test="remindPendingNum != null">remind_pending_num = #{remindPendingNum,jdbcType=BIGINT},</if>
- <if test="remindProcessedNum != null">remind_processed_num = #{remindProcessedNum,jdbcType=BIGINT},</if>
- </set>
- where id = #{id,jdbcType=BIGINT}
- </update>
- <update id="updateByPrimaryKey" parameterType="com.fs.statis.domain.FsStatisQwWatch">
- update fs_statis_qw_watch
- set dept_id = #{deptId,jdbcType=BIGINT},
- company_user_id = #{companyUserId,jdbcType=BIGINT},
- qw_user_id = #{qwUserId,jdbcType=VARCHAR},
- sop_task_num = #{sopTaskNum,jdbcType=BIGINT},
- period_num = #{periodNum,jdbcType=BIGINT},
- period_person_num = #{periodPersonNum,jdbcType=BIGINT},
- completed_num = #{completedNum,jdbcType=BIGINT},
- data_date = #{dataDate,jdbcType=DATE},
- send_num = #{sendNum,jdbcType=BIGINT},
- not_registered_num = #{notRegisteredNum,jdbcType=BIGINT},
- interrupt_num = #{interruptNum,jdbcType=BIGINT},
- qw_repeat_num = #{qwRepeatNum,jdbcType=BIGINT},
- user_repeat_num = #{userRepeatNum,jdbcType=BIGINT},
- black_num = #{blackNum,jdbcType=BIGINT},
- deleted_num = #{deletedNum,jdbcType=BIGINT},
- order_num = #{orderNum,jdbcType=BIGINT},
- order_money_total = #{orderMoneyTotal,jdbcType=DECIMAL},
- red_package_money_total = #{redPackageMoneyTotal,jdbcType=DECIMAL},
- call_num = #{callNum,jdbcType=BIGINT},
- receive_pass_num = #{receivePassNum,jdbcType=BIGINT},
- receive_not_num = #{receiveNotNum,jdbcType=BIGINT},
- call_time_total = #{callTimeTotal,jdbcType=BIGINT},
- remind_pending_num = #{remindPendingNum,jdbcType=BIGINT},
- remind_processed_num = #{remindProcessedNum,jdbcType=BIGINT}
- where id = #{id,jdbcType=BIGINT}
- </update>
- <select id="selectList" parameterType="com.fs.statis.domain.FsStatisQwWatch" resultMap="BaseResultMap">
- select
- <include refid="Base_Column_List" />
- from fs_statis_qw_watch
- <where>
- <if test="deptId != null">and dept_id = #{deptId,jdbcType=BIGINT}</if>
- <if test="companyUserId != null">and company_user_id = #{companyUserId,jdbcType=BIGINT}</if>
- <if test="qwUserId != null and qwUserId != ''">and qw_user_id = #{qwUserId,jdbcType=VARCHAR}</if>
- <if test="dataDate != null">and data_date = #{dataDate,jdbcType=DATE}</if>
- <!-- Add other conditions as needed -->
- </where>
- <!-- Add order by or limit clauses if necessary -->
- </select>
- <select id="queryList" resultType="com.fs.statis.domain.FsStatisQwWatch">
- select
- dept_id,
- company_user_id,
- qw_user_id,
- ifnull(sum(sop_task_num),0) as sop_task_num,
- ifnull(sum(period_num),0) as period_num,
- ifnull(sum(period_person_num),0) as period_person_num,
- ifnull(sum(completed_num),0) as completed_num,
- ifnull(sum(send_num),0) as send_num,
- ifnull(sum(not_registered_num),0) as not_registered_num,
- ifnull(sum(interrupt_num),0) as interrupt_num,
- ifnull(sum(registered_num),0) as registered_num,
- ifnull(sum(qw_repeat_num),0) as qw_repeat_num,
- ifnull(sum(user_repeat_num),0) as user_repeat_num,
- ifnull(sum(black_num),0) as black_num,
- ifnull(sum(deleted_num),0) as deleted_num,
- ifnull(sum(order_num),0) as order_num,
- ifnull(sum(order_money_total),0) as order_money_total,
- ifnull(sum(red_package_money_total),0) as red_package_money_total,
- ifnull(sum(call_num),0) as call_num,
- ifnull(sum(receive_pass_num),0) as receive_pass_num,
- ifnull(sum(receive_not_num),0) as receive_not_num,
- ifnull(sum(call_time_total),0) as call_time_total,
- ifnull(sum(remind_pending_num),0) as remind_pending_num,
- ifnull(sum(remind_processed_num),0) as remind_processed_num,
- (case when sum(send_num)>=sum(registered_num) then ROUND(SUM(registered_num) * 1.0 / SUM(send_num), 4) else 0 end) as reg_rate,
- (case when sum(send_num)>=sum(completed_num) then ROUND(SUM(completed_num) * 1.0 / SUM(send_num), 4) else 0 end) as finished_rate,
- ifnull(sum(traffic_sum,0)) as traffic_sum,
- ifnull(sum(reg_num,0)) as reg_num
- from fs_statis_qw_watch
- <where>
- <if test="startDate != null and endDate != null">
- AND data_date between #{startDate} and #{endDate}
- </if>
- <if test="userIds != null and userIds.size() > 0">
- AND company_user_id in
- <foreach collection="userIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </where>
- group by company_user_id
- </select>
- <select id="exportList" resultType="com.fs.statis.domain.FsStatisQwWatch">
- select
- any_value(watch.dept_id),
- concat(dept.dept_id,'_',dept.dept_name) as dept_name,
- watch.company_user_id,
- concat(cu.user_id,'_',cu.user_name) as company_user_name,
- ifnull(sum(watch.sop_task_num),0) as sop_task_num,
- ifnull(sum(watch.period_num),0) as period_num,
- ifnull(sum(watch.period_person_num),0) as period_person_num,
- ifnull(sum(watch.completed_num),0) as completed_num,
- ifnull(sum(watch.send_num),0) as send_num,
- ifnull(sum(watch.not_registered_num),0) as not_registered_num,
- ifnull(sum(watch.interrupt_num),0) as interrupt_num,
- ifnull(sum(watch.registered_num),0) as registered_num,
- ifnull(sum(watch.qw_repeat_num),0) as qw_repeat_num,
- ifnull(sum(watch.user_repeat_num),0) as user_repeat_num,
- ifnull(sum(watch.black_num),0) as black_num,
- ifnull(sum(watch.deleted_num),0) as deleted_num,
- ifnull(sum(watch.order_num),0) as order_num,
- ifnull(sum(watch.order_money_total),0) as order_money_total,
- ifnull(sum(watch.red_package_money_total),0) as red_package_money_total,
- ifnull(sum(watch.call_num),0) as call_num,
- ifnull(sum(watch.receive_pass_num),0) as receive_pass_num,
- ifnull(sum(watch.receive_not_num),0) as receive_not_num,
- ifnull(sum(watch.call_time_total),0) as call_time_total,
- ifnull(sum(watch.remind_pending_num),0) as remind_pending_num,
- ifnull(sum(watch.remind_processed_num),0) as remind_processed_num,
- (case when sum(watch.send_num)>=sum(watch.registered_num) then ROUND(SUM(watch.registered_num) * 1.0 / SUM(watch.send_num), 4) else 0 end) as reg_rate,
- (case when sum(watch.send_num)>=sum(watch.completed_num) then ROUND(SUM(watch.completed_num) * 1.0 / SUM(watch.send_num), 4) else 0 end) as finished_rate,
- ifnull(sum(traffic_sum,0)) as traffic_sum,
- ifnull(sum(reg_num,0)) as reg_num
- from fs_statis_qw_watch watch
- left join company_dept dept on watch.dept_id=dept.dept_id
- left join company_user cu on watch.company_user_id=cu.user_id
- <where>
- <if test="startDate != null and endDate != null">
- AND watch.data_date between #{startDate} and #{endDate}
- </if>
- <if test="userIds != null and userIds.size() > 0">
- AND watch.company_user in
- <foreach collection="userIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- </where>
- group by watch.company_user_id
- </select>
- <insert id="batchInsert" parameterType="java.util.List">
- replace into fs_statis_qw_watch (
- <include refid="Insert_Column_List" />
- )
- values
- <foreach collection="list" item="item" index="index" separator=",">
- (
- #{item.deptId,jdbcType=BIGINT}, #{item.companyUserId,jdbcType=BIGINT}, #{item.qwUserId,jdbcType=VARCHAR},
- #{item.sopTaskNum,jdbcType=BIGINT}, #{item.periodNum,jdbcType=BIGINT}, #{item.periodPersonNum,jdbcType=BIGINT},
- #{item.completedNum,jdbcType=BIGINT}, #{item.dataDate,jdbcType=DATE}, #{item.sendNum,jdbcType=BIGINT},
- #{item.notRegisteredNum,jdbcType=BIGINT}, #{item.interruptNum,jdbcType=BIGINT},
- #{item.qwRepeatNum,jdbcType=BIGINT}, #{item.userRepeatNum,jdbcType=BIGINT}, #{item.blackNum,jdbcType=BIGINT},
- #{item.deletedNum,jdbcType=BIGINT}, #{item.orderNum,jdbcType=BIGINT}, #{item.orderMoneyTotal,jdbcType=DECIMAL},
- #{item.redPackageMoneyTotal,jdbcType=DECIMAL}, #{item.callNum,jdbcType=BIGINT}, #{item.receivePassNum,jdbcType=BIGINT},
- #{item.receiveNotNum,jdbcType=BIGINT}, #{item.callTimeTotal,jdbcType=BIGINT}, #{item.remindPendingNum,jdbcType=BIGINT},
- #{item.remindProcessedNum,jdbcType=BIGINT},#{item.trafficSum,jdbcType=BIGINT},#{item.regNum,jdbcType=BIGINT}
- )
- </foreach>
- </insert>
- <insert id="generateData">
- <![CDATA[
- REPLACE INTO fs_statis_qw_watch(
- company_user_id,
- data_date,
- qw_user_id,
- send_num,
- period_num,
- period_person_num,
- not_registered_num,
- completed_num,
- interrupt_num,
- dept_id,
- black_num,
- deleted_num,
- order_num,
- order_money_total,
- red_package_money_total,
- receive_pass_num,
- receive_not_num,
- call_time_total,
- remind_pending_num,
- remind_processed_num,
- qw_repeat_num,
- user_repeat_num,
- traffic_sum,
- reg_num
- )
- WITH extended_temp AS (
- -- 原始temp表数据
- SELECT company_user_id, qw_user_id, this_date, dept_id
- FROM fs_statis_qw_temp_param
- WHERE this_date IS NOT NULL
- UNION
- -- 添加订单统计维度的记录
- SELECT DISTINCT
- o.company_user_id,
- '-1' as qw_user_id,
- #{date} as this_date,
- cu.dept_id as dept_id
- FROM fs_store_order o
- left join company_user cu
- on o.company_user_id=cu.user_id
- WHERE o.status in (4,5)
- AND o.company_user_id IS NOT NULL
- AND o.create_time >= #{startTime}
- AND o.create_time < #{endTime}
- UNION
- -- 添加红包统计维度的记录
- SELECT DISTINCT
- log.company_user_id,
- '-1' as qw_user_id,
- #{date} as this_date,
- cu.dept_id as dept_id
- FROM fs_course_red_packet_log log
- left join company_user cu
- on log.company_user_id=cu.user_id
- WHERE log.status = 1
- AND log.create_time >= #{startTime}
- AND log.create_time < #{endTime}
- )
- SELECT
- temp.company_user_id as company_user_id,
- temp.this_date as data_date,
- temp.qw_user_id as qw_user_id,
- IFNULL(log_stats.send_count, 0) as send_num,
- IFNULL(log_stats.period_count, 0) as period_num,
- IFNULL(log_stats.period_person_count, 0) as period_person_num,
- IFNULL(log_stats.not_register_count, 0) as not_registered_num,
- IFNULL(log_stats.completed_count, 0) as completed_num,
- IFNULL(log_stats.interrupt_count, 0) as interrupt_num,
- temp.dept_id as dept_id,
- IFNULL(contact.black_num, 0) as black_num,
- IFNULL(contact.deleted_num, 0) as deleted_num,
- IFNULL(stats_order.order_num, 0) as order_num,
- IFNULL(stats_order.order_money_total, 0) as order_money_total,
- IFNULL(redp.red_package_money_total, 0) as red_package_money_total,
- IFNULL(voice.receive_pass_num, 0) as receive_pass_num,
- IFNULL(voice.receive_not_num, 0) as receive_not_num,
- IFNULL(voice.call_time_total, 0) as call_time_total,
- IFNULL(qw_work.remind_pending_num, 0) as remind_pending_num,
- IFNULL(qw_work.remind_processed_num, 0) as remind_processed_num,
- IFNULL(contact.qw_repeat_num,0) as qw_repeat_num,
- IFNULL(contact.user_repeat_num,0) as user_repeat_num,
- IFNULL(traffic.traffic_sum,0) as traffic_sum,
- IFNULL(fs_user.reg_num,0) as reg_num
- FROM extended_temp temp
- LEFT JOIN (
- SELECT
- company_user_id,
- qw_user_id,
- COUNT(DISTINCT log_id) as send_count,
- COUNT(DISTINCT sop_id) as period_count,
- COUNT(DISTINCT CASE WHEN sop_id is not null then qw_external_contact_id END) as period_person_count,
- COUNT(DISTINCT CASE WHEN log_type = 3 THEN log_id END) as not_register_count,
- COUNT(DISTINCT CASE WHEN log_type = 2 THEN log_id END) as completed_count,
- COUNT(DISTINCT CASE WHEN (log_type = 4 OR log_type = 1) THEN log_id END) as interrupt_count
- FROM fs_course_watch_log
- WHERE ((update_time >= #{startTime} and update_time < #{endTime}) OR (create_time >= #{startTime} and create_time < #{endTime}))
- GROUP BY company_user_id, qw_user_id
- ) log_stats ON temp.company_user_id = log_stats.company_user_id
- AND temp.qw_user_id = log_stats.qw_user_id
- -- 拉黑数和删除数
- LEFT JOIN (
- SELECT
- contact.company_user_id,
- contact.qw_user_id,
- COUNT(CASE WHEN contact.status = 4 THEN 1 END) as black_num,
- COUNT(CASE WHEN contact.status = 5 OR contact.status = 7 THEN 1 END) as deleted_num,
- COUNT(contact.is_repeat) as qw_repeat_num,
- COUNT(contact.user_repeat) as user_repeat_num
- FROM qw_external_contact contact
- WHERE contact.qw_user_id IS NOT NULL
- AND contact.company_user_id IS NOT NULL
- AND contact.status IN (4, 5, 7)
- AND contact.update_time >= #{startTime}
- AND contact.update_time < #{endTime}
- GROUP BY company_user_id,qw_user_id
- ) contact ON contact.qw_user_id = temp.qw_user_id
- AND contact.company_user_id = temp.company_user_id
- -- 订单数、订单总金额
- LEFT JOIN (
- SELECT
- COUNT(DISTINCT order_id) as order_num,
- SUM(pay_money) as order_money_total,
- company_user_id,
- '-1' as qw_user_id
- FROM fs_store_order
- WHERE status = 5
- AND company_user_id IS NOT NULL
- AND create_time >= #{startTime}
- AND create_time < #{endTime}
- GROUP BY company_user_id,qw_user_id
- ) stats_order ON temp.company_user_id = stats_order.company_user_id
- AND temp.qw_user_id = '-1'
- -- 红包数
- LEFT JOIN (
- SELECT
- company_user_id,
- sum(amount) as red_package_money_total,
- '-1' as qw_user_id
- FROM fs_course_red_packet_log
- WHERE status = 1
- AND create_time >= #{startTime}
- AND create_time < #{endTime}
- GROUP BY company_user_id,qw_user_id
- ) redp ON temp.company_user_id = redp.company_user_id
- AND temp.qw_user_id = '-1'
- -- 通话统计(总拨打数(可以后面两项相加)、接通数、未接通数、通话时长)
- LEFT JOIN (
- SELECT
- company_user_id,
- qw_user_id,
- COUNT(CASE WHEN status = 1 THEN 1 END) as receive_pass_num,
- COUNT(CASE WHEN status = 2 THEN 1 END) as receive_not_num,
- SUM(CASE WHEN status = 1 THEN duration END) as call_time_total
- FROM qw_user_voice_log
- WHERE create_time >= #{startTime}
- AND create_time < #{endTime}
- GROUP BY company_user_id, qw_user_id
- ) voice ON temp.company_user_id = voice.company_user_id
- AND temp.qw_user_id = voice.qw_user_id
- -- 催课看板(催课未处理数、催课已处理数、未处理已完课数、已处理已完课数)
- LEFT JOIN (
- SELECT
- company_user_id,
- qw_user_id,
- COUNT(CASE WHEN status = 0 THEN 1 END) as remind_pending_num,
- COUNT(CASE WHEN status = 1 THEN 1 END) as remind_processed_num
- FROM qw_work_task
- WHERE create_time >= #{startTime}
- AND create_time < #{endTime}
- GROUP BY company_user_id, qw_user_id
- ) qw_work ON temp.company_user_id = qw_work.company_user_id
- AND temp.qw_user_id = qw_work.qw_user_id
- -- 流量统计
- LEFT JOIN (
- select
- company_user_id,
- qw_user_id,
- SUM(internet_traffic) as traffic_sum
- from fs_course_traffic_log
- where create_time >= #{startTime}
- AND create_time < #{endTime}
- GROUP BY company_user_id, qw_user_id
- )traffic ON temp.company_user_id = traffic.company_user_id
- AND temp.qw_user_id = traffic.qw_user_id
- -- 注册人数
- LEFT JOIN (
- select company_user_id,
- qw_user_id,
- count(user_id) as reg_num
- from fs_user
- WHERE create_time >= #{startTime}
- AND create_time < #{endTime}
- GROUP BY company_user_id, qw_user_id
- ) fs_user ON temp.company_user_id = fs_user.company_user_id
- AND temp.qw_user_id = fs_user.qw_user_id
- ]]>
- </insert>
- </mapper>
|