| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- <?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(DISTINCT lwu.user_id) AS totalViewers,
- COUNT(DISTINCT CASE WHEN l.live_type = 1 THEN lwu.user_id END) AS liveViewers,
- COUNT(DISTINCT CASE WHEN l.live_type = 3 THEN lwu.user_id END) AS playbackViewers,
- COALESCE(AVG(CASE WHEN l.live_type = 1 THEN lwu.online_seconds END), 0) AS liveAvgDuration,
- COALESCE(AVG(CASE WHEN l.live_type = 3 THEN lwu.online_seconds END), 0) AS playbackAvgDuration,
- 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,
- COUNT(DISTINCT CASE
- WHEN l.live_type = 1 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS liveCompletedCourses,
- COUNT(DISTINCT CASE
- WHEN l.live_type = 3 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS playbackCompletedCourses,
- COALESCE(SUM(lo.pay_price), 0) AS gmv,
- COUNT(DISTINCT CASE WHEN lo.is_pay = '1' THEN lo.user_id END) AS paidUsers,
- COUNT(DISTINCT CASE WHEN lo.is_pay = '1' THEN lo.order_id END) AS paidOrders,
- COUNT(DISTINCT CASE WHEN lo.is_pay = '1' THEN lo.order_id END) 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 live_order lo ON l.live_id = lo.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(DISTINCT lwu.user_id) AS totalViewers,
- COUNT(DISTINCT CASE WHEN l.live_type = 1 THEN lwu.user_id END) AS liveViewers,
- COUNT(DISTINCT CASE WHEN l.live_type = 3 THEN lwu.user_id END) AS playbackViewers,
- COALESCE(AVG(CASE WHEN l.live_type = 1 THEN lwu.online_seconds END), 0) AS liveAvgDuration,
- COALESCE(AVG(CASE WHEN l.live_type = 3 THEN lwu.online_seconds END), 0) AS playbackAvgDuration,
- 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,
- COUNT(DISTINCT CASE
- WHEN l.live_type = 1 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS liveCompletedCourses,
- COUNT(DISTINCT CASE
- WHEN l.live_type = 3 AND lwu.online_seconds >= COALESCE(video_duration.total_duration, 0) AND video_duration.total_duration > 0
- THEN lwu.user_id
- END) AS playbackCompletedCourses,
- COALESCE(SUM(lo.pay_price), 0) AS gmv,
- COUNT(DISTINCT CASE WHEN lo.is_pay = '1' THEN lo.user_id END) AS paidUsers,
- COUNT(DISTINCT CASE WHEN lo.is_pay = '1' THEN lo.order_id END) AS paidOrders,
- COUNT(DISTINCT CASE WHEN lo.is_pay = '1' THEN lo.order_id END) 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 live_order lo ON l.live_id = lo.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 BY l.start_time DESC
- </select>
- </mapper>
|