LivePlaybackHistoryMapper.xml 3.07 KB
<?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.subsidy.mapper.LivePlaybackHistoryMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.subsidy.model.LivePlaybackHistoryDO">
        <id column="id" property="id" />
        <result column="create_date" property="createDate" />
        <result column="update_date" property="updateDate" />
        <result column="delete_date" property="deleteDate" />
        <result column="live_vod_id" property="liveVodId" />
        <result column="member_id" property="memberId" />
        <result column="play_length" property="playLength" />
        <result column="start_time" property="startTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, live_vod_id, member_id, play_length, start_time
    </sql>

    <select id="livePlaybacks" resultType="com.subsidy.vo.live.PlaybacksVO">
        SELECT
            t.id,
            t.user_name,
            t.telephone,
            t2.play_length
        FROM
            (
            SELECT
                distinct
                t2.id,
                t2.user_name,
                t2.telephone
            FROM
                class_member_mapping t
                LEFT JOIN member t2 ON t.member_id = t2.id
                LEFT JOIN live_classes t3 ON t.class_id = t3.class_id
            WHERE
                t.delete_date IS NULL
                AND t2.delete_date IS NULL
                AND t3.delete_date IS NULL
                <if test="classId != null and classId != ''">
                    AND t.class_id = #{classId}
                </if>
                <if test="liveId != null and liveId != ''">
                    AND t3.live_id = #{liveId}
                </if>
                <if test="userName != null and userName != ''">
                    AND t2.user_name LIKE concat( '%', #{userName}, '%' )
                </if>
                )t
            LEFT JOIN (
            SELECT
                t.live_id,
                t.member_id,
                sum( t.play_length ) AS play_length
            FROM
                live_playback_history t
            WHERE
                t.delete_date IS NULL
                <if test="liveId != null and liveId != ''">
                    AND t.live_id = #{liveId}
                </if>
            GROUP BY
                t.live_id,
            t.member_id
            ) t2 ON t.id = t2.member_id
    </select>

    <select id="memberPlayback" parameterType="long" resultType="integer">
        SELECT
            count(
            DISTINCT ( t.member_id ))
        FROM
            live_playback_history t
			left join class_member_mapping t2 on t.member_id = t2.member_id
        WHERE
            t.live_id = #{liveId}
            and t2.class_id = #{classId}
            and t.delete_date is null
            and t2.delete_date IS NULL
        GROUP BY
            t.live_id
    </select>

</mapper>