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

    <select id="queryInfoThatCurrentUserNeedsToApprove" resultType="java.lang.String">
        SELECT
            DISTINCT
            run.F_BusinessId
        FROM
            ftb_personnels_audit_run_task AS run
                INNER JOIN ftb_personnels_audit_master_config AS mas ON run.F_MasterAuditConfigId = mas.F_Id
        WHERE run.F_UserId =#{userId} AND mas.F_ConfigType =#{configType}

    </select>

    <select id="queryMyApprovedReviewProcess" resultType="java.lang.String">
        SELECT DISTINCT
            run.F_BusinessId
        FROM
            ftb_personnels_audit_task_info AS info
                LEFT JOIN ftb_personnels_audit_run_task AS run ON run.F_Id = info.F_RunTaskId
                INNER JOIN ftb_personnels_audit_master_config AS mas ON run.F_MasterAuditConfigId = mas.F_Id
        WHERE
            info.F_UserId = #{userId}
          AND mas.F_ConfigType = #{configType}
          AND info.F_ApprovalResult IN (0,1)
        UNION
        SELECT DISTINCT
            history.F_BusinessId
        FROM
            ftb_personnels_audit_task_info AS info
                LEFT JOIN ftb_personnels_audit_run_task_history AS history ON history.F_Id = info.F_RunTaskId
                INNER JOIN ftb_personnels_audit_master_config AS mas ON history.F_MasterAuditConfigId = mas.F_Id
        WHERE
            info.F_UserId = #{userId}
          AND mas.F_ConfigType = #{configType}
          AND info.F_ApprovalResult IN (0,1)
    </select>

    <select id="queryHaveRuntask" resultType="java.lang.String">
        select
        run.F_MasterAuditConfigId as masterAuditConfigId
        from ftb_personnels_audit_run_task as run
        inner join ftb_personnels_audit_master_config as mas on run.F_MasterAuditConfigId = mas.F_Id
        inner  join ftb_personnels_audit_sub_config as sub on mas.F_Id = sub.F_MasterId
        where run.F_BusinessId = #{businessId} and mas.F_ConfigType =#{configType}
        and sub.F_AuditorId =#{userId}

    </select>
</mapper>