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

    <resultMap type="SysTeacherKpiFillingRewardsKpi" id="SysTeacherKpiFillingRewardsKpiResult">
        <result property="id" column="id"/>
        <result property="dutyDescription" column="duty_description"/>
        <result property="dutyTime" column="duty_time"/>
        <result property="dutyUserName" column="duty_user_name"/>
        <result property="fdyName" column="fdy_name"/>
        <result property="fillingYear" column="filling_year"/>
        <result property="fillingMonth" column="filling_month"/>
    </resultMap>

    <sql id="selectSysTeacherKpiFillingRewardsKpiVo">
        select id, duty_description, duty_time, duty_user_name, fdy_name, filling_year, filling_month
        from sys_teacher_kpi_filling_rewards_kpi
    </sql>

    <select id="selectSysTeacherKpiFillingRewardsKpiList" parameterType="SysTeacherKpiFillingRewardsKpi"
            resultMap="SysTeacherKpiFillingRewardsKpiResult">
        <include refid="selectSysTeacherKpiFillingRewardsKpiVo"/>
        <where>
            <if test="dutyDescription != null  and dutyDescription != ''">and duty_description = #{dutyDescription}</if>
            <if test="dutyTime != null ">and duty_time = #{dutyTime}</if>
            <if test="dutyUserName != null  and dutyUserName != ''">and duty_user_name like concat('%', #{dutyUserName},
                '%')
            </if>
            <if test="fdyName != null  and fdyName != ''">and fdy_name like concat('%', #{fdyName}, '%')</if>
            <if test="fillingYear != null  and fillingYear != ''">and filling_year = #{fillingYear}</if>
            <if test="fillingMonth != null  and fillingMonth != ''">and filling_month = #{fillingMonth}</if>
        </where>
        order by id desc
    </select>

    <select id="selectSysTeacherKpiFillingRewardsKpiById" parameterType="Long"
            resultMap="SysTeacherKpiFillingRewardsKpiResult">
        <include refid="selectSysTeacherKpiFillingRewardsKpiVo"/>
        where id = #{id}
    </select>

    <!--根据名称、年份、月份查询-->
    <select id="selectSysTeacherKpiFillingRewardsKpiByFdyName" parameterType="String"
            resultMap="SysTeacherKpiFillingRewardsKpiResult">
        <include refid="selectSysTeacherKpiFillingRewardsKpiVo"/>
        <where>
            <if test="fdyName != null and fdyName != ''">
                and fdy_name = #{fdyName}
            </if>
            <if test="fillingYear != null and fillingYear != ''">
                and filling_year = #{fillingYear}
            </if>
            <if test="fillingMonth != null and fillingMonth != ''">
                and filling_month = #{fillingMonth}
            </if>
        </where>
        order by id desc
    </select>

    <insert id="insertSysTeacherKpiFillingRewardsKpi" parameterType="SysTeacherKpiFillingRewardsKpi"
            useGeneratedKeys="true" keyProperty="id">
        insert into sys_teacher_kpi_filling_rewards_kpi
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dutyDescription != null and dutyDescription != ''">duty_description,</if>
            <if test="dutyTime != null">duty_time,</if>
            <if test="dutyUserName != null and dutyUserName != ''">duty_user_name,</if>
            <if test="fdyName != null and fdyName != ''">fdy_name,</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year,</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dutyDescription != null and dutyDescription != ''">#{dutyDescription},</if>
            <if test="dutyTime != null">#{dutyTime},</if>
            <if test="dutyUserName != null and dutyUserName != ''">#{dutyUserName},</if>
            <if test="fdyName != null and fdyName != ''">#{fdyName},</if>
            <if test="fillingYear != null and fillingYear != ''">#{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">#{fillingMonth},</if>
        </trim>
    </insert>

    <update id="updateSysTeacherKpiFillingRewardsKpi" parameterType="SysTeacherKpiFillingRewardsKpi">
        update sys_teacher_kpi_filling_rewards_kpi
        <trim prefix="SET" suffixOverrides=",">
            <if test="dutyDescription != null and dutyDescription != ''">duty_description = #{dutyDescription},</if>
            <if test="dutyTime != null">duty_time = #{dutyTime},</if>
            <if test="dutyUserName != null and dutyUserName != ''">duty_user_name = #{dutyUserName},</if>
            <if test="fdyName != null and fdyName != ''">fdy_name = #{fdyName},</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year = #{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month = #{fillingMonth},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysTeacherKpiFillingRewardsKpiById" parameterType="Long">
        delete
        from sys_teacher_kpi_filling_rewards_kpi
        where id = #{id}
    </delete>

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