<?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.teacher.mapper.SysTeacherCertificateMapper">
    
    <resultMap type="SysTeacherCertificate" id="SysTeacherCertificateResult">
        <result property="certificateId"    column="certificate_id"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="name"    column="name"    />
        <result property="unit"    column="unit"    />
        <result property="getTime"    column="getTime"    />
        <result property="photo"    column="photo"    />
    </resultMap>

    <sql id="selectSysTeacherCertificateVo">
        select certificate_id, teacher_id, name, unit, getTime, photo from sys_teacher_certificate
    </sql>

    <select id="selectSysTeacherCertificateList" parameterType="SysTeacherCertificate" resultMap="SysTeacherCertificateResult">
        <include refid="selectSysTeacherCertificateVo"/>
        <where>  
            <if test="teacherId != null "> and teacher_id = #{teacherId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="getTime != null  and getTime != ''"> and getTime = #{getTime}</if>
            <if test="photo != null  and photo != ''"> and photo = #{photo}</if>
        </where>
    </select>
    
    <select id="selectSysTeacherCertificateByCertificateId" parameterType="Long" resultMap="SysTeacherCertificateResult">
        <include refid="selectSysTeacherCertificateVo"/>
        where certificate_id = #{certificateId}
    </select>
        
    <insert id="insertSysTeacherCertificate" parameterType="SysTeacherCertificate" useGeneratedKeys="true" keyProperty="certificateId">
        insert into sys_teacher_certificate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">teacher_id,</if>
            <if test="name != null">name,</if>
            <if test="unit != null">unit,</if>
            <if test="getTime != null">getTime,</if>
            <if test="photo != null">photo,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="teacherId != null">#{teacherId},</if>
            <if test="name != null">#{name},</if>
            <if test="unit != null">#{unit},</if>
            <if test="getTime != null">#{getTime},</if>
            <if test="photo != null">#{photo},</if>
         </trim>
    </insert>

    <update id="updateSysTeacherCertificate" parameterType="SysTeacherCertificate">
        update sys_teacher_certificate
        <trim prefix="SET" suffixOverrides=",">
            <if test="teacherId != null">teacher_id = #{teacherId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="getTime != null">getTime = #{getTime},</if>
            <if test="photo != null">photo = #{photo},</if>
        </trim>
        where certificate_id = #{certificateId}
    </update>

    <delete id="deleteSysTeacherCertificateByCertificateId" parameterType="Long">
        delete from sys_teacher_certificate where certificate_id = #{certificateId}
    </delete>

    <delete id="deleteSysTeacherCertificateByCertificateIds" parameterType="String">
        delete from sys_teacher_certificate where certificate_id in 
        <foreach item="certificateId" collection="array" open="(" separator="," close=")">
            #{certificateId}
        </foreach>
    </delete>
</mapper>