<?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="jnpf.personnels.mapper.FtbPersonnelsAuditSubConfigMapper">

    <select id="queryInitializeExecutionNode" resultType="jnpf.model.personnels.po.FtbPersonnelsAuditSubConfig">
        SELECT
        sub.F_Id id,
        sub.F_MasterId masterId,
        sub.F_AuditorId auditorId,
        sub.F_AuditorName auditorName,
        sub.F_PostId postId,
        sub.F_PostName postName,
        sub.F_GradeId gradeId,
        sub.F_GradeName gradeName,
        sub.F_PayrollEntry payrollEntry,
        sub.F_PayrollAudit payrollAudit,
        sub.F_AuditProcessLevel auditProcessLevel,
        sub.F_PreReview preReview,
        sub.F_NextReview nextReview,
        sub.F_EnableMark enableMark
        FROM
            ftb_personnels_audit_master_config AS mas
                LEFT JOIN ftb_personnels_audit_sub_config AS sub ON mas.F_Id = sub.F_MasterId
        WHERE
            mas.F_ConfigType =#{type}
          AND mas.F_OrgId =#{orgId}
        and mas.F_EnableMark = 0
        <if test="isOnePersonPasses != null and isOnePersonPasses != 1 ">
            AND sub.F_PreReview='0'
        </if>
        ORDER BY sub.F_AuditProcessLevel
    </select>

    <select id="queryAuditSubConfig" resultType="jnpf.model.personnels.dto.audit.FtbPersonnelsAuditSubConfigVO">
        SELECT
            mas.F_IsApprovalComments isTheReviewRequired ,
            sub.F_PayrollEntry entryRequired,
            sub.F_PayrollAudit payrollRequired,
            sub.F_BlacklistFilling blacklistFilling,
            mas.F_IsOnePersonPasses isOnePersonPasses

        FROM
            ftb_personnels_audit_master_config AS mas
                INNER JOIN ftb_personnels_audit_sub_config AS sub ON mas.F_Id = sub.F_MasterId
        WHERE
            sub.F_AuditorId =#{userId}
          AND mas.F_OrgId = #{orgId}
        And mas.F_ConfigType = #{configType}
        and mas.F_EnableMark = 0
    </select>

    <select id="queryUserBound" resultType="jnpf.model.personnels.dto.config.MasterConfigUserBoudDto">

        SELECT
            sub.F_PostId AS positionId,
            sub.F_GradeId AS positionGradesId,
            sub.F_OrgId AS orgId,
            sub.F_OrgName AS orgName,
            sub.F_AuditorId AS userId,
            sub.F_AuditorName,
            mas.F_Id as masterId,
            mas.F_ConfigType as configType
        FROM
            ftb_personnels_audit_master_config AS mas
                INNER JOIN ftb_personnels_audit_sub_config AS sub ON mas.F_Id = sub.F_MasterId
        WHERE
            sub.F_AuditorId = #{userId}
          AND mas.F_EnableMark = 0
        GROUP BY mas.F_Id
    </select>

    <select id="isItAnApprover" resultType="java.util.Map">
        SELECT DISTINCT
            mas.F_OrgId orgId,
            mas.F_ConfigType AS configType
        FROM
            `ftb_personnels_audit_sub_config` AS sub
                LEFT JOIN ftb_personnels_audit_master_config AS mas ON sub.F_MasterId = mas.F_Id
        WHERE
            sub.F_AuditorId = #{userId}
          and mas.F_EnableMark = '0'
    </select>
</mapper>