<?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.SysPerformanceTaskMapper">
    
    <resultMap type="SysPerformanceTask" id="SysPerformanceTaskResult">
        <result property="id"    column="id"    />
        <result property="taskDescribe"    column="task_describe"    />
        <result property="taskStart"    column="task_start"    />
        <result property="taskEnd"    column="task_end"    />
        <result property="prizes"    column="prizes"    />
        <result property="years"    column="years"    />
        <result property="fdName"    column="fd_name"    />
    </resultMap>

    <sql id="selectSysPerformanceTaskVo">
        select id, task_describe, task_start, task_end, prizes, years, fd_name from sys_performance_task
    </sql>

    <select id="selectSysPerformanceTaskList" parameterType="SysPerformanceTask" resultMap="SysPerformanceTaskResult">
        <include refid="selectSysPerformanceTaskVo"/>
        <where>  
            <if test="taskDescribe != null  and taskDescribe != ''"> and task_describe = #{taskDescribe}</if>
            <if test="taskStart != null  and taskStart != ''"> and task_start = #{taskStart}</if>
            <if test="taskEnd != null  and taskEnd != ''"> and task_end = #{taskEnd}</if>
            <if test="prizes != null  and prizes != ''"> and prizes = #{prizes}</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="selectSysPerformanceTaskById" parameterType="Long" resultMap="SysPerformanceTaskResult">
        <include refid="selectSysPerformanceTaskVo"/>
        where id = #{id}
    </select>

    <!--根据填报人、年份查询-->
    <select id="selectSysPerformanceTaskByFdyName" parameterType="String"
            resultMap="SysPerformanceTaskResult">
        <include refid="selectSysPerformanceTaskVo"/>
        <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="insertSysPerformanceTask" parameterType="SysPerformanceTask" useGeneratedKeys="true" keyProperty="id">
        insert into sys_performance_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskDescribe != null">task_describe,</if>
            <if test="taskStart != null">task_start,</if>
            <if test="taskEnd != null">task_end,</if>
            <if test="prizes != null">prizes,</if>
            <if test="years != null">years,</if>
            <if test="fdName != null">fd_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskDescribe != null">#{taskDescribe},</if>
            <if test="taskStart != null">#{taskStart},</if>
            <if test="taskEnd != null">#{taskEnd},</if>
            <if test="prizes != null">#{prizes},</if>
            <if test="years != null">#{years},</if>
            <if test="fdName != null">#{fdName},</if>
         </trim>
    </insert>

    <update id="updateSysPerformanceTask" parameterType="SysPerformanceTask">
        update sys_performance_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskDescribe != null">task_describe = #{taskDescribe},</if>
            <if test="taskStart != null">task_start = #{taskStart},</if>
            <if test="taskEnd != null">task_end = #{taskEnd},</if>
            <if test="prizes != null">prizes = #{prizes},</if>
            <if test="years != null">years = #{years},</if>
            <if test="fdName != null">fd_name = #{fdName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysPerformanceTaskById" parameterType="Long">
        delete from sys_performance_task where id = #{id}
    </delete>

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