<?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.delivery.mapper.CtCloudClassMapper">
    
    <resultMap type="CtCloudClass" id="CtCloudClassResult">
        <result property="cloudClassId"    column="cloud_class_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="taskType"    column="task_type"    />
        <result property="doctorName"    column="doctor_name"    />
        <result property="institution"    column="institution"    />
        <result property="department"    column="department"    />
        <result property="jobTitle"    column="job_title"    />
        <result property="title"    column="title"    />
        <result property="groupId"    column="group_id"    />
        <result property="tags"    column="tags"    />
        <result property="createTime"    column="create_time"    />
        <result property="isOriginal"    column="is_original"    />
        <result property="coverUrl"    column="cover_url"    />
        <result property="summary"    column="summary"    />
        <result property="videoUrl"    column="video_url"    />
        <result property="validViews"    column="valid_views"    />
        <result property="viewCount"    column="view_count"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectCtCloudClassVo">
        select cloud_class_id, video_id, task_type, doctor_name, institution, department, job_title, title, group_id, tags, create_time, is_original, cover_url, summary, video_url, valid_views, view_count, status from ct_cloud_class
    </sql>

    <select id="selectCtCloudClassList" parameterType="CtCloudClass" resultMap="CtCloudClassResult">
        <include refid="selectCtCloudClassVo"/>
        <where>  
            <if test="doctorName != null  and doctorName != ''"> and doctor_name like concat('%', #{doctorName}, '%')</if>
            <if test="institution != null  and institution != ''"> and institution = #{institution}</if>
            <if test="department != null  and department != ''"> and department = #{department}</if>
            <if test="jobTitle != null  and jobTitle != ''"> and job_title = #{jobTitle}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="groupId != null "> and group_id = #{groupId}</if>
            <if test="tags != null  and tags != ''"> and tags = #{tags}</if>
            <if test="isOriginal != null "> and is_original = #{isOriginal}</if>
            <if test="coverUrl != null  and coverUrl != ''"> and cover_url = #{coverUrl}</if>
            <if test="summary != null  and summary != ''"> and summary = #{summary}</if>
            <if test="videoUrl != null  and videoUrl != ''"> and video_url = #{videoUrl}</if>
            <if test="validViews != null "> and valid_views = #{validViews}</if>
            <if test="viewCount != null "> and view_count = #{viewCount}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="keyWord != null and keyWord != ''">
                AND (
                title LIKE CONCAT('%', #{keyWord}, '%')
                OR doctor_name LIKE CONCAT('%', #{keyWord}, '%')
                )
            </if>
        </where>
    </select>
    
    <select id="selectCtCloudClassByCloudClassId" parameterType="Long" resultMap="CtCloudClassResult">
        <include refid="selectCtCloudClassVo"/>
        where cloud_class_id = #{cloudClassId}
    </select>
        
    <insert id="insertCtCloudClass" parameterType="CtCloudClass">
        insert into ct_cloud_class
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cloudClassId != null">cloud_class_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="taskType != null">task_type,</if>
            <if test="doctorName != null">doctor_name,</if>
            <if test="institution != null">institution,</if>
            <if test="department != null">department,</if>
            <if test="jobTitle != null">job_title,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="groupId != null">group_id,</if>
            <if test="tags != null">tags,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isOriginal != null">is_original,</if>
            <if test="coverUrl != null">cover_url,</if>
            <if test="summary != null">summary,</if>
            <if test="videoUrl != null">video_url,</if>
            <if test="validViews != null">valid_views,</if>
            <if test="viewCount != null">view_count,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cloudClassId != null">#{cloudClassId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="doctorName != null">#{doctorName},</if>
            <if test="institution != null">#{institution},</if>
            <if test="department != null">#{department},</if>
            <if test="jobTitle != null">#{jobTitle},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="tags != null">#{tags},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isOriginal != null">#{isOriginal},</if>
            <if test="coverUrl != null">#{coverUrl},</if>
            <if test="summary != null">#{summary},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
            <if test="validViews != null">#{validViews},</if>
            <if test="viewCount != null">#{viewCount},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateCtCloudClass" parameterType="CtCloudClass">
        update ct_cloud_class
        <trim prefix="SET" suffixOverrides=",">
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="taskType != null">task_type = #{taskType},</if>
            <if test="doctorName != null">doctor_name = #{doctorName},</if>
            <if test="institution != null">institution = #{institution},</if>
            <if test="department != null">department = #{department},</if>
            <if test="jobTitle != null">job_title = #{jobTitle},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="tags != null">tags = #{tags},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isOriginal != null">is_original = #{isOriginal},</if>
            <if test="coverUrl != null">cover_url = #{coverUrl},</if>
            <if test="summary != null">summary = #{summary},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if>
            <if test="validViews != null">valid_views = #{validViews},</if>
            <if test="viewCount != null">view_count = #{viewCount},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where cloud_class_id = #{cloudClassId}
    </update>

    <delete id="deleteCtCloudClassByCloudClassId" parameterType="Long">
        delete from ct_cloud_class where cloud_class_id = #{cloudClassId}
    </delete>

    <delete id="deleteCtCloudClassByCloudClassIds" parameterType="String">
        delete from ct_cloud_class where cloud_class_id in 
        <foreach item="cloudClassId" collection="array" open="(" separator="," close=")">
            #{cloudClassId}
        </foreach>
    </delete>
</mapper>