<?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.tofly.qualitycontrol.mapper.PlanAuditorMapper">
    <resultMap id="planAuditorMap" type="com.tofly.qualitycontrol.entity.PlanAuditor">
        <id property="id" column="ID"/>
        <result property="planId" column="PLAN_ID"/>
        <result property="auditLevel" column="AUDIT_LEVEL"/>
        <result property="auditorId" column="AUDITOR_ID"/>
        <result property="auditorName" column="AUDITOR_NAME"/>
        <result property="auditorDeptId" column="AUDITOR_DEPT_ID"/>
        <result property="auditorDeptName" column="AUDITOR_DEPT_NAME"/>
        <result property="status" column="STATUS"/>
    </resultMap>

    <insert id="insertBatch">
        INSERT INTO
        TF_YWPN_ZJJHRY_W
        (ID,
        PLAN_ID,
        AUDIT_LEVEL,
        AUDITOR_ID,
        AUDITOR_NAME,
        AUDITOR_DEPT_ID,
        AUDITOR_DEPT_NAME,
        STATUS)
        <foreach collection="planAuditorList" item="planAuditor" separator="union all">
            SELECT
            #{planAuditor.id},
            #{planAuditor.planId},
            #{planAuditor.auditLevel},
            #{planAuditor.auditorId},
            #{planAuditor.auditorName},
            #{planAuditor.auditorDeptId},
            #{planAuditor.auditorDeptName},
            #{planAuditor.status}
            FROM DUAL
        </foreach>
    </insert>

    <select id="getCurrentId" resultType="java.lang.Long">
        select nvl(max(id),0)+1 from TF_YWPN_ZJJHRY_W
    </select>

    <select id="getMaxLevel" resultType="java.lang.Integer">
        select nvl(max(AUDIT_LEVEL),0) from TF_YWPN_ZJJHRY_W WHERE PLAN_ID = #{id}
    </select>

</mapper>