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

    <select id="getRunTaskInfos" resultType="jnpf.model.personnels.vo.config.FtbPersonnelsAuditRunTaskInfo">
        SELECT
        task.F_Id as id,
        a.F_AuditorId as auditorId,
        roster.F_Name auditorName,
        a.F_PostId postId,
        a.F_PostName postName,
        a.F_GradeId gradeId,
        a.F_GradeName gradeName,
        task.F_PayrollEntry payrollEntry,
        task.F_PayrollAudit payrollAudit,
        IFNULL(task.F_ApprovalResult,4)	 approvalResult,
        task.F_ApprovalOpinion approvalOpinion,
        task.F_CreatorTime creatorTime,
        task.F_LastModifyTime lastModifyTime,
        task.F_IsBeBlackList blacklistFilling,
        task.F_BlackListPeriod as blackListPeriod,
        task.F_BlackTypeId as blackTypeId,
        type.F_RegularName as blackTypeName,
        task.F_BlacklistCause as blacklistCause,
        a.F_AuditProcessLevel auditProcessLevel,
        a.F_OrgId orgId,
        a.F_OrgName orgName
        FROM
        (
        SELECT
        sub.*,
        mas.F_Id AS MasId,
        mas.F_ConfigType,
        mas.F_IsApprovalComments,
        mas.F_IsOnePersonPasses
        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_Id = #{masterAuditConfigId}
        ) a
        INNER JOIN ftb_personnels_audit_run_task AS run ON a.MasId = run.F_MasterAuditConfigId
        LEFT JOIN ftb_personnels_audit_task_info AS task ON run.F_Id = task.F_RunTaskId AND task.F_UserId = a.F_AuditorId
        left join ftb_personnels_blacklist_type as type on  type.F_Id = task.F_BlackTypeId
        left join ftb_personnels_staff_roster as roster on  roster.F_UserId = a.F_AuditorId
        WHERE
        run.F_BusinessId = #{id}
        ORDER BY
        a.F_AuditProcessLevel
    </select>

    <select id="getHisTaskInfos" resultType="jnpf.model.personnels.vo.config.FtbPersonnelsAuditRunTaskInfo">
        SELECT
        task.F_Id as id,
        a.F_AuditorId as auditorId,
        roster.F_Name auditorName,
        a.F_PostId postId,
        a.F_PostName postName,
        a.F_GradeId gradeId,
        a.F_GradeName gradeName,
        task.F_PayrollEntry payrollEntry,
        task.F_PayrollAudit payrollAudit,
        IFNULL(task.F_ApprovalResult,4)	 approvalResult,
        task.F_ApprovalOpinion approvalOpinion,
        task.F_CreatorTime creatorTime,
        task.F_LastModifyTime lastModifyTime,
        a.F_AuditProcessLevel auditProcessLevel,
        task.F_IsBeBlackList blacklistFilling,
        task.F_BlackListPeriod as blackListPeriod,
        task.F_BlackTypeId as blackTypeId,
        type.F_RegularName as blackTypeName,
        task.F_BlacklistCause as blacklistCause,
        a.F_OrgId orgId,
        a.F_OrgName orgName
        FROM
        (
        SELECT
        sub.*,
        mas.F_Id AS MasId,
        mas.F_ConfigType,
        mas.F_IsApprovalComments,
        mas.F_IsOnePersonPasses
        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_Id = #{masterAuditConfigId}
        ) a
        INNER JOIN ftb_personnels_audit_run_task_history AS hist ON a.MasId = hist.F_MasterAuditConfigId
        LEFT JOIN ftb_personnels_audit_task_info AS task ON hist.F_Id = task.F_RunTaskId AND task.F_UserId = a.F_AuditorId
        left join ftb_personnels_staff_roster as roster on  roster.F_UserId = a.F_AuditorId
        left join ftb_personnels_blacklist_type as type on  type.F_Id = task.F_BlackTypeId
        WHERE
        hist.F_Id = #{id}
        ORDER BY
        a.F_AuditProcessLevel
    </select>
</mapper>