|
|
@@ -992,410 +992,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
GROUP BY
|
|
|
o.company_id,
|
|
|
o.send_type
|
|
|
- </select>
|
|
|
- <select id="selectFsCourseReportVO" resultType="com.fs.his.vo.FsCourseReportVO">
|
|
|
- SELECT
|
|
|
- c.company_id AS companyId,
|
|
|
- c.company_name AS companyName,
|
|
|
-
|
|
|
- <!-- 看课统计数据 -->
|
|
|
- COALESCE(watch.pending_count, 0) AS pendingCount,
|
|
|
- COALESCE(watch.watching_count, 0) AS watchingCount,
|
|
|
- COALESCE(watch.finished_count, 0) AS finishedCount,
|
|
|
- COALESCE(watch.interrupted_count, 0) AS interruptedCount,
|
|
|
- COALESCE(watch.today_access_count, 0) AS accessCount,
|
|
|
-
|
|
|
- <!-- 计算比率(避免除零) -->
|
|
|
- CASE
|
|
|
- WHEN COALESCE(watch.today_access_count, 0) > 0
|
|
|
- THEN ROUND(
|
|
|
- (COALESCE(watch.watching_count, 0) + COALESCE(watch.finished_count, 0)) * 100.0 /
|
|
|
- watch.today_access_count,
|
|
|
- 2
|
|
|
- )
|
|
|
- ELSE 0
|
|
|
- END AS watchRate,
|
|
|
-
|
|
|
- CASE
|
|
|
- WHEN COALESCE(watch.today_access_count, 0) > 0
|
|
|
- THEN ROUND(
|
|
|
- COALESCE(watch.finished_count, 0) * 100.0 /
|
|
|
- watch.today_access_count,
|
|
|
- 2
|
|
|
- )
|
|
|
- ELSE 0
|
|
|
- END AS finishRate,
|
|
|
-
|
|
|
- <!-- 答题人数 -->
|
|
|
- COALESCE(answer.answer_user_count, 0) AS answerUserCount,
|
|
|
-
|
|
|
- <!-- 红包统计 -->
|
|
|
- COALESCE(packet.packet_user_count, 0) AS packetUserCount,
|
|
|
- COALESCE(packet.packet_amount, 0) AS packetAmount
|
|
|
-
|
|
|
- <!-- 动态判断是否查询营期信息 -->
|
|
|
- <if test='dimension == "camp"'>
|
|
|
- ,(SELECT training_camp_name FROM fs_user_course_training_camp
|
|
|
- WHERE training_camp_id = (SELECT training_camp_id FROM fs_user_course_period WHERE period_id = watch.sample_period_id LIMIT 1)
|
|
|
- ) AS trainingCampName
|
|
|
- </if>
|
|
|
- <if test='dimension == "camp"'>
|
|
|
- , (SELECT period_name FROM fs_user_course_period WHERE period_id = watch.sample_period_id LIMIT 1) AS periodName
|
|
|
- </if>
|
|
|
-
|
|
|
- FROM company c
|
|
|
-
|
|
|
- <!-- 看课统计(一次性预聚合) -->
|
|
|
- LEFT JOIN (
|
|
|
- SELECT
|
|
|
- company_id,
|
|
|
- period_id AS sample_period_id,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type = 3 THEN user_id END) AS pending_count,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type = 1 THEN user_id END) AS watching_count,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS finished_count,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type = 4 THEN user_id END) AS interrupted_count,
|
|
|
- COUNT(DISTINCT CASE WHEN DATE(create_time) = CURDATE() THEN user_id END) AS today_access_count
|
|
|
- FROM fs_course_watch_log
|
|
|
- <where>
|
|
|
- <if test="sTime != null and eTime != null">
|
|
|
- AND create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
- </if>
|
|
|
- <if test="trainingCampId != null">
|
|
|
- AND period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
- </if>
|
|
|
- <if test="periodId !=null">
|
|
|
- AND period_id =#{periodId}
|
|
|
- </if>
|
|
|
- </where>
|
|
|
- GROUP BY company_id
|
|
|
- ) AS watch ON c.company_id = watch.company_id
|
|
|
-
|
|
|
- <!-- 答题统计(预聚合) -->
|
|
|
- LEFT JOIN (
|
|
|
- SELECT
|
|
|
- w.company_id,
|
|
|
- COUNT(DISTINCT a.user_id) AS answer_user_count
|
|
|
- FROM fs_course_answer_logs a
|
|
|
- INNER JOIN fs_course_watch_log w ON a.watch_log_id = w.log_id
|
|
|
- <where>
|
|
|
- <if test="sTime != null and eTime != null">
|
|
|
- AND w.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
- </if>
|
|
|
- <if test="trainingCampId != null">
|
|
|
- AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
- </if>
|
|
|
- <if test="periodId!=null">
|
|
|
- AND w.period_id = #{periodId}
|
|
|
- </if>
|
|
|
- </where>
|
|
|
- GROUP BY w.company_id
|
|
|
- ) AS answer ON c.company_id = answer.company_id
|
|
|
-
|
|
|
- <!-- 红包统计(预聚合) -->
|
|
|
- LEFT JOIN (
|
|
|
- SELECT
|
|
|
- company_id,
|
|
|
- COUNT(DISTINCT user_id) AS packet_user_count,
|
|
|
- COALESCE(SUM(amount), 0) AS packet_amount
|
|
|
- FROM fs_course_red_packet_log
|
|
|
- <where>
|
|
|
- <if test="sTime != null and eTime != null">
|
|
|
- AND create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
- </if>
|
|
|
- </where>
|
|
|
- GROUP BY company_id
|
|
|
- ) AS packet ON c.company_id = packet.company_id
|
|
|
-
|
|
|
- <!-- 只显示有数据的公司 -->
|
|
|
- WHERE watch.company_id IS NOT NULL
|
|
|
-
|
|
|
- <!-- 公司筛选条件 -->
|
|
|
-
|
|
|
- <if test="companyId != null and companyId != ''">
|
|
|
- AND c.company_id =#{companyId}
|
|
|
- </if>
|
|
|
-
|
|
|
- <!-- 训练营筛选条件 -->
|
|
|
- <if test="trainingCampId != null">
|
|
|
- AND EXISTS (
|
|
|
- SELECT 1 FROM fs_course_watch_log w2
|
|
|
- INNER JOIN fs_user_course_period p ON w2.period_id = p.period_id
|
|
|
- WHERE w2.company_id = c.company_id
|
|
|
- AND p.training_camp_id = #{trainingCampId}
|
|
|
- )
|
|
|
- </if>
|
|
|
-
|
|
|
- <if test="periodId != null">
|
|
|
- AND EXISTS (
|
|
|
- SELECT 1 FROM fs_course_watch_log w2
|
|
|
- WHERE w2.company_id = c.company_id
|
|
|
- AND w2.period_id = #{periodId}
|
|
|
- )
|
|
|
- </if>
|
|
|
-
|
|
|
- ORDER BY COALESCE(watch.today_access_count, 0) DESC
|
|
|
-
|
|
|
- </select>
|
|
|
- <select id="selectWatchLogReportVO" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
- <choose>
|
|
|
- <when test="dimension == 'user'">
|
|
|
- WITH user_orders AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- COUNT(DISTINCT CASE WHEN status = 3 THEN order_id END) AS history_order_count
|
|
|
- FROM fs_package_order
|
|
|
- GROUP BY user_id
|
|
|
- ),
|
|
|
- user_watch_stats AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- log_id,
|
|
|
- video_id,
|
|
|
- period_id,
|
|
|
- log_type,
|
|
|
- duration,
|
|
|
- create_time,
|
|
|
- finish_time
|
|
|
- FROM fs_course_watch_log
|
|
|
- WHERE send_type = 1
|
|
|
- ),
|
|
|
- user_red_packet AS (
|
|
|
- SELECT
|
|
|
- watch_log_id,
|
|
|
- SUM(amount) AS total_amount
|
|
|
- FROM fs_course_red_packet_log
|
|
|
- GROUP BY watch_log_id
|
|
|
- )
|
|
|
-
|
|
|
- SELECT
|
|
|
- u.user_id AS userId,
|
|
|
- u.nick_name AS nickName,
|
|
|
- cu.nick_name AS salesName,
|
|
|
- c.company_name AS salesCompany,
|
|
|
- dept.dept_name AS salesDept,
|
|
|
- camp.training_camp_name trainingCampName,
|
|
|
- cp.period_name periodName,
|
|
|
- cv.title videoTitle,
|
|
|
- CASE
|
|
|
- WHEN watch_log.log_type = '1' THEN '看课中'
|
|
|
- WHEN watch_log.log_type = '2' THEN '完课'
|
|
|
- WHEN watch_log.log_type = '3' THEN '待看课'
|
|
|
- WHEN watch_log.log_type = '4' THEN '看课中断'
|
|
|
- ELSE '无'
|
|
|
- END AS watchStatus,
|
|
|
- watch_log.duration,
|
|
|
- watch_log.create_time courseTime,
|
|
|
- watch_log.finish_time finishTime,
|
|
|
- CASE
|
|
|
- WHEN answer.log_id IS NOT NULL THEN '已答题'
|
|
|
- ELSE '未答题'
|
|
|
- END AS answerStatus,
|
|
|
- COALESCE(red_packet.total_amount, 0) AS redPacketAmount,
|
|
|
- COALESCE(orders.history_order_count, 0) AS historyOrderCount
|
|
|
- FROM fs_user u
|
|
|
- LEFT JOIN user_orders orders ON u.user_id = orders.user_id
|
|
|
- LEFT JOIN fs_user_company_user cuu ON u.user_id = cuu.user_id
|
|
|
- LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
|
|
|
- LEFT JOIN company c ON cuu.company_id = c.company_id
|
|
|
- LEFT JOIN company_dept dept ON cu.dept_id = dept.dept_id
|
|
|
- LEFT JOIN user_watch_stats watch_log ON u.user_id = watch_log.user_id
|
|
|
- LEFT JOIN fs_user_course_video cv ON cv.video_id = watch_log.video_id
|
|
|
- LEFT JOIN fs_user_course_period cp ON watch_log.period_id = cp.period_id AND cp.del_flag = 0
|
|
|
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id
|
|
|
- LEFT JOIN user_red_packet red_packet ON watch_log.log_id = red_packet.watch_log_id
|
|
|
- LEFT JOIN fs_course_answer_logs answer ON watch_log.log_id = answer.log_id
|
|
|
- WHERE u.user_id IS NOT NULL
|
|
|
- <include refid="commonConditions"/>
|
|
|
- ORDER BY u.register_date DESC, watch_log.create_time DESC
|
|
|
- </when>
|
|
|
-
|
|
|
- <when test="dimension == 'sales'">
|
|
|
- WITH sales_user_stats AS (
|
|
|
- SELECT
|
|
|
- cuu.company_user_id,
|
|
|
- COUNT(DISTINCT cuu.user_id) AS user_count,
|
|
|
- COUNT(DISTINCT CASE WHEN u.status = '1' THEN u.user_id END) AS online_user_count
|
|
|
- FROM fs_user_company_user cuu
|
|
|
- LEFT JOIN fs_user u ON cuu.user_id = u.user_id
|
|
|
- GROUP BY cuu.company_user_id
|
|
|
- ),
|
|
|
- user_watch_stats AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type = '2' THEN log_id END) AS finished_count,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type IN ('1', '3', '4') THEN log_id END) AS unfinished_count,
|
|
|
- COUNT(DISTINCT log_id) AS total_log_count,
|
|
|
- COUNT(DISTINCT user_id) AS watched_user_count
|
|
|
- FROM fs_course_watch_log
|
|
|
- WHERE send_type = 1
|
|
|
- GROUP BY user_id
|
|
|
- ),
|
|
|
- user_red_packet AS (
|
|
|
- SELECT
|
|
|
- wl.user_id,
|
|
|
- SUM(rp.amount) AS total_amount
|
|
|
- FROM fs_course_watch_log wl
|
|
|
- JOIN fs_course_red_packet_log rp ON wl.log_id = rp.watch_log_id
|
|
|
- WHERE wl.send_type = 1
|
|
|
- GROUP BY wl.user_id
|
|
|
- ),
|
|
|
- user_orders AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- COUNT(DISTINCT CASE WHEN status = 3 THEN order_id END) AS history_order_count
|
|
|
- FROM fs_package_order
|
|
|
- GROUP BY user_id
|
|
|
- ),
|
|
|
- user_answer_stats AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- COUNT(DISTINCT log_id) AS answered_count
|
|
|
- FROM fs_course_answer_logs
|
|
|
- GROUP BY user_id
|
|
|
- )
|
|
|
-
|
|
|
- SELECT
|
|
|
- cu.nick_name as salesName,
|
|
|
- sus.user_count AS userCount,
|
|
|
- sus.online_user_count AS onlineUserCount,
|
|
|
- cd.dept_name AS salesDept,
|
|
|
- c.company_name AS salesCompany,
|
|
|
- camp.training_camp_name trainingCampName,
|
|
|
- cp.period_name periodName,
|
|
|
- cv.title videoTitle,
|
|
|
- COALESCE(SUM(uws.finished_count), 0) AS finishedCount,
|
|
|
- COALESCE(SUM(uws.unfinished_count), 0) AS unfinishedCount,
|
|
|
- CASE
|
|
|
- WHEN COALESCE(SUM(uws.total_log_count), 0) = 0 THEN 0
|
|
|
- ELSE ROUND(COALESCE(SUM(uws.finished_count), 0) * 100.0 / COALESCE(SUM(uws.total_log_count), 0), 2)
|
|
|
- END AS completionRate,
|
|
|
- MAX(watch_log.create_time) AS courseTime,
|
|
|
- sus.user_count - COALESCE(SUM(uws.watched_user_count), 0) AS notWatchedCount,
|
|
|
- COALESCE(SUM(uws.watched_user_count), 0) - COUNT(DISTINCT uas.user_id) AS notAnsweredCount,
|
|
|
- COALESCE(SUM(urp.total_amount), 0) AS redPacketAmount,
|
|
|
- COALESCE(SUM(uo.history_order_count), 0) AS historyOrderCount
|
|
|
- FROM company_user cu
|
|
|
- LEFT JOIN company c ON cu.company_id = c.company_id
|
|
|
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
|
|
|
- LEFT JOIN sales_user_stats sus ON cu.user_id = sus.company_user_id
|
|
|
- LEFT JOIN fs_user_company_user cuu ON cu.user_id = cuu.company_user_id
|
|
|
- LEFT JOIN fs_user u ON cuu.user_id = u.user_id
|
|
|
- LEFT JOIN user_watch_stats uws ON u.user_id = uws.user_id
|
|
|
- LEFT JOIN fs_course_watch_log watch_log ON u.user_id = watch_log.user_id AND watch_log.send_type = 1
|
|
|
- LEFT JOIN fs_user_course_video cv ON cv.video_id = watch_log.video_id
|
|
|
- LEFT JOIN fs_user_course_period cp ON watch_log.period_id = cp.period_id AND cp.del_flag = 0
|
|
|
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id
|
|
|
- LEFT JOIN user_red_packet urp ON u.user_id = urp.user_id
|
|
|
- LEFT JOIN user_answer_stats uas ON u.user_id = uas.user_id
|
|
|
- LEFT JOIN user_orders uo ON u.user_id = uo.user_id
|
|
|
- WHERE cu.user_id IS NOT NULL
|
|
|
- <include refid="commonConditions"/>
|
|
|
- GROUP BY cu.user_id, cu.nick_name, cd.dept_name, c.company_name
|
|
|
- ORDER BY userCount DESC, completionRate DESC
|
|
|
- </when>
|
|
|
-
|
|
|
- <when test="dimension == 'company'">
|
|
|
- WITH company_sales_stats AS (
|
|
|
- SELECT
|
|
|
- c.company_id,
|
|
|
- cd.dept_id,
|
|
|
- COUNT(DISTINCT cu.user_id) AS sales_count
|
|
|
- FROM company c
|
|
|
- LEFT JOIN company_dept cd ON c.company_id = cd.company_id
|
|
|
- LEFT JOIN company_user cu ON cd.dept_id = cu.dept_id
|
|
|
- GROUP BY c.company_id, cd.dept_id
|
|
|
- ),
|
|
|
- company_user_stats AS (
|
|
|
- SELECT
|
|
|
- cuu.company_id,
|
|
|
- COUNT(DISTINCT cuu.user_id) AS user_count,
|
|
|
- COUNT(DISTINCT CASE WHEN u.status = '1' THEN u.user_id END) AS online_user_count
|
|
|
- FROM fs_user_company_user cuu
|
|
|
- LEFT JOIN fs_user u ON cuu.user_id = u.user_id
|
|
|
- GROUP BY cuu.company_id
|
|
|
- ),
|
|
|
- user_watch_stats AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type = '2' THEN log_id END) AS finished_count,
|
|
|
- COUNT(DISTINCT CASE WHEN log_type IN ('1', '3', '4') THEN log_id END) AS unfinished_count,
|
|
|
- COUNT(DISTINCT log_id) AS total_log_count,
|
|
|
- COUNT(DISTINCT user_id) AS watched_user_count
|
|
|
- FROM fs_course_watch_log
|
|
|
- WHERE send_type = 1
|
|
|
- GROUP BY user_id
|
|
|
- ),
|
|
|
- user_red_packet AS (
|
|
|
- SELECT
|
|
|
- wl.user_id,
|
|
|
- SUM(rp.amount) AS total_amount
|
|
|
- FROM fs_course_watch_log wl
|
|
|
- JOIN fs_course_red_packet_log rp ON wl.log_id = rp.watch_log_id
|
|
|
- WHERE wl.send_type = 1
|
|
|
- GROUP BY wl.user_id
|
|
|
- ),
|
|
|
- user_orders AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- COUNT(DISTINCT CASE WHEN status = 3 THEN order_id END) AS history_order_count
|
|
|
- FROM fs_package_order
|
|
|
- GROUP BY user_id
|
|
|
- ),
|
|
|
- user_answer_stats AS (
|
|
|
- SELECT
|
|
|
- user_id,
|
|
|
- COUNT(DISTINCT log_id) AS answered_count
|
|
|
- FROM fs_course_answer_logs
|
|
|
- GROUP BY user_id
|
|
|
- )
|
|
|
-
|
|
|
- SELECT
|
|
|
- cd.dept_name AS salesDept,
|
|
|
- css.sales_count AS salesCount,
|
|
|
- cus.user_count AS userCount,
|
|
|
- cus.online_user_count AS onlineUserCount,
|
|
|
- c.company_name AS salesCompany,
|
|
|
- camp.training_camp_name trainingCampName,
|
|
|
- cp.period_name periodName,
|
|
|
- cv.title videoTitle,
|
|
|
- COALESCE(SUM(uws.finished_count), 0) AS finishedCount,
|
|
|
- COALESCE(SUM(uws.unfinished_count), 0) AS unfinishedCount,
|
|
|
- CASE
|
|
|
- WHEN COALESCE(SUM(uws.total_log_count), 0) = 0 THEN 0
|
|
|
- ELSE ROUND(COALESCE(SUM(uws.finished_count), 0) * 100.0 / COALESCE(SUM(uws.total_log_count), 0), 2)
|
|
|
- END AS completionRate,
|
|
|
- MAX(watch_log.create_time) AS courseTime,
|
|
|
- cus.user_count - COALESCE(SUM(uws.watched_user_count), 0) AS notWatchedCount,
|
|
|
- COALESCE(SUM(uws.watched_user_count), 0) - COUNT(DISTINCT uas.user_id) AS notAnsweredCount,
|
|
|
- COALESCE(SUM(urp.total_amount), 0) AS redPacketAmount,
|
|
|
- COALESCE(SUM(uo.history_order_count), 0) AS historyOrderCount
|
|
|
- FROM company c
|
|
|
- LEFT JOIN company_dept cd ON c.company_id = cd.company_id
|
|
|
- LEFT JOIN company_sales_stats css ON c.company_id = css.company_id AND cd.dept_id = css.dept_id
|
|
|
- LEFT JOIN company_user_stats cus ON c.company_id = cus.company_id
|
|
|
- LEFT JOIN company_user cu ON cd.dept_id = cu.dept_id
|
|
|
- LEFT JOIN fs_user_company_user cuu ON cu.user_id = cuu.company_user_id
|
|
|
- LEFT JOIN fs_user u ON cuu.user_id = u.user_id
|
|
|
- LEFT JOIN user_watch_stats uws ON u.user_id = uws.user_id
|
|
|
- LEFT JOIN fs_course_watch_log watch_log ON u.user_id = watch_log.user_id AND watch_log.send_type = 1
|
|
|
- LEFT JOIN fs_user_course_video cv ON cv.video_id = watch_log.video_id
|
|
|
- LEFT JOIN fs_user_course_period cp ON watch_log.period_id = cp.period_id AND cp.del_flag = 0
|
|
|
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id
|
|
|
- LEFT JOIN user_red_packet urp ON u.user_id = urp.user_id
|
|
|
- LEFT JOIN user_answer_stats uas ON u.user_id = uas.user_id
|
|
|
- LEFT JOIN user_orders uo ON u.user_id = uo.user_id
|
|
|
- WHERE c.company_id IS NOT NULL
|
|
|
- <include refid="commonConditions"/>
|
|
|
- GROUP BY cd.dept_id, cd.dept_name, c.company_id, c.company_name
|
|
|
- ORDER BY salesCount DESC, userCount DESC, completionRate DESC
|
|
|
- </when>
|
|
|
- </choose>
|
|
|
-
|
|
|
-
|
|
|
</select>
|
|
|
<select id="selectUserBaseInfo" resultType="com.fs.his.vo.FsUserReportVO">
|
|
|
SELECT distinct u.user_id AS userId,
|
|
|
u.nick_name AS nickName,
|
|
|
+ u.integral AS integral,
|
|
|
CASE
|
|
|
WHEN u.`status` = '1' THEN '正常'
|
|
|
WHEN u.`status` = '2' THEN '禁止'
|
|
|
@@ -1498,9 +1099,8 @@ FROM
|
|
|
<select id="selectIntegralStatsByUserIds" resultType="com.fs.his.vo.FsUserReportVO">
|
|
|
SELECT
|
|
|
user_id AS userId,
|
|
|
- SUM(integral) AS Integral,
|
|
|
ABS(SUM(CASE WHEN integral < 0 THEN integral ELSE 0 END)) AS consumedIntegral
|
|
|
- FROM fs_user_integral_logs
|
|
|
+ from fs_user_integral_logs
|
|
|
WHERE user_id IN
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
#{userId}
|
|
|
@@ -1533,84 +1133,186 @@ FROM
|
|
|
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
|
|
#{userId}
|
|
|
</foreach>
|
|
|
+ <if test="watchParam.sTime != null and watchParam.eTime != null">
|
|
|
+ AND create_time BETWEEN #{watchParam.sTime} AND #{watchParam.eTime}
|
|
|
+ </if>
|
|
|
GROUP BY user_id
|
|
|
</select>
|
|
|
<select id="selectUserBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
- SELECT DISTINCT
|
|
|
- u.user_id AS userId,
|
|
|
+ SELECT
|
|
|
+ log.user_id userId,
|
|
|
u.nick_name AS nickName,
|
|
|
- u.status AS userStatus,
|
|
|
- u.register_date AS registerDate,
|
|
|
- cuu.company_user_id AS companyUserId,
|
|
|
cu.nick_name AS salesName,
|
|
|
c.company_name AS salesCompany,
|
|
|
- dept.dept_name AS salesDept
|
|
|
- FROM fs_user u
|
|
|
- LEFT JOIN fs_user_company_user cuu ON u.user_id = cuu.user_id
|
|
|
- LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
|
|
|
- LEFT JOIN company c ON cuu.company_id = c.company_id
|
|
|
- LEFT JOIN company_dept dept ON cu.dept_id = dept.dept_id
|
|
|
- <if test="(trainingCampId != null and trainingCampId != '') or (periodId != null and periodId != '')">
|
|
|
- LEFT JOIN fs_course_watch_log watch ON watch.user_id = u.user_id
|
|
|
- LEFT JOIN fs_user_course_period cp ON watch.period_id = cp.period_id
|
|
|
- AND cp.del_flag = 0
|
|
|
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id and camp.del_flag=0
|
|
|
+ cd.dept_name AS salesDept,
|
|
|
+ log.period_id periodId,
|
|
|
+ log.video_id videoId,
|
|
|
+ log.log_id logId,
|
|
|
+ log.create_time courseTime,
|
|
|
+ log.finish_time finishTime,
|
|
|
+ log.duration ,
|
|
|
+ CASE
|
|
|
+ WHEN log.log_type = '1' THEN '看课中'
|
|
|
+ WHEN log.log_type = '2' THEN '完课'
|
|
|
+ WHEN log.log_type = '3' THEN '待看课'
|
|
|
+ WHEN log.log_type = '4' THEN '看课中断'
|
|
|
+ ELSE '无'
|
|
|
+ END AS watchStatus,
|
|
|
+ cv.title AS videoTitle
|
|
|
+ FROM
|
|
|
+ fs_course_watch_log log
|
|
|
+ <if test="orderSTime != null and orderETime != null">
|
|
|
+ left join fs_package_order po ON po.user_id = log.user_id
|
|
|
</if>
|
|
|
- WHERE u.user_id IS NOT NULL
|
|
|
+ LEFT JOIN fs_user u ON u.user_id = log.user_id
|
|
|
+ LEFT JOIN fs_user_company_user cuu ON cuu.user_id = u.user_id
|
|
|
+ LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
|
|
|
+ LEFT JOIN company c ON log.company_id = c.company_id
|
|
|
+ LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
|
|
|
+ LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
|
|
|
+ WHERE log.send_type =1
|
|
|
<include refid="commonConditions"/>
|
|
|
+ <if test="orderSTime != null and orderETime != null">
|
|
|
+ AND po.create_time BETWEEN #{orderSTime} AND #{orderETime}
|
|
|
+ </if>
|
|
|
ORDER BY u.register_date DESC
|
|
|
</select>
|
|
|
<select id="selectSalesBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
- SELECT DISTINCT
|
|
|
- cu.user_id AS companyUserId,
|
|
|
- cu.nick_name AS salesName,
|
|
|
- u.user_id AS userId,
|
|
|
- cd.dept_name AS salesDept,
|
|
|
- c.company_name AS salesCompany,
|
|
|
- COUNT(DISTINCT cuu.user_id) AS userCount,
|
|
|
- COUNT(DISTINCT CASE WHEN u.status = '1' THEN u.user_id END) AS onlineUserCount
|
|
|
- FROM company_user cu
|
|
|
- LEFT JOIN company c ON cu.company_id = c.company_id
|
|
|
- LEFT JOIN company_dept cd ON cu.dept_id = cd.dept_id
|
|
|
- LEFT JOIN fs_user_company_user cuu ON cu.user_id = cuu.company_user_id
|
|
|
- LEFT JOIN fs_user u ON cuu.user_id = u.user_id
|
|
|
- <if test="(trainingCampId != null and trainingCampId != '') or (periodId != null and periodId != '')">
|
|
|
- LEFT JOIN fs_course_watch_log watch ON watch.user_id = u.user_id
|
|
|
- LEFT JOIN fs_user_course_period cp ON watch.period_id = cp.period_id
|
|
|
- AND cp.del_flag = 0
|
|
|
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id and camp.del_flag=0
|
|
|
+ SELECT
|
|
|
+ log.user_id userId,
|
|
|
+ log.company_user_id companyUserId,
|
|
|
+ log.period_id periodId,
|
|
|
+ log.video_id videoId,
|
|
|
+ log.log_id logId,
|
|
|
+ log.create_time courseTime,
|
|
|
+ log.finish_time finishTime,
|
|
|
+ log.duration,
|
|
|
+ cv.title videoTitle,
|
|
|
+ COUNT(DISTINCT log.log_id) AS totalLogCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
|
|
|
+ COUNT(DISTINCT log.log_id)-COUNT(DISTINCT log.user_id) AS notWatchedCount
|
|
|
+ FROM
|
|
|
+ fs_course_watch_log log
|
|
|
+ <if test="orderSTime != null and orderETime != null">
|
|
|
+ LEFT JOIN fs_package_order po ON po.user_id = log.user_id
|
|
|
</if>
|
|
|
- WHERE cu.user_id IS NOT NULL
|
|
|
- <include refid="commonConditions"/>
|
|
|
- GROUP BY cu.user_id, cu.nick_name, cd.dept_name, c.company_name
|
|
|
- ORDER BY userCount DESC
|
|
|
+ LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ LEFT JOIN company c ON log.company_id = c.company_id
|
|
|
+ LEFT JOIN company_dept cd ON c.company_id = cd.company_id
|
|
|
+ </if>
|
|
|
+ <if test="nickName != null and nickName != '' or userPhone != null and userPhone != ''">
|
|
|
+ LEFT JOIN fs_user u ON log.user_id = u.user_id
|
|
|
+ </if>
|
|
|
+ WHERE log.send_type =1
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND log.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ <if test="orderSTime != null and orderETime != null">
|
|
|
+ AND po.create_time BETWEEN #{orderSTime} AND #{orderETime}
|
|
|
+ </if>
|
|
|
+ <!-- 销售公司 -->
|
|
|
+ <if test="companyId != null and companyId != ''">
|
|
|
+ AND log.company_id = #{companyId}
|
|
|
+ </if>
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ AND cd.dept_id = #{deptId}
|
|
|
+ </if>
|
|
|
+ <!-- 训练营 -->
|
|
|
+ <if test="trainingCampId != null and trainingCampId != ''">
|
|
|
+ AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id =
|
|
|
+ #{trainingCampId})
|
|
|
+ </if>
|
|
|
+ <!-- 营期 -->
|
|
|
+ <if test="periodId != null and periodId != ''">
|
|
|
+ AND log.period_id = #{periodId}
|
|
|
+ </if>
|
|
|
+ <!-- 会员id -->
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND log.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ <!-- 会员手机号 -->
|
|
|
+ <if test="userPhone != null and userPhone != ''">
|
|
|
+ AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="project != null and project != ''">
|
|
|
+ AND log.project = #{project}
|
|
|
+ </if>
|
|
|
+ <!-- 会员昵称 -->
|
|
|
+ <if test="nickName != null and nickName != ''">
|
|
|
+ AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
|
|
|
+ </if>
|
|
|
+ GROUP BY log.company_user_id
|
|
|
+
|
|
|
</select>
|
|
|
<select id="selectCompanyBaseData" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
- SELECT DISTINCT
|
|
|
- c.company_id AS companyId,
|
|
|
- c.company_name AS salesCompany,
|
|
|
- cd.dept_id AS deptId,
|
|
|
- u.user_id AS userId,
|
|
|
- cd.dept_name AS salesDept,
|
|
|
- cu.user_id AS companyUserId,
|
|
|
- COUNT(DISTINCT cu.user_id) AS salesCount,
|
|
|
- COUNT(DISTINCT cuu.user_id) AS userCount,
|
|
|
- COUNT(DISTINCT CASE WHEN u.status = '1' THEN cuu.user_id END) AS onlineUserCount
|
|
|
- FROM company c
|
|
|
- LEFT JOIN company_dept cd ON c.company_id = cd.company_id
|
|
|
- LEFT JOIN company_user cu ON cd.dept_id = cu.dept_id
|
|
|
- LEFT JOIN fs_user_company_user cuu ON cu.user_id = cuu.company_user_id
|
|
|
- LEFT JOIN fs_user u ON cuu.user_id = u.user_id
|
|
|
- <if test="(trainingCampId != null and trainingCampId != '') or (periodId != null and periodId != '')">
|
|
|
- LEFT JOIN fs_course_watch_log watch ON watch.user_id = u.user_id
|
|
|
- LEFT JOIN fs_user_course_period cp ON watch.period_id = cp.period_id
|
|
|
- AND cp.del_flag = 0
|
|
|
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id and camp.del_flag=0
|
|
|
+ SELECT
|
|
|
+ log.user_id userId,
|
|
|
+ log.company_user_id companyUserId,
|
|
|
+ log.period_id periodId,
|
|
|
+ log.video_id videoId,
|
|
|
+ log.log_id logId,
|
|
|
+ log.create_time courseTime,
|
|
|
+ log.finish_time finishTime,
|
|
|
+ log.duration,
|
|
|
+ cv.title videoTitle,
|
|
|
+ COUNT(DISTINCT log.log_id) AS totalLogCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN log.log_type = '2' THEN log.log_id END) AS finishedCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN log.log_type IN ('1', '3', '4') THEN log.log_id END) AS unfinishedCount,
|
|
|
+ COUNT(DISTINCT log.log_id)-COUNT(DISTINCT log.user_id) AS notWatchedCount
|
|
|
+ FROM
|
|
|
+ fs_course_watch_log log
|
|
|
+ <if test="orderSTime != null and orderETime != null">
|
|
|
+ LEFT JOIN fs_package_order po ON po.user_id = log.user_id
|
|
|
</if>
|
|
|
- WHERE c.company_id IS NOT NULL
|
|
|
- <include refid="commonConditions"/>
|
|
|
- GROUP BY c.company_id, c.company_name, cd.dept_id, cd.dept_name
|
|
|
- ORDER BY salesCount DESC, userCount DESC
|
|
|
+ LEFT JOIN fs_user_course_video cv ON log.video_id = cv.video_id
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ LEFT JOIN company c ON log.company_id = c.company_id
|
|
|
+ LEFT JOIN company_dept cd ON c.company_id = cd.company_id
|
|
|
+ </if>
|
|
|
+ <if test="nickName != null and nickName != '' or userPhone != null and userPhone != ''">
|
|
|
+ LEFT JOIN fs_user u ON log.user_id = u.user_id
|
|
|
+ </if>
|
|
|
+ WHERE log.send_type =1
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND log.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ <if test="orderSTime != null and orderETime != null">
|
|
|
+ AND po.create_time BETWEEN #{orderSTime} AND #{orderETime}
|
|
|
+ </if>
|
|
|
+ <!-- 销售公司 -->
|
|
|
+ <if test="companyId != null and companyId != ''">
|
|
|
+ AND log.company_id = #{companyId}
|
|
|
+ </if>
|
|
|
+ <!--部门 -->
|
|
|
+ <if test="deptId != null and deptId != ''">
|
|
|
+ AND cd.dept_id = #{deptId}
|
|
|
+ </if>
|
|
|
+ <!-- 训练营 -->
|
|
|
+ <if test="trainingCampId != null and trainingCampId != ''">
|
|
|
+ AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
+ </if>
|
|
|
+ <!-- 营期 -->
|
|
|
+ <if test="periodId != null and periodId != ''">
|
|
|
+ AND log.period_id = #{periodId}
|
|
|
+ </if>
|
|
|
+ <!-- 会员id -->
|
|
|
+ <if test="userId != null and userId != ''">
|
|
|
+ AND log.user_id = #{userId}
|
|
|
+ </if>
|
|
|
+ <!-- 会员手机号 -->
|
|
|
+ <if test="userPhone != null and userPhone != ''">
|
|
|
+ AND u.phone LIKE CONCAT('%', #{userPhone}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="project != null and project != ''">
|
|
|
+ AND log.project = #{project}
|
|
|
+ </if>
|
|
|
+ <!-- 会员昵称 -->
|
|
|
+ <if test="nickName != null and nickName != ''">
|
|
|
+ AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
|
|
|
+ </if>
|
|
|
+ GROUP BY log.company_user_id
|
|
|
</select>
|
|
|
<select id="selectUserWatchDetails" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
SELECT
|
|
|
@@ -1642,7 +1344,7 @@ FROM
|
|
|
FROM fs_course_watch_log wl
|
|
|
LEFT JOIN fs_user_course_video cv ON wl.video_id = cv.video_id
|
|
|
LEFT JOIN fs_user_course_period cp ON wl.period_id = cp.period_id AND cp.del_flag = 0
|
|
|
- LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id
|
|
|
+ LEFT JOIN fs_user_course_training_camp camp ON cp.training_camp_id = camp.training_camp_id and camp.del_flag=0
|
|
|
WHERE wl.send_type = 1
|
|
|
and (wl.user_id, wl.company_user_id) IN
|
|
|
<foreach collection="userConditions" item="condition" open="(" close=")" separator=",">
|
|
|
@@ -1657,19 +1359,27 @@ FROM
|
|
|
<if test="watchParam.sTime != null and watchParam.eTime != null">
|
|
|
AND wl.create_time BETWEEN #{watchParam.sTime} AND #{watchParam.eTime}
|
|
|
</if>
|
|
|
+ GROUP BY
|
|
|
+ wl.user_id,
|
|
|
+ wl.company_user_id,
|
|
|
+ camp.training_camp_name,
|
|
|
+ cp.period_name,
|
|
|
+ cv.title,
|
|
|
+ wl.log_type,
|
|
|
+ wl.duration,
|
|
|
+ wl.create_time,
|
|
|
+ wl.finish_time
|
|
|
</select>
|
|
|
<select id="selectRedPacketStats" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
SELECT
|
|
|
- wl.user_id AS userId,
|
|
|
- SUM(rp.amount) AS totalAmount
|
|
|
- FROM fs_course_watch_log wl
|
|
|
- JOIN fs_course_red_packet_log rp ON wl.log_id = rp.watch_log_id
|
|
|
- WHERE wl.send_type = 1
|
|
|
- AND wl.user_id IN
|
|
|
- <foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
|
|
- #{userId}
|
|
|
+ rp.watch_log_id as logId,
|
|
|
+ SUM(rp.amount) AS redPacketAmount
|
|
|
+ FROM fs_course_red_packet_log rp
|
|
|
+ WHERE rp.watch_log_id IN
|
|
|
+ <foreach collection="logIds" item="logId" open="(" separator="," close=")">
|
|
|
+ #{logId}
|
|
|
</foreach>
|
|
|
- GROUP BY wl.user_id
|
|
|
+ GROUP BY rp.watch_log_id
|
|
|
</select>
|
|
|
<select id="selectOrderStats" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
SELECT
|
|
|
@@ -1680,27 +1390,216 @@ FROM
|
|
|
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
|
|
#{userId}
|
|
|
</foreach>
|
|
|
+ <!--下单时间-->
|
|
|
+ <if test="watchParam.orderSTime != null and watchParam.orderETime != null">
|
|
|
+ AND create_time BETWEEN #{watchParam.orderSTime} AND #{watchParam.orderETime}
|
|
|
+ </if>
|
|
|
GROUP BY user_id
|
|
|
</select>
|
|
|
<select id="selectAnswerStats" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
SELECT
|
|
|
- u.user_id AS userId,
|
|
|
+ l.watch_log_id AS logId,
|
|
|
CASE WHEN l.log_id IS NOT NULL THEN '已答题' ELSE '未答题' END AS answerStatus,
|
|
|
- (SELECT COUNT(1)
|
|
|
- FROM fs_user
|
|
|
- WHERE user_id IN
|
|
|
- <foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
|
|
- #{userId}
|
|
|
+ (
|
|
|
+ SELECT COUNT(1)
|
|
|
+ FROM fs_course_watch_log wl
|
|
|
+ WHERE wl.log_id IN
|
|
|
+ <foreach collection="logIds" item="logId" open="(" separator="," close=")">
|
|
|
+ #{logId}
|
|
|
+ </foreach>
|
|
|
+ AND wl.log_id NOT IN (
|
|
|
+ SELECT watch_log_id
|
|
|
+ FROM fs_course_answer_logs
|
|
|
+ WHERE watch_log_id IS NOT NULL
|
|
|
+ )) AS notAnsweredCount
|
|
|
+ FROM fs_course_answer_logs l
|
|
|
+ WHERE l.watch_log_id IN
|
|
|
+ <foreach collection="logIds" item="logId" open="(" separator="," close=")">
|
|
|
+ #{logId}
|
|
|
+ </foreach>
|
|
|
+ GROUP BY l.watch_log_id
|
|
|
+ </select>
|
|
|
+ <select id="selectCompanyBaseInfo" resultType="com.fs.his.vo.FsCourseReportVO">
|
|
|
+ SELECT
|
|
|
+ c.company_id AS companyId,
|
|
|
+ c.company_name AS companyName
|
|
|
+ FROM company c
|
|
|
+ <where>
|
|
|
+ <if test="companyId != null and companyId != ''">
|
|
|
+ AND company_id = #{companyId}
|
|
|
+ </if>
|
|
|
+ <if test="trainingCampId != null">
|
|
|
+ AND EXISTS (
|
|
|
+ SELECT 1 FROM fs_course_watch_log w
|
|
|
+ INNER JOIN fs_user_course_period p ON w.period_id = p.period_id
|
|
|
+ WHERE w.company_id = c.company_id
|
|
|
+ AND p.training_camp_id = #{trainingCampId}
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND w.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="periodId != null">
|
|
|
+ AND EXISTS (
|
|
|
+ SELECT 1 FROM fs_course_watch_log w
|
|
|
+ WHERE w.company_id = c.company_id
|
|
|
+ AND w.period_id = #{periodId}
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND w.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="(trainingCampId == null and periodId == null) and (sTime != null and eTime != null)">
|
|
|
+ AND EXISTS (
|
|
|
+ SELECT 1 FROM fs_course_watch_log w
|
|
|
+ WHERE w.company_id = c.company_id
|
|
|
+ AND w.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+ <select id="selectWatchStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
|
|
|
+ SELECT
|
|
|
+ company_id AS companyId,
|
|
|
+ period_id AS periodId,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 3 THEN user_id END) AS pendingCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 1 THEN user_id END) AS watchingCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS finishedCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN log_type = 4 THEN user_id END) AS interruptedCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN DATE(create_time) = CURDATE() THEN user_id END) AS accessCount
|
|
|
+ FROM fs_course_watch_log
|
|
|
+ <where>
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ <if test="trainingCampId != null">
|
|
|
+ AND period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
+ </if>
|
|
|
+ <if test="periodId != null">
|
|
|
+ AND period_id = #{periodId}
|
|
|
+ </if>
|
|
|
+ <if test="companyIds != null and companyIds.size() > 0">
|
|
|
+ AND company_id IN
|
|
|
+ <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
|
|
|
+ #{companyId}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY company_id
|
|
|
+
|
|
|
+ </select>
|
|
|
+ <select id="selectAnswerStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
|
|
|
+ SELECT
|
|
|
+ w.company_id AS companyId,
|
|
|
+ COUNT(DISTINCT a.user_id) AS answerUserCount
|
|
|
+ FROM fs_course_answer_logs a
|
|
|
+ INNER JOIN fs_course_watch_log w ON a.watch_log_id = w.log_id
|
|
|
+ <where>
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND w.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ <if test="trainingCampId != null">
|
|
|
+ AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
+ </if>
|
|
|
+ <if test="periodId != null">
|
|
|
+ AND w.period_id = #{periodId}
|
|
|
+ </if>
|
|
|
+ <if test="companyIds != null and companyIds.size() > 0">
|
|
|
+ AND w.company_id IN
|
|
|
+ <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
|
|
|
+ #{companyId}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY w.company_id
|
|
|
+ </select>
|
|
|
+ <select id="selectRedPacketStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
|
|
|
+ SELECT
|
|
|
+ w.company_id AS companyId,
|
|
|
+ COUNT(DISTINCT rpl.user_id) AS packetUserCount,
|
|
|
+ COALESCE(SUM(rpl.amount), 0) AS packetAmount
|
|
|
+ FROM fs_course_red_packet_log rpl
|
|
|
+ INNER JOIN fs_course_watch_log w ON rpl.watch_log_id = w.log_id
|
|
|
+ <where>
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND w.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
+ </if>
|
|
|
+ <if test="companyIds != null and companyIds.size() > 0">
|
|
|
+ AND w.company_id IN
|
|
|
+ <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
|
|
|
+ #{companyId}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY w.company_id
|
|
|
+ </select>
|
|
|
+ <select id="selectCampPeriodInfo" resultType="com.fs.his.vo.FsCourseReportVO">
|
|
|
+ SELECT
|
|
|
+ p.period_id AS periodId,
|
|
|
+ p.period_name AS periodName,
|
|
|
+ c.training_camp_name AS trainingCampName
|
|
|
+ FROM fs_user_course_period p
|
|
|
+ LEFT JOIN fs_user_course_training_camp c ON p.training_camp_id = c.training_camp_id
|
|
|
+ WHERE p.period_id IN
|
|
|
+ <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
|
|
|
+ #{periodId}
|
|
|
+ </foreach>
|
|
|
+ </select>
|
|
|
+ <select id="selectCampPeriodByPeriod" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
+ SELECT
|
|
|
+ cp.period_id periodId,
|
|
|
+ cp.period_name periodName,
|
|
|
+ camp.training_camp_name
|
|
|
+ FROM
|
|
|
+ fs_user_course_period cp
|
|
|
+ LEFT JOIN fs_user_course_training_camp camp ON camp.training_camp_id = cp.training_camp_id
|
|
|
+ WHERE cp.period_id in
|
|
|
+ <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
|
|
|
+ #{periodId}
|
|
|
</foreach>
|
|
|
- AND user_id NOT IN (SELECT user_id FROM fs_course_answer_logs)
|
|
|
- ) AS notAnsweredCount
|
|
|
+ </select>
|
|
|
+ <select id="getSalesMemberStats" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
+ SELECT
|
|
|
+ cu.user_id companyUserId,
|
|
|
+ cu.nick_name salesName,
|
|
|
+ COUNT(DISTINCT u.user_id) AS userCount,
|
|
|
+ COUNT(DISTINCT CASE WHEN u.status = 1 THEN u.user_id END) AS onlineUserCount
|
|
|
FROM fs_user u
|
|
|
- LEFT JOIN fs_course_answer_logs l ON u.user_id = l.user_id
|
|
|
- WHERE u.user_id IN
|
|
|
- <foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
|
|
- #{userId}
|
|
|
+ LEFT JOIN fs_user_company_user cuu ON u.user_id = cuu.user_id
|
|
|
+ LEFT JOIN company_user cu ON cuu.company_user_id = cu.user_id
|
|
|
+ <where>
|
|
|
+ (u.status = 1 OR cu.status = 1)
|
|
|
+ <if test="salesIds != null and salesIds.size() > 0">
|
|
|
+ AND cu.user_id IN
|
|
|
+ <foreach collection="salesIds" item="id" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ GROUP BY cu.user_id
|
|
|
+ </select>
|
|
|
+ <select id="getSalesDeptCompanyInfo" resultType="com.fs.his.vo.WatchLogReportVO">
|
|
|
+ SELECT
|
|
|
+ cu.user_id AS companyUserId,
|
|
|
+ d.dept_name AS salesDept,
|
|
|
+ c.company_name AS salesCompany,
|
|
|
+ (SELECT COUNT(*)
|
|
|
+ FROM company_user cu2
|
|
|
+ WHERE cu2.dept_id = cu.dept_id
|
|
|
+ AND cu2.del_flag = '0'
|
|
|
+ AND cu2.status = '0') AS salesCount
|
|
|
+ FROM company_user cu
|
|
|
+ LEFT JOIN company_dept d ON cu.dept_id = d.dept_id
|
|
|
+ LEFT JOIN company c ON d.company_id = c.company_id
|
|
|
+ WHERE cu.user_id IN
|
|
|
+ <foreach collection="salesIds" item="salesId" open="(" separator="," close=")">
|
|
|
+ #{salesId}
|
|
|
</foreach>
|
|
|
- GROUP BY u.user_id, l.log_id;
|
|
|
+ <!--部门-->
|
|
|
+ <if test="watchParam.deptId != null and watchParam.deptId != ''">
|
|
|
+ AND d.dept_id = #{watchParam.deptId}
|
|
|
+ </if>
|
|
|
+ AND cu.del_flag = '0'
|
|
|
</select>
|
|
|
<sql id="commonConditions">
|
|
|
<!-- 销售公司 -->
|
|
|
@@ -1720,22 +1619,19 @@ FROM
|
|
|
|
|
|
<!-- 项目 -->
|
|
|
<if test="project != null and project != ''">
|
|
|
- AND cuu.project_id = #{projectId}
|
|
|
+ AND cuu.project_id = #{project}
|
|
|
+ </if>
|
|
|
+ <!-- 时间范围 -->
|
|
|
+ <if test="sTime != null and eTime != null">
|
|
|
+ AND log.create_time BETWEEN #{sTime} AND #{eTime}
|
|
|
</if>
|
|
|
-
|
|
|
<!-- 训练营 -->
|
|
|
<if test="trainingCampId != null and trainingCampId != ''">
|
|
|
- AND camp.training_camp_id = #{trainingCampId}
|
|
|
+ AND log.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
|
|
|
</if>
|
|
|
-
|
|
|
<!-- 营期 -->
|
|
|
<if test="periodId != null and periodId != ''">
|
|
|
- AND cp.period_id = #{periodId}
|
|
|
- </if>
|
|
|
-
|
|
|
- <!-- 时间范围 -->
|
|
|
- <if test="sTime != null and eTime != null">
|
|
|
- AND watch.create_time BETWEEN #{startTime} AND #{endTime}
|
|
|
+ AND log.period_id = #{periodId}
|
|
|
</if>
|
|
|
|
|
|
<!-- 会员ID -->
|