| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- <?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.live.mapper.LiveDataMapper">
- <resultMap type="LiveData" id="LiveDataResult">
- <result property="liveId" column="live_id" />
- <result property="createTime" column="create_time" />
- <result property="pageViews" column="page_views" />
- <result property="uniqueVisitors" column="unique_visitors" />
- <result property="totalViews" column="total_views" />
- <result property="uniqueViewers" column="unique_viewers" />
- <result property="peakConcurrentViewers" column="peak_concurrent_viewers" />
- <result property="favouriteNum" column="favourite_num" />
- <result property="followNum" column="follow_num" />
- </resultMap>
- <sql id="selectLiveDataVo">
- SELECT favourite_num,follow_num,likes,live_id,page_views,peak_concurrent_viewers,unique_viewers,unique_visitors,total_views FROM live_data
- </sql>
- <select id="selectLiveDataList" parameterType="LiveData" resultMap="LiveDataResult">
- <include refid="selectLiveDataVo"/>
- <where>
- <if test="pageViews != null "> and page_views = #{pageViews}</if>
- <if test="uniqueVisitors != null "> and unique_visitors = #{uniqueVisitors}</if>
- <if test="totalViews != null "> and total_views = #{totalViews}</if>
- <if test="uniqueViewers != null "> and unique_viewers = #{uniqueViewers}</if>
- <if test="peakConcurrentViewers != null "> and peak_concurrent_viewers = #{peakConcurrentViewers}</if>
- <if test="favouriteNum != null "> and favourite_num = #{favouriteNum}</if>
- <if test="followNum != null "> and follow_num = #{followNum}</if>
- <if test="likes != null "> and likes = #{likes}</if>
- <if test="liveId != null "> and live_id = #{live_id}</if>
- </where>
- </select>
- <select id="selectLiveDataByLiveId" parameterType="Long" resultMap="LiveDataResult">
- <include refid="selectLiveDataVo"/>
- where live_id = #{liveId}
- </select>
- <select id="getAllLiveIds" resultType="java.lang.Long">
- SELECT B.live_id
- FROM live B
- where B.status = '2'
- </select>
- <select id="getAllLiveDatas" resultMap="LiveDataResult">
- SELECT A.favourite_num,A.follow_num,A.likes,A.live_id,A.page_views,
- A.peak_concurrent_viewers,A.unique_viewers,A.unique_visitors,A.total_views
- FROM live_data A
- inner join live B on A.live_id = B.live_id
- where B.status in (1,2,4) and b.is_audit = 1 and b.is_show = 1 and is_del=0
- </select>
- <select id="getRecentLive" resultType="com.fs.live.vo.RecentLiveDataVo">
- SELECT A.page_views AS pageViews,A.unique_visitors AS uniqueVisitors, B.live_id AS liveId,B.live_name AS liveName,B.`status` AS status,B.live_img_url AS liveImgUrl,B.start_time AS startTime
- FROM live_data A LEFT JOIN live B ON A.live_id = B.live_id ORDER BY B.start_time LIMIT 4
- </select>
- <select id="getCompanyRecentLive" resultType="com.fs.live.vo.RecentLiveDataVo">
- SELECT A.page_views AS pageViews,A.unique_visitors AS uniqueVisitors, B.live_id AS liveId,B.live_name AS liveName,B.`status` AS status,B.live_img_url AS liveImgUrl,B.start_time AS startTime
- FROM live_data A LEFT JOIN live B ON A.live_id = B.live_id
- <if test="companyId != null">
- where b.company_id = #{companyId}
- </if>
- ORDER BY B.start_time LIMIT 4
- </select>
- <select id="getLiveTop" resultType="com.fs.live.vo.RecentLiveDataVo">
- SELECT A.page_views AS pageViews,A.unique_visitors AS uniqueVisitors,A.total_views AS totalViews,A.unique_viewers AS uniqueViewers,A.peak_concurrent_viewers AS peakConcurrentViewers,
- B.live_name AS liveName,B.live_img_url AS liveImgUrl
- FROM live_data A LEFT JOIN live B ON A.live_id = B.live_id
- <choose>
- <when test="rankType == 'highFlow'">
- ORDER BY A.page_views DESC
- </when>
- <when test="rankType == 'highView'">
- ORDER BY A.total_views DESC
- </when>
- <when test="rankType == 'lowFlow'">
- ORDER BY A.page_views ASC
- </when>
- <when test="rankType == 'lowView'">
- ORDER BY A.total_views ASC
- </when>
- <otherwise>
- ORDER BY A.page_views DESC
- </otherwise>
- </choose>
- LIMIT 10
- </select>
- <select id="getCompanyLiveTop" resultType="com.fs.live.vo.RecentLiveDataVo">
- SELECT A.page_views AS pageViews,A.unique_visitors AS uniqueVisitors,A.total_views AS totalViews,A.unique_viewers AS uniqueViewers,A.peak_concurrent_viewers AS peakConcurrentViewers,
- B.live_name AS liveName,B.live_img_url AS liveImgUrl
- FROM live_data A LEFT JOIN live B ON A.live_id = B.live_id
- <if test="companyId != null">
- where b.company_id = #{companyId}
- </if>
- <choose>
- <when test="rankType == 'highFlow'">
- ORDER BY A.page_views DESC
- </when>
- <when test="rankType == 'highView'">
- ORDER BY A.total_views DESC
- </when>
- <when test="rankType == 'lowFlow'">
- ORDER BY A.page_views ASC
- </when>
- <when test="rankType == 'lowView'">
- ORDER BY A.total_views ASC
- </when>
- <otherwise>
- ORDER BY A.page_views DESC
- </otherwise>
- </choose>
- LIMIT 10
- </select>
- <select id="getCurrentData" resultType="com.fs.live.vo.TrendDataVO">
- SELECT
- SUM(ld.page_views) AS views,
- SUM(ld.unique_visitors) AS visitors,
- COUNT(l.live_id) AS streams,
- SUM(ld.total_views) AS pv,
- SUM(ld.unique_viewers) AS uv
- FROM live_data ld
- JOIN live l ON ld.live_id = l.live_id
- WHERE DATE(l.start_time) BETWEEN #{startDate} AND #{endDate};
- </select>
- <select id="getChartData" resultType="java.util.Map">
- SELECT
- CASE
- WHEN #{format} = 'day' THEN DATE(l.start_time)
- WHEN #{format} = 'week' THEN
- CONCAT(
- DATE_FORMAT(DATE_SUB(l.start_time, INTERVAL WEEKDAY(l.start_time) DAY), '%m/%d'),
- '-',
- DATE_FORMAT(DATE_ADD(l.start_time, INTERVAL (6 - WEEKDAY(l.start_time)) DAY), '%m/%d')
- )
- WHEN #{format} = 'month' THEN DATE_FORMAT(l.start_time, '%Y-%m')
- END AS date_range,
- <choose>
- <when test="category == 'streams'"> COUNT(l.live_id) </when>
- <otherwise> SUM(ld.${category}) </otherwise>
- </choose>
- AS views
- FROM live_data ld
- LEFT JOIN live l ON ld.live_id = l.live_id
- WHERE DATE(l.start_time) BETWEEN #{chartStartDate} AND #{chartEndDate}
- GROUP BY date_range
- ORDER BY date_range;
- </select>
- <select id="getPreviousData" resultType="com.fs.live.vo.TrendDataVO">
- SELECT
- SUM(ld.page_views) AS prevViews,
- SUM(ld.unique_visitors) AS prevVisitors,
- COUNT(l.live_id) AS prevStreams,
- SUM(ld.total_views) AS prevPv,
- SUM(ld.unique_viewers) AS prevUv
- FROM live_data ld
- LEFT JOIN live l ON ld.live_id = l.live_id
- WHERE DATE(l.start_time) BETWEEN #{prevStartDate} AND #{prevStartDate};
- </select>
- <select id="getCompanyCurrentData" resultType="com.fs.live.vo.TrendDataVO">
- SELECT
- SUM(ld.page_views) AS views,
- SUM(ld.unique_visitors) AS visitors,
- COUNT(l.live_id) AS streams,
- SUM(ld.total_views) AS pv,
- SUM(ld.unique_viewers) AS uv
- FROM live_data ld
- JOIN live l ON ld.live_id = l.live_id
- WHERE DATE(l.start_time) BETWEEN #{startDate} AND #{endDate}
- <if test="companyId != null">
- and l.company_id = #{companyId}
- </if>
- ;
- </select>
- <select id="getCompanyChartData" resultType="java.util.Map">
- SELECT
- CASE
- WHEN #{format} = 'day' THEN DATE(l.start_time)
- WHEN #{format} = 'week' THEN
- CONCAT(
- DATE_FORMAT(DATE_SUB(l.start_time, INTERVAL WEEKDAY(l.start_time) DAY), '%m/%d'),
- '-',
- DATE_FORMAT(DATE_ADD(l.start_time, INTERVAL (6 - WEEKDAY(l.start_time)) DAY), '%m/%d')
- )
- WHEN #{format} = 'month' THEN DATE_FORMAT(l.start_time, '%Y-%m')
- END AS date_range,
- <choose>
- <when test="category == 'streams'"> COUNT(l.live_id) </when>
- <otherwise> SUM(ld.${category}) </otherwise>
- </choose>
- AS views
- FROM live_data ld
- LEFT JOIN live l ON ld.live_id = l.live_id
- WHERE DATE(l.start_time) BETWEEN #{chartStartDate} AND #{chartEndDate}
- <if test="companyId != null">
- and l.company_id = #{companyId}
- </if>
- GROUP BY date_range
- ORDER BY date_range;
- </select>
- <select id="getCompanyPreviousData" resultType="com.fs.live.vo.TrendDataVO">
- SELECT
- SUM(ld.page_views) AS prevViews,
- SUM(ld.unique_visitors) AS prevVisitors,
- COUNT(l.live_id) AS prevStreams,
- SUM(ld.total_views) AS prevPv,
- SUM(ld.unique_viewers) AS prevUv
- FROM live_data ld
- LEFT JOIN live l ON ld.live_id = l.live_id
- WHERE DATE(l.start_time) BETWEEN #{prevStartDate} AND #{prevStartDate}
- <if test="companyId != null">
- and l.company_id = #{companyId}
- </if>
- ;
- </select>
- <insert id="insertLiveData" parameterType="LiveData">
- insert into live_data
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="liveId != null">live_id,</if>
- <if test="pageViews != null">page_views,</if>
- <if test="uniqueVisitors != null">unique_visitors,</if>
- <if test="totalViews != null">total_views,</if>
- <if test="uniqueViewers != null">unique_viewers,</if>
- <if test="peakConcurrentViewers != null">peak_concurrent_viewers,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="liveId != null">#{liveId},</if>
- <if test="pageViews != null">#{pageViews},</if>
- <if test="uniqueVisitors != null">#{uniqueVisitors},</if>
- <if test="totalViews != null">#{totalViews},</if>
- <if test="uniqueViewers != null">#{uniqueViewers},</if>
- <if test="peakConcurrentViewers != null">#{peakConcurrentViewers},</if>
- </trim>
- </insert>
- <update id="updateLiveData" parameterType="LiveData">
- update live_data
- <trim prefix="SET" suffixOverrides=",">
- <if test="pageViews != null">page_views = #{pageViews},</if>
- <if test="uniqueVisitors != null">unique_visitors = #{uniqueVisitors},</if>
- <if test="totalViews != null">total_views = #{totalViews},</if>
- <if test="uniqueViewers != null">unique_viewers = #{uniqueViewers},</if>
- <if test="peakConcurrentViewers != null">peak_concurrent_viewers = #{peakConcurrentViewers},</if>
- <if test="likes != null">likes = #{likes},</if>
- <if test="favouriteNum != null">favourite_num = #{favouriteNum},</if>
- <if test="followNum != null">follow_num = #{followNum},</if>
- </trim>
- where live_id = #{liveId}
- </update>
- <delete id="deleteLiveDataByLiveId" parameterType="Long">
- delete from live_data where live_id = #{liveId}
- </delete>
- <delete id="deleteLiveDataByLiveIds" parameterType="String">
- delete from live_data where live_id in
- <foreach item="liveId" collection="array" open="(" separator="," close=")">
- #{liveId}
- </foreach>
- </delete>
- <update id="updateBatchLiveData">
- <foreach collection="liveDatas" item="liveData" separator=";">
- UPDATE live_data
- <set>
- <if test="liveData.pageViews != null">page_views = #{liveData.pageViews},</if>
- <if test="liveData.uniqueVisitors != null">unique_visitors = #{liveData.uniqueVisitors},</if>
- <if test="liveData.totalViews != null">total_views = #{liveData.totalViews},</if>
- <if test="liveData.uniqueViewers != null">unique_viewers = #{liveData.uniqueViewers},</if>
- <if test="liveData.peakConcurrentViewers != null">peak_concurrent_viewers = #{liveData.peakConcurrentViewers},</if>
- <if test="liveData.likes != null">likes = #{liveData.likes},</if>
- <if test="liveData.favouriteNum != null">favourite_num = #{liveData.favouriteNum},</if>
- <if test="liveData.followNum != null">follow_num = #{liveData.followNum},</if>
- </set>
- WHERE live_id = #{liveData.liveId}
- </foreach>
- </update>
- <!-- 查询直播间统计数据 -->
- <select id="selectLiveDataStatistics" resultType="com.fs.live.vo.LiveDataStatisticsVo">
- SELECT
- COUNT( lwu.user_id) AS totalViewers,
- COUNT( CASE WHEN lwu.live_flag = 1 and lwu.replay_flag = 0 THEN lwu.user_id END) AS liveViewers,
- COUNT( CASE WHEN lwu.live_flag = 0 and lwu.replay_flag = 1 THEN lwu.user_id END) AS playbackViewers,
- COALESCE(AVG(CASE WHEN lwu.live_flag = 1 and lwu.replay_flag = 0 THEN lwu.online_seconds END), 0) AS liveAvgDuration,
- COALESCE(AVG(CASE WHEN lwu.live_flag = 0 and lwu.replay_flag = 1 THEN lwu.online_seconds END), 0) AS playbackAvgDuration,
- COUNT( CASE
- WHEN lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS totalCompletedCourses,
- COUNT( CASE
- WHEN lwu.live_flag = 1 and lwu.replay_flag = 0 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS liveCompletedCourses,
- COUNT( CASE
- WHEN lwu.live_flag = 0 and lwu.replay_flag = 1 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS playbackCompletedCourses,
- COALESCE((
- SELECT SUM( pay_price)
- FROM live_order
- WHERE live_id IN
- <foreach collection="liveIds" item="liveId" open="(" separator="," close=")">
- #{liveId}
- </foreach>
- AND is_pay = '1'
- ), 0) AS gmv,
- COALESCE((
- select sum(acs.paid) from (SELECT COUNT(DISTINCT user_id) as paid
- FROM live_order
- WHERE live_id IN
- <foreach collection="liveIds" item="liveId" open="(" separator="," close=")">
- #{liveId}
- </foreach>
- AND is_pay = '1'
- group by live_id
- ) acs
- ), 0) AS paidUsers,
- COALESCE((
- SELECT COUNT(DISTINCT order_id)
- FROM live_order
- WHERE live_id IN
- <foreach collection="liveIds" item="liveId" open="(" separator="," close=")">
- #{liveId}
- </foreach>
- AND is_pay = '1'
- ), 0) AS paidOrders,
- COALESCE((
- SELECT COUNT(DISTINCT order_id)
- FROM live_order
- WHERE live_id IN
- <foreach collection="liveIds" item="liveId" open="(" separator="," close=")">
- #{liveId}
- </foreach>
- ), 0) AS salesCount
- FROM live l
- LEFT JOIN live_watch_user lwu ON l.live_id = lwu.live_id
- LEFT JOIN (
- SELECT live_id, SUM(COALESCE(duration, 0)) AS total_duration
- FROM live_video
- WHERE video_type IN (1, 2)
- GROUP BY live_id
- ) video_duration ON l.live_id = video_duration.live_id
- WHERE l.live_id IN
- <foreach collection="liveIds" item="liveId" open="(" separator="," close=")">
- #{liveId}
- </foreach>
- </select>
- <!-- 查询直播间列表数据 -->
- <select id="selectLiveDataListByLiveIds" resultType="com.fs.live.vo.LiveDataListVo">
- SELECT
- l.live_id AS liveId,
- l.live_name AS liveName,
- l.live_type AS liveType,
- l.status AS status,
- l.start_time AS startTime,
- l.finish_time AS finishTime,
- COUNT(1) AS totalViewers,
- COUNT(CASE WHEN lwu.live_flag = 1 and lwu.replay_flag = 0 THEN lwu.user_id END) AS liveViewers,
- COUNT(CASE WHEN lwu.live_flag = 0 and lwu.replay_flag = 1 THEN lwu.user_id END) AS playbackViewers,
- COALESCE(AVG(CASE WHEN lwu.live_flag = 1 and lwu.replay_flag = 0 THEN lwu.online_seconds END), 0) AS liveAvgDuration,
- COALESCE(AVG(CASE WHEN lwu.live_flag = 0 and lwu.replay_flag = 1 THEN lwu.online_seconds END), 0) AS playbackAvgDuration,
- COUNT(CASE
- WHEN lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS totalCompletedCourses,
- COUNT(CASE
- WHEN lwu.live_flag = 1 and lwu.replay_flag = 0 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS liveCompletedCourses,
- COUNT(CASE
- WHEN lwu.live_flag = 0 and lwu.replay_flag = 1 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS playbackCompletedCourses,
- COALESCE(order_stats.gmv, 0) AS gmv,
- COALESCE(order_stats.paidUsers, 0) AS paidUsers,
- COALESCE(order_stats.paidOrders, 0) AS paidOrders,
- COALESCE(order_stats.salesCount, 0) AS salesCount
- FROM live l
- LEFT JOIN live_watch_user lwu ON l.live_id = lwu.live_id
- LEFT JOIN (
- SELECT live_id, SUM(COALESCE(duration, 0)) AS total_duration
- FROM live_video
- WHERE video_type IN (1, 2)
- GROUP BY live_id
- ) video_duration ON l.live_id = video_duration.live_id
- LEFT JOIN (
- SELECT
- live_id,
- SUM( case when is_pay = '1' then pay_price else 0 end) AS gmv,
- COUNT(distinct CASE WHEN is_pay = '1' THEN user_id END) AS paidUsers,
- sum(CASE WHEN is_pay = '1' THEN 1 else 0 END) AS paidOrders,
- COUNT(DISTINCT order_id) AS salesCount
- FROM live_order
- GROUP BY live_id
- ) order_stats ON l.live_id = order_stats.live_id
- WHERE l.live_id IN
- <foreach collection="liveIds" item="liveId" open="(" separator="," close=")">
- #{liveId}
- </foreach>
- GROUP BY l.live_id, l.live_name, l.live_type, l.status, l.start_time, l.finish_time,
- order_stats.gmv, order_stats.paidUsers, order_stats.paidOrders, order_stats.salesCount
- ORDER BY l.start_time DESC
- </select>
- <!-- 查询直播间详情数据(SQL方式) -->
- <select id="selectLiveDataDetailBySql" resultType="com.fs.live.vo.LiveDataDetailVo">
- SELECT
- COALESCE(video_duration.total_duration, 0) AS videoDuration,
- COUNT(DISTINCT lwu.user_id) AS totalViewers,
- COUNT(DISTINCT CASE
- WHEN lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS totalCompletedCourses,
- CASE
- WHEN COUNT(DISTINCT lwu.user_id) > 0 THEN
- ROUND(COUNT(DISTINCT CASE
- WHEN lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) * 100.0 / COUNT(DISTINCT lwu.user_id), 2)
- ELSE 0
- END AS totalCompletionRate,
- COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 THEN lwu.user_id END) AS liveViewers,
- COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 AND lwu.online_seconds >= 1200 THEN lwu.user_id END) AS liveOver20Minutes,
- COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 AND lwu.online_seconds >= 1800 THEN lwu.user_id END) AS liveOver30Minutes,
- CASE
- WHEN COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 THEN lwu.user_id END) > 0 THEN
- ROUND(COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 AND lwu.online_seconds >= 1200 THEN lwu.user_id END) * 100.0 / COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 THEN lwu.user_id END), 2)
- ELSE 0
- END AS liveCompletionRate20,
- CASE
- WHEN COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 THEN lwu.user_id END) > 0 THEN
- ROUND(COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 AND lwu.online_seconds >= 1800 THEN lwu.user_id END) * 100.0 / COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 THEN lwu.user_id END), 2)
- ELSE 0
- END AS liveCompletionRate30,
- COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.user_id END) AS playbackViewers,
- COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 AND lwu.online_seconds >= 1200 THEN lwu.user_id END) AS playbackOver20Minutes,
- COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 AND lwu.online_seconds >= 1800 THEN lwu.user_id END) AS playbackOver30Minutes,
- CASE
- WHEN COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.user_id END) > 0 THEN
- ROUND(COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 AND lwu.online_seconds >= 1200 THEN lwu.user_id END) * 100.0 / COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.user_id END), 2)
- ELSE 0
- END AS playbackCompletionRate20,
- CASE
- WHEN COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.user_id END) > 0 THEN
- ROUND(COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 AND lwu.online_seconds >= 1800 THEN lwu.user_id END) * 100.0 / COUNT(DISTINCT CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.user_id END), 2)
- ELSE 0
- END AS playbackCompletionRate30,
- COALESCE(ld.peak_concurrent_viewers, 0) AS livePeak,
- COALESCE(AVG(CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 THEN lwu.online_seconds END), 0) AS liveAvgDuration,
- COALESCE(AVG(CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.online_seconds END), 0) AS playbackAvgDuration,
- CASE
- WHEN COALESCE(video_duration.total_duration, 0) > 0 THEN
- ROUND(COALESCE(AVG(CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.online_seconds END), 0) * 100.0 / video_duration.total_duration, 2)
- ELSE 0
- END AS playbackFinishRate,
- COALESCE(order_stats.gmv, 0) AS gmv,
- COALESCE(order_stats.paidUsers, 0) AS paidUsers,
- COALESCE(order_stats.paidOrders, 0) AS paidOrders,
- CASE
- WHEN COALESCE(ld.peak_concurrent_viewers, 0) > 0 THEN
- ROUND(order_stats.paidUsers * 100.0 / ld.peak_concurrent_viewers, 2)
- ELSE 0
- END AS peakConversionRate,
- CASE
- WHEN COUNT(DISTINCT lwu.user_id) > 0 THEN
- ROUND(order_stats.paidUsers * 100.0 / COUNT(DISTINCT lwu.user_id), 2)
- ELSE 0
- END AS totalViewerConversionRate,
- CASE
- WHEN COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 AND lwu.online_seconds >= 1800 THEN lwu.user_id END) > 0 THEN
- ROUND(order_stats.paidUsers * 100.0 / COUNT(DISTINCT CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 AND lwu.online_seconds >= 1800 THEN lwu.user_id END), 2)
- ELSE 0
- END AS completion30MinConversionRate,
- CASE
- WHEN COALESCE(ld.peak_concurrent_viewers, 0) > 0 THEN
- ROUND(order_stats.gmv / ld.peak_concurrent_viewers, 2)
- ELSE 0
- END AS peakRValue,
- CASE
- WHEN COUNT(DISTINCT CASE
- WHEN lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) > 0 THEN
- ROUND(order_stats.gmv / COUNT(DISTINCT CASE
- WHEN lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END), 2)
- ELSE 0
- END AS completionRValue
- FROM live l
- LEFT JOIN live_data ld ON l.live_id = ld.live_id
- LEFT JOIN live_watch_user lwu ON l.live_id = lwu.live_id
- LEFT JOIN (
- SELECT live_id, SUM(COALESCE(duration, 0)) AS total_duration
- FROM live_video
- WHERE video_type IN (1, 2)
- GROUP BY live_id
- ) video_duration ON l.live_id = video_duration.live_id
- LEFT JOIN (
- SELECT
- live_id,
- SUM(CASE WHEN is_pay = '1' THEN pay_price ELSE 0 END) AS gmv,
- COUNT(DISTINCT CASE WHEN is_pay = '1' THEN user_id END) AS paidUsers,
- SUM(CASE WHEN is_pay = '1' THEN 1 ELSE 0 END) AS paidOrders
- FROM live_order
- GROUP BY live_id
- ) order_stats ON l.live_id = order_stats.live_id
- WHERE l.live_id = #{liveId}
- </select>
- <!-- 查询直播间用户详情列表(SQL方式) -->
- <select id="selectLiveUserDetailListBySql" resultType="com.fs.live.vo.LiveUserDetailVo">
- SELECT
- u.user_id AS userId,
- COALESCE(u.nickname,u.nick_name, '未知用户') AS userName,
- COALESCE(SUM(CASE WHEN lwu.live_flag = 1 AND lwu.replay_flag = 0 THEN lwu.online_seconds ELSE 0 END), 0) AS liveWatchDuration,
- COALESCE(SUM(CASE WHEN lwu.live_flag = 0 AND lwu.replay_flag = 1 THEN lwu.online_seconds ELSE 0 END), 0) AS playbackWatchDuration,
- COALESCE(order_info.orderCount, 0) AS orderCount,
- COALESCE(order_info.orderAmount, 0) AS orderAmount,
- COALESCE(c.company_name, '') AS companyName,
- COALESCE(cu.user_name, '') AS salesName
- FROM live_watch_user lwu
- LEFT JOIN fs_user u ON lwu.user_id = u.user_id
- LEFT JOIN (
- SELECT
- CAST(user_id AS UNSIGNED) AS user_id,
- COUNT(DISTINCT order_id) AS orderCount,
- SUM(CASE WHEN is_pay = '1' THEN pay_price ELSE 0 END) AS orderAmount
- FROM live_order
- WHERE live_id = #{liveId} AND user_id IS NOT NULL AND user_id != ''
- GROUP BY user_id
- ) order_info ON lwu.user_id = order_info.user_id
- LEFT JOIN fs_user_company_user fucu ON lwu.user_id = fucu.user_id
- LEFT JOIN company c ON fucu.company_id = c.company_id
- LEFT JOIN company_user cu ON fucu.company_user_id = cu.user_id
- WHERE lwu.live_id = #{liveId}
- GROUP BY u.user_id, u.nick_name, u.nickname, order_info.orderCount, order_info.orderAmount, c.company_name, cu.user_name
- ORDER BY order_info.orderAmount DESC, liveWatchDuration DESC
- </select>
- </mapper>
|