CourseContentMapper.xml 4.57 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.CourseContentMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.subsidy.model.CourseContentDO">
        <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="course_id" property="courseId" />
        <result column="content" property="content" />
        <result column="order_no" property="orderNo" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, course_id, content, order_no
    </sql>

    <select id="getCourseVods" parameterType="long" resultType="com.subsidy.model.VodDictDO">
        SELECT
           t2.id,
            t2.content_id,
            t2.vod_name,
            t2.vod_length,
            t2.vod_type,
            t2.vod_size,
            t2.vod_url,
            t2.vod_code,
            t2.teacher_name,
            t2.cover_page
        FROM
            course_content t
            LEFT JOIN vod_dict t2 ON t.id = t2.content_id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            and t.course_id = #{courseId}
            and t2.id is  not null
    </select>

    <select id="contentVodProcess" resultType="com.subsidy.vo.member.MemberVodVO">
        SELECT
            t3.id,
            t3.vod_url,
            t3.vod_name,
            t3.vod_type,
            t3.vod_length,
            t3.play_record,
        IF
            ( t3.vod_length - t3.sumPlay > 0, t3.vod_length - t3.sumPlay, 0 ) AS leftLength,
            if(round( t3.sumPlay * 100 / t3.vod_length, 0 ) &lt; 100,round( t3.sumPlay * 100 / t3.vod_length, 0 ),100) AS percent
        FROM
            (
            SELECT
                t.id,
                t.vod_url,
                t.vod_name,
                t.vod_type,
                t.vod_length,
                t.order_no,
                ifnull( t2.sumPlay, 0 ) AS sumPlay,
                t4.play_record
            FROM
                vod_dict t
                LEFT JOIN (
                SELECT
                    t.vod_id,
                    t.member_id,
                    sum( t.play_length ) AS sumPlay
                FROM
                    vod_play_history t
                WHERE
                    t.member_id = #{memberId}
                GROUP BY
                    t.vod_id,
                    t.member_id
                ) t2 ON t.id = t2.vod_id
                LEFT JOIN (
                SELECT
                    t.member_id,
                    t.vod_id,
                    t2.play_record
                FROM
                    (
                    SELECT
                        t.member_id,
                        t.vod_id,
                        max( t.create_date ) AS create_date
                    FROM
                        vod_play_history t
                    WHERE
                        t.delete_date IS NULL
                        AND t.member_id = #{memberId}
                    GROUP BY
                        t.member_id,
                        t.vod_id
                    ) t
                    LEFT JOIN vod_play_history t2 ON t.vod_id = t2.vod_id
                    AND t.member_id = t2.member_id
                    AND t.create_date = t2.create_date
                ) t4 ON t2.vod_id = t4.vod_id
            WHERE
                t.content_id = #{contentId}
            ) t3
        ORDER BY
            t3.order_no
    </select>

    <select id="contentFiles" parameterType="long" resultType="com.subsidy.model.FileDictDO">
        SELECT
            t2.id,
            t2.file_name,
            t2.file_size,
            t2.file_type,
            t2.file_url
        FROM
            course_content t
            LEFT JOIN file_dict t2 ON t.id = t2.content_id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            AND t2.id IS NOT NULL
            AND t.course_id = #{courseId}
        ORDER BY
            t.order_no,
            t2.order_no
    </select>

    <select id="selectMaxOrderNo" parameterType="long" resultType="integer">
        SELECT
            max(t.order_no)
        FROM
            course_content t
        WHERE
            t.delete_date IS NULL
            AND t.course_id = #{courseId}
    </select>

</mapper>