<?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.survey.mapper.SurSurveyMapper">
    
    <resultMap type="SurSurvey" id="SurSurveyResult">
        <result property="surveyId"    column="survey_id"    />
        <result property="surveyName"    column="survey_name"    />
        <result property="countDate"    column="count_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="cutoffTime"    column="cutoff_time"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectSurSurveyVo">
        select survey_id,count_date, survey_name, create_by, create_time, cutoff_time, remark, status from sur_survey
    </sql>

    <select id="selectSurSurveyList" parameterType="SurSurvey" resultMap="SurSurveyResult">
        <include refid="selectSurSurveyVo"/>
        <where>  
            <if test="surveyName != null  and surveyName != ''"> and survey_name like concat('%', #{surveyName}, '%')</if>
            <if test="cutoffTime != null "> and cutoff_time = #{cutoffTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
        order by survey_id desc
    </select>
    
    <select id="selectSurSurveyBySurveyId" parameterType="Long" resultMap="SurSurveyResult">
        <include refid="selectSurSurveyVo"/>
        where survey_id = #{surveyId}
    </select>
        
    <insert id="insertSurSurvey" parameterType="SurSurvey" useGeneratedKeys="true" keyProperty="surveyId">
        insert into sur_survey
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="surveyName != null">survey_name,</if>
            <if test="countDate != null">count_date,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="cutoffTime != null">cutoff_time,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="surveyName != null">#{surveyName},</if>
            <if test="countDate != null">#{countDate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="cutoffTime != null">#{cutoffTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateSurSurvey" parameterType="SurSurvey">
        update sur_survey
        <trim prefix="SET" suffixOverrides=",">
            <if test="surveyName != null">survey_name = #{surveyName},</if>
            <if test="countDate != null">count_date = #{countDate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="cutoffTime != null">cutoff_time = #{cutoffTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where survey_id = #{surveyId}
    </update>

    <delete id="deleteSurSurveyBySurveyId" parameterType="Long">
        delete from sur_survey where survey_id = #{surveyId}
    </delete>

    <delete id="deleteSurSurveyBySurveyIds" parameterType="String">
        delete from sur_survey where survey_id in 
        <foreach item="surveyId" collection="array" open="(" separator="," close=")">
            #{surveyId}
        </foreach>
    </delete>
</mapper>