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

    <resultMap id="BaseResultMap" type="com.xinelu.familydoctor.entity.EvaluateAdviceTemplate">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="templateType" column="template_type" jdbcType="VARCHAR"/>
            <result property="content" column="content" 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="remark" column="remark" jdbcType="VARCHAR"/>
            <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
    </resultMap>

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

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

    <select id="getTemplateByType" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" /> from evaluate_advice_template
        where del_flag = '1'
          and use_flag = '1'
          and template_type = #{templateType}
        limit 1
    </select>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.xinelu.familydoctor.entity.EvaluateAdviceTemplate" useGeneratedKeys="true">
        insert into evaluate_advice_template
        ( id,template_type,content
        ,use_flag,create_time,create_by
        ,update_time,update_by,remark
        ,del_flag)
        values (#{id,jdbcType=BIGINT},#{templateType,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR}
        ,#{useFlag,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{createBy,jdbcType=BIGINT}
        ,#{updateTime,jdbcType=TIMESTAMP},#{updateBy,jdbcType=BIGINT},#{remark,jdbcType=VARCHAR}
        ,#{delFlag,jdbcType=VARCHAR})
    </insert>
    <update id="update" parameterType="com.xinelu.familydoctor.entity.EvaluateAdviceTemplate">
        update evaluate_advice_template
        <set>
                <if test="templateType != null">
                    template_type = #{templateType,jdbcType=VARCHAR},
                </if>
                <if test="content != null">
                    content = #{content,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="remark != null">
                    remark = #{remark,jdbcType=VARCHAR},
                </if>
                <if test="delFlag != null">
                    del_flag = #{delFlag,jdbcType=VARCHAR},
                </if>
        </set>
        where   id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
