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
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
delete from fs_statis_qw_watch
where id = #{id,jdbcType=BIGINT}
insert into fs_statis_qw_watch (
)
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 into fs_statis_qw_watch
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,#{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},
update fs_statis_qw_watch
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 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}
replace into fs_statis_qw_watch (
)
values
(
#{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}
)
= #{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
]]>