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

    <resultMap type="SysTeacherKpiFillingAuditRecord" id="SysTeacherKpiFillingAuditRecordResult">
        <result property="auditRecordId" column="audit_record_id"/>
        <result property="fdyName" column="fdy_name"/>
        <result property="jobNumber" column="job_number"/>
        <result property="fillingYear" column="filling_year"/>
        <result property="fillingMonth" column="filling_month"/>
        <result property="auditStatus" column="audit_status"/>
        <result property="roleAudit" column="role_audit"/>
        <result property="departmentName" column="departmentName"/>
        <result property="xwOpinion" column="xw_opinion"/>
        <result property="dzzsjOpinion" column="dzzsj_opinion"/>
        <result property="ksOpinion" column="ks_opinion"/>
        <result property="xgczOpinion" column="xgcz_opinion"/>
        <result property="auditName" column="audit_name"/>
        <result property="auditTime" column="audit_time"/>
    </resultMap>

    <sql id="selectSysTeacherKpiFillingAuditRecordVo">
        select audit_record_id,
               fdy_name,
               job_number,
               filling_year,
               filling_month,
               audit_status,
               role_audit,
               departmentName,
               xw_opinion,
               dzzsj_opinion,
               ks_opinion,
               xgcz_opinion,
               audit_name,
               audit_time
        from sys_teacher_kpi_filling_audit_record
    </sql>

    <select id="selectSysTeacherKpiFillingAuditRecordList" parameterType="SysTeacherKpiFillingAuditRecord"
            resultMap="SysTeacherKpiFillingAuditRecordResult">
        <include refid="selectSysTeacherKpiFillingAuditRecordVo"/>
        <where>
            <if test="fdyName != null  and fdyName != ''">and fdy_name like concat('%', #{fdyName}, '%')</if>
            <if test="jobNumber != null  and jobNumber != ''">and job_number = #{jobNumber}</if>
            <if test="fillingYear != null  and fillingYear != ''">and filling_year = #{fillingYear}</if>
            <if test="fillingMonth != null  and fillingMonth != ''">and filling_month = #{fillingMonth}</if>
            <if test="auditStatus != null ">and audit_status = #{auditStatus}</if>
            <if test="roleAudit != null ">and role_audit = #{roleAudit}</if>
            <if test="departmentName != null  and departmentName != ''">and departmentName like concat('%',
                #{departmentName}, '%')
            </if>
            <if test="xwOpinion != null  and xwOpinion != ''">and xw_opinion = #{xwOpinion}</if>
            <if test="dzzsjOpinion != null  and dzzsjOpinion != ''">and dzzsj_opinion = #{dzzsjOpinion}</if>
            <if test="ksOpinion != null  and ksOpinion != ''">and ks_opinion = #{ksOpinion}</if>
            <if test="xgczOpinion != null  and xgczOpinion != ''">and xgcz_opinion = #{xgczOpinion}</if>
            <if test="auditName != null  and auditName != ''">and audit_name = #{auditName}</if>
            <if test="auditTime != null "> and audit_time = #{auditTime}</if>
        </where>
        order by audit_record_id desc
    </select>

    <select id="selectSysTeacherKpiFillingAuditRecordByAuditRecordId" parameterType="Long"
            resultMap="SysTeacherKpiFillingAuditRecordResult">
        <include refid="selectSysTeacherKpiFillingAuditRecordVo"/>
        where audit_record_id = #{auditRecordId}
    </select>

    <!--根据名称、年份、月份查询-->
    <select id="selectSysTeacherKpiFillingAuditRecordByFdyName" parameterType="String"
            resultMap="SysTeacherKpiFillingAuditRecordResult">
        <include refid="selectSysTeacherKpiFillingAuditRecordVo"/>
        <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>
            <if test="auditName != null and auditName != ''">
                and audit_name = #{auditName}
            </if>
        </where>
        order by audit_record_id desc
    </select>

    <insert id="insertSysTeacherKpiFillingAuditRecord" parameterType="SysTeacherKpiFillingAuditRecord">
        insert into sys_teacher_kpi_filling_audit_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="auditRecordId != null">audit_record_id,</if>
            <if test="fdyName != null and fdyName != ''">fdy_name,</if>
            <if test="jobNumber != null and jobNumber != ''">job_number,</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year,</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month,</if>
            <if test="auditStatus != null">audit_status,</if>
            <if test="roleAudit != null">role_audit,</if>
            <if test="departmentName != null and departmentName != ''">departmentName,</if>
            <if test="xwOpinion != null">xw_opinion,</if>
            <if test="dzzsjOpinion != null">dzzsj_opinion,</if>
            <if test="ksOpinion != null">ks_opinion,</if>
            <if test="xgczOpinion != null">xgcz_opinion,</if>
            <if test="auditName != null">audit_name,</if>
            <if test="auditTime != null">audit_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="auditRecordId != null">#{auditRecordId},</if>
            <if test="fdyName != null and fdyName != ''">#{fdyName},</if>
            <if test="jobNumber != null and jobNumber != ''">#{jobNumber},</if>
            <if test="fillingYear != null and fillingYear != ''">#{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">#{fillingMonth},</if>
            <if test="auditStatus != null">#{auditStatus},</if>
            <if test="roleAudit != null">#{roleAudit},</if>
            <if test="departmentName != null and departmentName != ''">#{departmentName},</if>
            <if test="xwOpinion != null">#{xwOpinion},</if>
            <if test="dzzsjOpinion != null">#{dzzsjOpinion},</if>
            <if test="ksOpinion != null">#{ksOpinion},</if>
            <if test="xgczOpinion != null">#{xgczOpinion},</if>
            <if test="auditName != null">#{auditName},</if>
            <if test="auditTime != null">#{auditTime},</if>
        </trim>
    </insert>

    <!--批量新增-->
    <insert id="insertSysTeacherKpiFillingAuditRecordBatch" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";">
            insert into sys_teacher_kpi_filling_audit_record
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.auditRecordId != null">audit_record_id,</if>
                <if test="item.fdyName != null and item.fdyName != ''">fdy_name,</if>
                <if test="item.jobNumber != null and item.jobNumber != ''">job_number,</if>
                <if test="item.fillingYear != null and item.fillingYear != ''">filling_year,</if>
                <if test="item.fillingMonth != null and item.fillingMonth != ''">filling_month,</if>
                <if test="item.auditStatus != null">audit_status,</if>
                <if test="item.roleAudit != null">role_audit,</if>
                <if test="item.departmentName != null and item.departmentName != ''">departmentName,</if>
                <if test="item.xwOpinion != null">xw_opinion,</if>
                <if test="item.dzzsjOpinion != null">dzzsj_opinion,</if>
                <if test="item.ksOpinion != null">ks_opinion,</if>
                <if test="item.xgczOpinion != null">xgcz_opinion,</if>
                <if test="item.auditName != null">audit_name,</if>
                <if test="item.auditTime != null">audit_time,</if>
                <!-- 可能还需要一个主键字段，如果数据库自动生成则忽略 -->
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="item.auditRecordId != null">#{item.auditRecordId},</if>
                <if test="item.fdyName != null and item.fdyName != ''">#{item.fdyName},</if>
                <if test="item.jobNumber != null and item.jobNumber != ''">#{item.jobNumber},</if>
                <if test="item.fillingYear != null and item.fillingYear != ''">#{item.fillingYear},</if>
                <if test="item.fillingMonth != null and item.fillingMonth != ''">#{item.fillingMonth},</if>
                <if test="item.auditStatus != null">#{item.auditStatus},</if>
                <if test="item.roleAudit != null">#{item.roleAudit},</if>
                <if test="item.departmentName != null and item.departmentName != ''">#{item.departmentName},</if>
                <if test="item.xwOpinion != null">#{item.xwOpinion},</if>
                <if test="item.dzzsjOpinion != null">#{item.dzzsjOpinion},</if>
                <if test="item.ksOpinion != null">#{item.ksOpinion},</if>
                <if test="item.xgczOpinion != null">#{item.xgczOpinion},</if>
                <if test="item.auditName != null">#{item.auditName},</if>
                <if test="item.auditTime != null">#{item.auditTime},</if>
                <!-- 如果有主键字段且非自动生成，这里也需要插入 -->
            </trim>
        </foreach>
    </insert>

    <update id="updateSysTeacherKpiFillingAuditRecord" parameterType="SysTeacherKpiFillingAuditRecord">
        update sys_teacher_kpi_filling_audit_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="fdyName != null and fdyName != ''">fdy_name = #{fdyName},</if>
            <if test="jobNumber != null and jobNumber != ''">job_number = #{jobNumber},</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year = #{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month = #{fillingMonth},</if>
            <if test="auditStatus != null">audit_status = #{auditStatus},</if>
            <if test="roleAudit != null">role_audit = #{roleAudit},</if>
            <if test="departmentName != null and departmentName != ''">departmentName = #{departmentName},</if>
            <if test="xwOpinion != null">xw_opinion = #{xwOpinion},</if>
            <if test="dzzsjOpinion != null">dzzsj_opinion = #{dzzsjOpinion},</if>
            <if test="ksOpinion != null">ks_opinion = #{ksOpinion},</if>
            <if test="xgczOpinion != null">xgcz_opinion = #{xgczOpinion},</if>
            <if test="auditName != null">audit_name = #{auditName},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
        </trim>
        where audit_record_id = #{auditRecordId}
    </update>

    <delete id="deleteSysTeacherKpiFillingAuditRecordByAuditRecordId" parameterType="Long">
        delete
        from sys_teacher_kpi_filling_audit_record
        where audit_record_id = #{auditRecordId}
    </delete>

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