<?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.srs.comprehensive.mapper.QuestionnaireMapper">
    
    <resultMap type="Questionnaire" id="QuestionnaireResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="questions"    column="questions"    />
        <result property="createId"    column="create_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateId"    column="update_id"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectQuestionnaireVo">
        select id, title, questions, create_id, create_time, update_id, update_time,status from t_questionnaire
    </sql>

    <select id="selectQuestionnaireList" parameterType="Questionnaire" resultMap="QuestionnaireResult">
        <include refid="selectQuestionnaireVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title like concat('%',#{title},'%')</if>
            <if test="questions != null  and questions != ''"> and questions = #{questions}</if>
            <if test="createId != null "> and create_id = #{createId}</if>
            <if test="updateId != null "> and update_id = #{updateId}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectQuestionnaireById" parameterType="Long" resultMap="QuestionnaireResult">
        <include refid="selectQuestionnaireVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQuestionnaire" parameterType="Questionnaire" useGeneratedKeys="true" keyProperty="id">
        insert into t_questionnaire
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null">title,</if>
            <if test="questions != null">questions,</if>
            <if test="createId != null">create_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateId != null">update_id,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="title != null">#{title},</if>
            <if test="questions != null">#{questions},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>




    <update id="updateQuestionnaire" parameterType="Questionnaire">
        update t_questionnaire
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="questions != null">questions = #{questions},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateId != null">update_id = #{updateId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQuestionnaireById" parameterType="Long">
        delete from t_questionnaire where id = #{id}
    </delete>

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

    <insert id="insertRelease" parameterType="Questionnaire" useGeneratedKeys="true" keyProperty="id">
        insert into t_release
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null">title,</if>
            <if test="questions != null">questions,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="status != null">status,</if>
            <if test="qId != null">q_id,</if>
            <if test="stuYearId != null">stu_year_id,</if>
            <if test="stuYearName != null">stu_year_name,</if>
            <if test="teacherId != null">teacher_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="teacherName != null">teacher_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null">#{title},</if>
            <if test="questions != null">#{questions},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="status != null">#{status},</if>
            <if test="qId != null">#{qId},</if>
            <if test="stuYearId != null">#{stuYearId},</if>
            <if test="stuYearName != null">#{stuYearName},</if>
            <if test="teacherId != null">#{teacherId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="teacherName != null">#{teacherName},</if>
        </trim>
    </insert>



</mapper>