<?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.zhongzheng.modules.course.mapper.CourseStreamingMapper">

    <resultMap type="com.zhongzheng.modules.course.domain.CourseStreaming" id="CourseStreamingResult">
        <result property="id" column="id"/>
        <result property="streamingType" column="streaming_type"/>
        <result property="streamingName" column="streaming_name"/>
        <result property="code" column="code"/>
        <result property="liveChannelNumber" column="live_channel_number"/>
        <result property="livePushUrl" column="live_push_url"/>
        <result property="livePullUrl" column="live_pull_url"/>
        <result property="liveUrl" column="live_url"/>
        <result property="streamingAddressType" column="streaming_address_type"/>
        <result property="introduce" column="introduce"/>
        <result property="recordingVideoId" column="recording_video_id"/>
        <result property="playbackUrl" column="playback_url"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="polyvId" column="polyv_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseStreamingVo" id="CourseStreamingResultVo">
        <result property="id" column="id"/>
        <result property="streamingType" column="streaming_type"/>
        <result property="streamingName" column="streaming_name"/>
        <result property="code" column="code"/>
        <result property="liveChannelNumber" column="live_channel_number"/>
        <result property="livePushUrl" column="live_push_url"/>
        <result property="livePullUrl" column="live_pull_url"/>
        <result property="liveUrl" column="live_url"/>
        <result property="streamingAddressType" column="streaming_address_type"/>
        <result property="introduce" column="introduce"/>
        <result property="recordingVideoId" column="recording_video_id"/>
        <result property="playbackUrl" column="playback_url"/>
        <result property="status" column="status"/>
        <result property="polyvUrl" column="polyv_url"/>
        <collection property="businessList" column="id" select="findBusinessList"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.domain.CourseStreamingBusiness" id="CourseStreamingBusinessResult">
        <result property="id" column="join_id"/>
        <result property="streamingId" column="streaming_id"/>
        <result property="educationTypeId" column="education_type_id"/>
        <result property="businessId" column="business_id"/>
        <result property="projectId" column="project_id"/>

        <result property="educationName" column="education_name"/>
        <result property="projectName" column="project_name"/>
        <result property="businessName" column="business_name"/>
    </resultMap>

    <select id="findBusinessList" resultMap="CourseStreamingBusinessResult">
        SELECT
            csb.education_type_id,
            csb.id AS join_id,
            csb.business_id,
            csb.project_id,
            cet.education_name,
            cpt.project_name,
            cb.business_name
        FROM
            course_streaming_business csb
            LEFT JOIN course_education_type cet ON csb.education_type_id = cet.id AND cet.status =1
            LEFT JOIN course_project_type cpt ON csb.project_id = cpt.id AND cpt.status =1
            LEFT JOIN course_business cb ON csb.business_id = cb.id AND cb.status =1
        WHERE
            csb.streaming_id=#{id}
    </select>

    <select id="selectList" parameterType="com.zhongzheng.modules.course.bo.CourseStreamingQueryBo" resultMap="CourseStreamingResultVo">
        SELECT
        cs.*,
        pv.mp4 AS polyv_url
        FROM
        course_streaming cs
        LEFT JOIN course_streaming_business csb ON cs.id = csb.streaming_id
        LEFT JOIN polyv_video pv ON cs.polyv_id = pv.polyv_id
        WHERE
        1 = 1
        <if test="businessId != null and businessId.size()!=0 ">
            AND csb.business_id in
            <foreach collection="businessId" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="educationTypeId != null and educationTypeId != ''">
            AND csb.education_type_id = #{educationTypeId}
        </if>
        <if test="streamingAddressType != null and streamingAddressType != ''">
            AND cs.streaming_address_type = #{streamingAddressType}
        </if>
        <if test="streamingType != null and streamingType != ''">
            AND cs.streaming_type = #{streamingType}
        </if>
        <if test="streamingName != null and streamingName != ''">
            AND cs.streaming_name like concat('%', #{streamingName}, '%')
        </if>
        <if test="recordingVideoId != null and recordingVideoId != ''">
            AND cs.recording_video_id = #{recordingVideoId}
        </if>
        <if test="status != null and status.size()!=0 ">
            AND cs.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY
        cs.id
        ORDER BY cs.id DESC
    </select>
</mapper>
