<?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.xinelu.familydoctor.mapper.EvaluateSurveyMapper">

    <resultMap id="BaseResultMap" type="com.xinelu.familydoctor.entity.EvaluateSurvey">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="surveySubject" column="survey_subject" jdbcType="VARCHAR"/>
            <result property="useFlag" column="use_flag" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="createBy" column="create_by" jdbcType="BIGINT"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy" column="update_by" jdbcType="BIGINT"/>
            <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
            <collection property="questions" ofType="com.xinelu.familydoctor.entity.EvaluateQuestion"
                        column="id" select="com.xinelu.familydoctor.mapper.EvaluateQuestionMapper.getQuestions">

            </collection>
    </resultMap>

    <sql id="Base_Column_List">
        id,survey_subject,use_flag,
        create_time,create_by,update_time,
        update_by,del_flag,remark
    </sql>

    <select id="findList" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from evaluate_survey
        where del_flag = '1'
        <if test="surveySubject != null and surveySubject != ''">
            and survey_subject = #{surveySubject}
        </if>
        <if test="useFlag != null and useFlag != ''">
            and use_flag = #{useFlag}
        </if>
        order by id
    </select>

    <select id="getSurvey" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from evaluate_survey
        where  survey_subject = #{surveySubject}
        and del_flag = '1'
        limit 1
    </select>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.xinelu.familydoctor.entity.EvaluateSurvey" useGeneratedKeys="true">
        insert into evaluate_survey
        (survey_subject,use_flag
        ,create_time,create_by,update_time
        ,update_by,del_flag,remark
        )
        values (#{surveySubject,jdbcType=VARCHAR},#{useFlag,jdbcType=VARCHAR}
        ,#{createTime,jdbcType=TIMESTAMP},#{createBy,jdbcType=BIGINT},#{updateTime,jdbcType=TIMESTAMP}
        ,#{updateBy,jdbcType=BIGINT},#{delFlag,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR}
        )
    </insert>
    <update id="update" parameterType="com.xinelu.familydoctor.entity.EvaluateSurvey">
        update evaluate_survey
        <set>
                <if test="surveyName != null">
                    survey_subject = #{surveySubject,jdbcType=VARCHAR},
                </if>
                <if test="useFlag != null">
                    use_flag = #{useFlag,jdbcType=VARCHAR},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=TIMESTAMP},
                </if>
                <if test="createBy != null">
                    create_by = #{createBy,jdbcType=BIGINT},
                </if>
                <if test="updateTime != null">
                    update_time = #{updateTime,jdbcType=TIMESTAMP},
                </if>
                <if test="updateBy != null">
                    update_by = #{updateBy,jdbcType=BIGINT},
                </if>
                <if test="delFlag != null">
                    del_flag = #{delFlag,jdbcType=VARCHAR},
                </if>
                <if test="remark != null">
                    remark = #{remark,jdbcType=VARCHAR},
                </if>
        </set>
        where   id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
