<?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.SysPerformanceServingMapper">
    
    <resultMap type="SysPerformanceServing" id="SysPerformanceServingResult">
        <result property="id"    column="id"    />
        <result property="servingPost"    column="serving_post"    />
        <result property="servingTime"    column="serving_time"    />
        <result property="servingFile"    column="serving_file"    />
        <result property="appointment"    column="appointment"    />
        <result property="years"    column="years"    />
        <result property="fdName"    column="fd_name"    />
    </resultMap>

    <sql id="selectSysPerformanceServingVo">
        select id, serving_post, serving_time, serving_file, appointment, years, fd_name from sys_performance_serving
    </sql>

    <select id="selectSysPerformanceServingList" parameterType="SysPerformanceServing" resultMap="SysPerformanceServingResult">
        <include refid="selectSysPerformanceServingVo"/>
        <where>  
            <if test="servingPost != null  and servingPost != ''"> and serving_post = #{servingPost}</if>
            <if test="servingTime != null "> and serving_time = #{servingTime}</if>
            <if test="servingFile != null  and servingFile != ''"> and serving_file = #{servingFile}</if>
            <if test="appointment != null  and appointment != ''"> and appointment = #{appointment}</if>
            <if test="years != null  and years != ''"> and years = #{years}</if>
            <if test="fdName != null  and fdName != ''"> and fd_name like concat('%', #{fdName}, '%')</if>
        </where>
    </select>
    
    <select id="selectSysPerformanceServingById" parameterType="Long" resultMap="SysPerformanceServingResult">
        <include refid="selectSysPerformanceServingVo"/>
        where id = #{id}
    </select>

    <!--根据填报人、年份查询-->
    <select id="selectSysPerformanceServingByFdyName" parameterType="String"
            resultMap="SysPerformanceServingResult">
        <include refid="selectSysPerformanceServingVo"/>
        <where>
            <if test="fdName != null and fdName != ''">
                and fd_name = #{fdName}
            </if>
            <if test="years != null and years != ''">
                and years = #{years}
            </if>

        </where>
        order by id desc
    </select>
        
    <insert id="insertSysPerformanceServing" parameterType="SysPerformanceServing">
        insert into sys_performance_serving
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="servingPost != null">serving_post,</if>
            <if test="servingTime != null">serving_time,</if>
            <if test="servingFile != null">serving_file,</if>
            <if test="appointment != null">appointment,</if>
            <if test="years != null">years,</if>
            <if test="fdName != null">fd_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="servingPost != null">#{servingPost},</if>
            <if test="servingTime != null">#{servingTime},</if>
            <if test="servingFile != null">#{servingFile},</if>
            <if test="appointment != null">#{appointment},</if>
            <if test="years != null">#{years},</if>
            <if test="fdName != null">#{fdName},</if>
         </trim>
    </insert>

    <update id="updateSysPerformanceServing" parameterType="SysPerformanceServing">
        update sys_performance_serving
        <trim prefix="SET" suffixOverrides=",">
            <if test="servingPost != null">serving_post = #{servingPost},</if>
            <if test="servingTime != null">serving_time = #{servingTime},</if>
            <if test="servingFile != null">serving_file = #{servingFile},</if>
            <if test="appointment != null">appointment = #{appointment},</if>
            <if test="years != null">years = #{years},</if>
            <if test="fdName != null">fd_name = #{fdName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysPerformanceServingById" parameterType="Long">
        delete from sys_performance_serving where id = #{id}
    </delete>

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