<?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.EvaluateAnswerMapper">

    <resultMap id="BaseResultMap" type="com.xinelu.familydoctor.entity.EvaluateAnswer">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="recordId" column="record_id" jdbcType="BIGINT"/>
            <result property="questionId" column="question_id" jdbcType="BIGINT"/>
            <result property="optionId" column="option_id" jdbcType="BIGINT"/>
            <result property="optionContent" column="option_content" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,record_id,question_id,
        option_id,option_content
    </sql>

    <select id="getAnswers" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" />
        from evaluate_answer
        where  record_id = #{recordId,jdbcType=BIGINT}
    </select>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.xinelu.familydoctor.entity.EvaluateAnswer" useGeneratedKeys="true">
        insert into evaluate_answer
        (record_id,question_id
        ,option_id,option_content)
        values (#{recordId,jdbcType=BIGINT},#{questionId,jdbcType=BIGINT}
        ,#{optionId,jdbcType=BIGINT},#{optionContent,jdbcType=VARCHAR})
    </insert>
    <update id="update" parameterType="com.xinelu.familydoctor.entity.EvaluateAnswer">
        update evaluate_answer
        <set>
                <if test="recordId != null">
                    record_id = #{recordId,jdbcType=BIGINT},
                </if>
                <if test="questionId != null">
                    question_id = #{questionId,jdbcType=BIGINT},
                </if>
                <if test="optionId != null">
                    option_id = #{optionId,jdbcType=BIGINT},
                </if>
                <if test="optionContent != null">
                    option_content = #{optionContent,jdbcType=VARCHAR},
                </if>
        </set>
        where   id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
