<?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.course.mapper.FsUserCoursePeriodMapper">

    <resultMap type="FsUserCoursePeriod" id="FsUserCoursePeriodResult">
        <result property="periodId"    column="period_id"    />
        <result property="periodName"    column="period_name"    />
        <result property="companyId"    column="company_id"    />
        <result property="trainingCampId"    column="training_camp_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="courseStyle"    column="course_style"    />
        <result property="liveRoomStyle"    column="live_room_style"    />
        <result property="redPacketGrantMethod"    column="red_packet_grant_method"    />
        <result property="periodType"    column="period_type"    />
        <result property="periodStartingTime"    column="period_starting_time"    />
        <result property="periodEndTime"    column="period_end_time"    />
    </resultMap>

    <sql id="selectFsUserCoursePeriodVo">
        select * from fs_user_course_period
    </sql>

    <select id="selectFsUserCoursePeriodList" parameterType="FsUserCoursePeriod" resultMap="FsUserCoursePeriodResult">
        <include refid="selectFsUserCoursePeriodVo"/>
        <where>
            <if test="periodName != null  and periodName != ''"> and period_name like concat('%', #{periodName}, '%')</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="trainingCampId != null "> and training_camp_id = #{trainingCampId}</if>
            <if test="courseStyle != null  and courseStyle != ''"> and course_style = #{courseStyle}</if>
            <if test="liveRoomStyle != null  and liveRoomStyle != ''"> and live_room_style = #{liveRoomStyle}</if>
            <if test="redPacketGrantMethod != null "> and red_packet_grant_method = #{redPacketGrantMethod}</if>
            <if test="periodType != null "> and period_type = #{periodType}</if>
            <if test="periodStartingTime != null "> and period_starting_time = #{periodStartingTime}</if>
            <if test="periodEndTime != null "> and period_end_time = #{periodEndTime}</if>
        </where>
    </select>

    <select id="selectFsUserCoursePeriodPage" parameterType="FsUserCoursePeriod" resultType="FsUserCoursePeriodVO">
        SELECT
        period_id,
        period_name,
        fs_user_course_period.company_id,
        training_camp_id,
        fs_user_course_period.create_time,
        fs_user_course_period.update_time,
        course_style,
        live_room_style,
        red_packet_grant_method,
        period_type,
        period_end_time,
        period_starting_time
        FROM
        fs_user_course_period
        <where>
            <if test="trainingCampId != null"> and training_camp_id = #{trainingCampId}</if>
            <if test="periodName != null  and periodName != ''"> and period_name like concat('%', #{periodName}, '%')</if>
            <if test="periodStartingTime != null "> and period_starting_time = #{periodStartingTime}</if>
            <if test="periodEndTime != null "> and period_end_time = #{periodEndTime}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectFsUserCoursePeriodById" parameterType="Long" resultMap="FsUserCoursePeriodResult">
        <include refid="selectFsUserCoursePeriodVo"/>
        where period_id = #{periodId}
    </select>

    <insert id="insertFsUserCoursePeriod" parameterType="FsUserCoursePeriod" useGeneratedKeys="true" keyProperty="periodId">
        insert into fs_user_course_period
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="periodId != null">period_id,</if>
            <if test="periodName != null">period_name,</if>
            <if test="companyId != null">company_id,</if>
            <if test="trainingCampId != null">training_camp_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="courseStyle != null">course_style,</if>
            <if test="liveRoomStyle != null">live_room_style,</if>
            <if test="redPacketGrantMethod != null">red_packet_grant_method,</if>
            <if test="periodType != null">period_type,</if>
            <if test="periodStartingTime != null">period_starting_time,</if>
            <if test="periodEndTime != null">period_end_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="periodId != null">#{periodId},</if>
            <if test="periodName != null">#{periodName},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="trainingCampId != null">#{trainingCampId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="courseStyle != null">#{courseStyle},</if>
            <if test="liveRoomStyle != null">#{liveRoomStyle},</if>
            <if test="redPacketGrantMethod != null">#{redPacketGrantMethod},</if>
            <if test="periodType != null">#{periodType},</if>
            <if test="periodStartingTime != null">#{periodStartingTime},</if>
            <if test="periodEndTime != null">#{periodEndTime},</if>
         </trim>
    </insert>

    <update id="updateFsUserCoursePeriod" parameterType="FsUserCoursePeriod">
        update fs_user_course_period
        <trim prefix="SET" suffixOverrides=",">
            <if test="periodName != null">period_name = #{periodName},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="trainingCampId != null">training_camp_id = #{trainingCampId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="courseStyle != null">course_style = #{courseStyle},</if>
            <if test="liveRoomStyle != null">live_room_style = #{liveRoomStyle},</if>
            <if test="redPacketGrantMethod != null">red_packet_grant_method = #{redPacketGrantMethod},</if>
            <if test="periodType != null">period_type = #{periodType},</if>
            <if test="periodStartingTime != null">period_starting_time = #{periodStartingTime},</if>
            <if test="periodEndTime != null">period_end_time = #{periodEndTime},</if>
        </trim>
        where period_id = #{periodId}
    </update>

    <delete id="deleteFsUserCoursePeriodById" parameterType="Long">
        delete from fs_user_course_period where period_id = #{periodId}
    </delete>

    <delete id="deleteFsUserCoursePeriodByIds" parameterType="String">
        delete from fs_user_course_period where period_id in
        <foreach item="periodId" collection="array" open="(" separator="," close=")">
            #{periodId}
        </foreach>
    </delete>

</mapper>
