Blame view

CourseContentMapper.xml 4.8 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?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>

24
    <select id="getCourseVods" parameterType="long" resultType="com.subsidy.model.VodDictDO">
涂亚平 committed
25
        SELECT
26 27 28 29 30 31 32 33 34 35
           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
涂亚平 committed
36 37 38 39 40 41 42
        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}
涂亚平 committed
43
            and t2.id is not null
涂亚平 committed
44 45
    </select>

涂亚平 committed
46 47
    <select id="contentVodProcess" resultType="com.subsidy.vo.member.MemberVodVO">
        SELECT
涂亚平 committed
48 49 50 51 52 53
            t3.id,
            t3.vod_url,
            t3.vod_name,
            t3.vod_type,
            t3.vod_length,
            t3.play_record,
涂亚平 committed
54
            if(t3.vod_length - t3.sumPlay > 0, TRUNCATE(t3.vod_length - t3.sumPlay,0), 0 ) AS leftLength,
涂亚平 committed
55
            if(TRUNCATE( t3.sumPlay * 100 / t3.vod_length,2) &lt; 100,TRUNCATE( t3.sumPlay * 100 / t3.vod_length, 2),100) AS percent
涂亚平 committed
56 57 58 59 60 61 62 63 64 65 66 67 68
        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
邓敏 committed
69
                LEFT JOIN content_vod_mapping cvm ON cvm.vod_id = t.id
涂亚平 committed
70 71 72 73 74 75 76 77
                LEFT JOIN (
                SELECT
                    t.vod_id,
                    t.member_id,
                    sum( t.play_length ) AS sumPlay
                FROM
                    vod_play_history t
                WHERE
邓敏 committed
78 79 80
                    t.delete_date IS NULL
                    AND t.member_id = #{memberId}
                    AND t.class_id = #{classId}
涂亚平 committed
81 82
                GROUP BY
                    t.vod_id,
涂亚平 committed
83 84
                    t.member_id,
                    t.class_id
涂亚平 committed
85 86 87 88 89 90 91 92 93 94 95
                ) 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,
96
                        max( t.id ) AS id
涂亚平 committed
97 98 99 100 101
                    FROM
                        vod_play_history t
                    WHERE
                        t.delete_date IS NULL
                        AND t.member_id = #{memberId}
涂亚平 committed
102
                        and t.class_id = #{classId}
涂亚平 committed
103 104
                    GROUP BY
                        t.member_id,
涂亚平 committed
105 106
                        t.vod_id,
                        t.class_id
涂亚平 committed
107
                    ) t
108
                    LEFT JOIN vod_play_history t2 ON t.id = t2.id
涂亚平 committed
109 110
                ) t4 ON t2.vod_id = t4.vod_id
            WHERE
邓敏 committed
111 112 113
                t.delete_date IS NULL
                AND cvm.delete_date IS NULL
                and cvm.content_id = #{contentId}
涂亚平 committed
114 115 116
            ) t3
        ORDER BY
            t3.order_no
涂亚平 committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    </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>

139 140 141 142 143 144 145 146 147 148
    <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>

涂亚平 committed
149
</mapper>