<?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.FtbPersonnelsStaffTransferPositionMapper">
    <sql id="Base_Column_List">
        SELECT a.`F_Id`               as id,
               a.`F_Phone`            as phone,
               a.`F_UserId`           as userId,
               a.`F_ToOrg`            as toOrg,
               a.`F_ToPositionId`     as toPositionId,
               a.`F_ToRankId`         as toRankId,
               a.`F_ToRole`           as toRole,
               a.`F_ToManager`        as toManager,
               a.`F_FromOrg`          as fromOrg,
               a.`F_FromPositionId`   as fromPositionId,
               a.`F_FromRankId`       as fromRankId,
               a.`F_TransferDate`     as transferDate,
               a.`F_FromManager`      as fromManager,
               a.`F_ToMoney`          AS toMoney,
               a.`F_Remarks`          AS remarks,
               a.`F_OpUser`          AS opUser,
               a.`F_OpUserName`      AS opUserName,
               a.`F_Files`            AS files,
               a.`F_IsNeedCheck`      AS isNeedCheck,
               a.`F_CheckStatus`      AS checkStatus,
               a.`F_EnabledMark`      AS enabledMark,
               a.`F_CreatorUserId`    AS createrUserId,
               a.`F_CreatorTime`      AS creatorTime,
               a.`F_LastModifyUserId` as lastModifyUserId,
               a.`F_LastModifyTime`   as lastModifyTime,
               a.`F_DeleteUserId`     as deleteUserId,
               a.`F_DeleteTime`       as deleteTime,
               a.`F_TenantId`         AS tenantId,
               a.F_AttendanceGroup    as attendanceGroup,
               b.`F_Id`               AS staffRosterId,
               b.`F_Name`             AS `name`,
               b.`F_WorkerNo`         AS workerNo,
               b.`F_CurrOrg`          AS currOrg,
               b.`F_CurrPosition`     AS currPosition,
               b.`F_CurrRank`         AS currRank,
               b.`F_ContractType`     AS contractType,
               b.`F_ActualStartDate`  AS actualStartDate,
               b.`F_WorkerType`       AS workerType,
               b.`F_SystemContractId` AS systemContractId,
               b.`F_ActualStartDate`  AS actualStartDate,
               b.`F_ActualProbationaryDate` AS actualProbationaryDate,
               b.`F_EntrySalary`  AS entrySalary,
               b.`F_CurrSalary` as currSalary,
               b.`F_RegularSalary` as regularSalary,
               b.`F_SystemWokerId`    AS systemWokerId,
               b.`F_WorkerStatus`     AS workerStatus,
               a.`F_TaskInfoId`    AS taskInfoId,
               a.`F_SalaryStructure`    AS salaryStructure,
               a.`F_IsAdjustSalary`    AS isAdjustSalary,
               a.`F_PayrollEffectiveDate` as payrollEffectiveDate,
               a.F_SalaryStructureList as salaryStructureStr,
            a.F_VersionNum as versionNum,
            a.F_ReasonsForSalary as reasonsForSalaryAdjustments,
            a.F_Source as source
        FROM `ftb_personnels_staff_transfer_position` as a
                  join ftb_personnels_staff_roster as b on a.F_UserId = b.F_UserId
    </sql>

    <select id="complatePagingQuery" resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        <include refid="Base_Column_List"></include>

        <where>
            a.F_EnabledMark = 0 and (a.F_IsNeedCheck=1 or (a.F_IsNeedCheck=0 and a.F_CheckStatus=2))
            <if test="params.keyWord!= null and params.keyWord!= ''">
                and (
                a.F_Phone like CONCAT('%',#{params.keyWord},'%')
                or b.F_Name like CONCAT('%',#{params.keyWord},'%')
                or b.F_WorkerNo like CONCAT('%',#{params.keyWord},'%')
                )
            </if>
            <if test="params.userId != null and params.userId != ''">
                and a.F_UserId =#{params.userId} and ( a.F_CheckStatus = 2 or a.F_IsNeedCheck = 1)
            </if>

            <if test="params.orgId!= null and params.orgId!= ''">
                and find_in_set(a.F_ToOrg,#{params.orgId}) > 0
            </if>

            <if test="params.positionId!= null and params.positionId!= ''">
                and a.F_ToPositionId =#{params.positionId}
            </if>

            <if test="params.rankId!= null and params.rankId!= ''">
                and a.F_ToRankId =#{params.rankId}
            </if>


            <if test="params.startTransferDate!= null and params.endTransferDate!= null">
                and a.F_TransferDate between #{params.startTransferDate} and #{params.endTransferDate}
            </if>

            <if test="orgIds != null and orgIds.size() > 0 ">
                and a.F_FromOrg in
                <foreach collection="orgIds" item="item" open="("  separator="," close=")">
                    #{item}
                </foreach>
            </if>

        </where>
        order by a.F_CreatorTime desc

    </select>
    <select id="waitCheckPagingQuery"
            resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        <include refid="Base_Column_List"></include>
        <where>
            a.F_EnabledMark = 0 and  a.F_IsNeedCheck=0 and  a.F_CheckStatus != 2
            <if test="params.keyWord!= null and params.keyWord!= ''">
                and (
                a.F_Phone like CONCAT('%',#{params.keyWord},'%')
                or b.F_Name like CONCAT('%',#{params.keyWord},'%')
                or b.F_WorkerNo like CONCAT('%',#{params.keyWord},'%')
                )
            </if>
            <if test="params.checkStatus!= null and params.checkStatus!=''">
                and a.F_CheckStatus =#{params.checkStatus}
            </if>
            <if test="params.orgId!= null and params.orgId!= ''">
                and find_in_set(a.F_ToOrg,#{params.orgId}) > 0
            </if>

            <if test="params.positionId!= null and params.positionId!= ''">
                and a.F_ToPositionId =#{params.positionId}
            </if>

            <if test="params.rankId!= null and params.rankId!= ''">
                and a.F_ToRankId =#{params.rankId}
            </if>


            <if test="params.startTransferDate!= null and params.endTransferDate!= null">
                and a.F_TransferDate between #{params.startTransferDate} and #{params.endTransferDate}
            </if>

            <if test="orgIds != null and orgIds.size() > 0 ">
                and a.F_FromOrg in
                <foreach collection="orgIds" item="item" open="("  separator="," close=")">
                    #{item}
                </foreach>
            </if>

        </where>
        order by a.F_CreatorTime desc


    </select>
    <select id="myPagingQuery" resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        <include refid="Base_Column_List"></include>
        <where>
            a.F_EnabledMark = 0 and a.F_UserId = #{loginUserId}
        </where>
        order by a.F_CreatorTime desc
    </select>
    <select id="queryNoCompleteForUserId"
            resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        SELECT a.`F_Id`               as id,
        a.`F_Phone`            as phone,
        a.`F_UserId`           as userId,
        a.`F_ToOrg`            as toOrg,
        a.`F_ToPositionId`     as toPositionId,
        a.`F_ToRankId`         as toRankId,
        a.`F_ToRole`           as toRole,
        a.`F_ToManager`        as toManager,
        a.`F_FromOrg`          as fromOrg,
        a.`F_FromPositionId`   as fromPositionId,
        a.`F_FromRankId`       as fromRankId,
        a.`F_TransferDate`     as transferDate,
        a.`F_FromManager`      as fromManager,
        a.`F_ToMoney`          AS toMoney,
        a.`F_Remarks`          AS remarks,
        a.`F_Files`            AS files,
        a.`F_IsNeedCheck`      AS isNeedCheck,
        a.`F_CheckStatus`      AS checkStatus,
        a.`F_EnabledMark`      AS enabledMark,
        a.`F_CreatorUserId`    AS createrUserId,
        a.`F_CreatorTime`      AS creatorTime,
        a.`F_LastModifyUserId` as lastModifyUserId,
        a.`F_LastModifyTime`   as lastModifyTime,
        a.`F_DeleteUserId`     as deleteUserId,
        a.`F_DeleteTime`       as deleteTime,
        a.`F_TenantId`         AS tenantId,
        a.F_TaskInfoId taskInfoId,
        a.F_VersionNum versionNum
        FROM `ftb_personnels_staff_transfer_position` as a
        where a.F_UserId = #{userId}
        and a.F_EnabledMark = 0
        and a.F_IsNeedCheck = 0
        and a.F_CheckStatus in (0, 1)

    </select>
    <select id="getInfoForId" resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        <include refid="Base_Column_List"></include>
        where  a.F_EnabledMark = 0 and a.F_Id = #{id}
    </select>
    <select id="appPagingQuery" resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        <include refid="Base_Column_List"></include>
        <where>
            a.F_EnabledMark = 0
            <if test="params.keyWord!= null and params.keyWord!= ''">
                and (
                a.F_Phone like CONCAT('%',#{params.keyWord},'%')
                or b.F_Name like CONCAT('%',#{params.keyWord},'%')
                or b.F_WorkerNo like CONCAT('%',#{params.keyWord},'%')
                )
            </if>

            <if test="orgIds != null and orgIds.size() > 0 ">
                and a.F_FromOrg in
                <foreach collection="orgIds" item="item" open="("  separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by a.F_CreatorTime desc

    </select>
    <select id="getListByRegularForApp"
            resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        SELECT a.`F_Id`               as id,
        a.`F_Phone`            as phone,
        a.`F_UserId`           as userId,
        a.`F_ToOrg`            as toOrg,
        a.`F_ToPositionId`     as toPositionId,
        a.`F_ToRankId`         as toRankId,
        a.`F_ToRole`           as toRole,
        a.`F_ToManager`        as toManager,
        a.`F_FromOrg`          as fromOrg,
        a.`F_FromPositionId`   as fromPositionId,
        a.`F_FromRankId`       as fromRankId,
        a.`F_TransferDate`     as transferDate,
        a.`F_FromManager`      as fromManager,
        a.`F_ToMoney`          AS toMoney,
        a.`F_Remarks`          AS remarks,
        a.`F_Files`            AS files,
        a.F_OpUser            as opUser,
        a.F_OpUserName        as opUserName,
        a.`F_IsNeedCheck`      AS isNeedCheck,
        a.`F_CheckStatus`      AS checkStatus,
        a.`F_EnabledMark`      AS enabledMark,
        a.`F_CreatorUserId`    AS createrUserId,
        a.`F_CreatorTime`      AS creatorTime,
        a.`F_LastModifyUserId` as lastModifyUserId,
        a.`F_LastModifyTime`   as lastModifyTime,
        a.`F_DeleteUserId`     as deleteUserId,
        a.`F_DeleteTime`       as deleteTime,
        a.`F_TenantId`         AS tenantId,
        b.`F_Id`               AS staffRosterId,
        b.`F_Name`             AS `name`,
        b.`F_WorkerNo`         AS workerNo,
        b.`F_CurrOrg`          AS currOrg,
        b.`F_CurrPosition`     AS currPosition,
        b.`F_CurrRank`         AS currRank,
        b.`F_ContractType`     AS contractType,
        b.`F_ActualStartDate`  AS actualStartDate,
        b.`F_WorkerType`       AS workerType,
        b.`F_SystemContractId` AS systemContractId,
        b.`F_SystemWokerId`    AS systemWokerId,
        info.F_ApprovalResult approvalResult,
        a.F_TaskInfoId as taskInfoId
        FROM `ftb_personnels_staff_transfer_position` as a
        left join ftb_personnels_staff_roster as b on a.F_UserId = b.F_UserId
        left JOIN ftb_personnels_audit_run_task AS run ON run.F_BusinessId = a.F_Id
        <if test="dto.checkStatus != null and dto.checkStatus != 0 ">
            left JOIN ftb_personnels_audit_run_task_history AS his ON his.F_BusinessId = a.F_Id
        </if>
        left JOIN ftb_personnels_audit_task_info AS info ON (run.F_Id = info.F_RunTaskId
        <if test="dto.checkStatus != null and dto.checkStatus != 0 ">
            or his.F_Id = info.F_RunTaskId
        </if>
        )
        <where>

            <if test="dto.checkStatus != null and dto.checkStatus ==0">
                and a.F_CheckStatus in (0,1)
                and run.F_UserId =#{checkUserId}
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus ==2">
                and a.F_CheckStatus in (2)
                and  info.F_UserId =#{checkUserId}
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus ==3">
                and a.F_CheckStatus in (3)
                and  info.F_UserId =#{checkUserId}
            </if>
        </where>

    </select>

    <select id="getCountByRegularForApp" resultType="java.lang.Integer">
        SELECT count(*)
        FROM `ftb_personnels_staff_transfer_position` as a
        left join ftb_personnels_staff_roster as b on a.F_UserId = b.F_UserId
        INNER JOIN ftb_personnels_audit_run_task AS run ON run.F_BusinessId = a.F_Id
        INNER JOIN ftb_personnels_audit_task_info AS info ON run.F_Id = info.F_RunTaskId
        <where>

            <if test="dto.checkStatus != null and dto.checkStatus ==0">
                and a.F_CheckStatus in (0,1)
                and run.F_UserId =#{checkUserId}
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus ==2">
                and a.F_CheckStatus in (2)
                and  info.F_UserId =#{checkUserId}
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus ==3">
                and a.F_CheckStatus in (3)
                and  info.F_UserId =#{checkUserId}
            </if>
        </where>

    </select>
    <select id="getListForApp" resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        SELECT DISTINCT
        e.*
        FROM
        (
        SELECT
        a.`F_Id` AS id,
        a.`F_Phone` AS phone,
        a.`F_UserId` AS userId,
        b.F_WorkerStatus workerStatus,
        a.`F_ToOrg` AS toOrg,
        a.`F_ToPositionId` AS toPositionId,
        a.`F_ToRankId` AS toRankId,
        a.`F_ToRole` AS toRole,
        a.`F_ToManager` AS toManager,
        a.`F_FromOrg` AS fromOrg,
        a.`F_FromPositionId` AS fromPositionId,
        a.`F_FromRankId` AS fromRankId,
        a.`F_TransferDate` AS transferDate,
        a.`F_FromManager` AS fromManager,
        a.`F_ToMoney` AS toMoney,
        a.`F_Remarks` AS remarks,
        a.`F_Files` AS files,
        a.F_OpUser AS opUser,
        a.F_OpUserName AS opUserName,
        a.`F_IsNeedCheck` AS isNeedCheck,
        a.`F_CheckStatus` AS checkStatus,
        a.`F_EnabledMark` AS enabledMark,
        a.`F_CreatorUserId` AS createrUserId,
        a.`F_CreatorTime` AS creatorTime,
        a.`F_LastModifyUserId` AS lastModifyUserId,
        a.`F_LastModifyTime` AS lastModifyTime,
        a.`F_DeleteUserId` AS deleteUserId,
        a.`F_DeleteTime` AS deleteTime,
        a.`F_TenantId` AS tenantId,
        b.`F_Id` AS staffRosterId,
        b.`F_Name` AS `name`,
        b.`F_WorkerNo` AS workerNo,
        b.`F_CurrOrg` AS currOrg,
        b.`F_CurrPosition` AS currPosition,
        b.`F_CurrRank` AS currRank,
        b.`F_ContractType` AS contractType,
        b.`F_ActualStartDate` AS actualStartDate,
        b.`F_WorkerType` AS workerType,
        b.`F_SystemContractId` AS systemContractId,
        b.`F_SystemWokerId` AS systemWokerId,
        a.F_TaskInfoId AS taskInfoId
        FROM
        `ftb_personnels_staff_transfer_position` AS a
        LEFT JOIN ftb_personnels_staff_roster AS b ON a.F_UserId = b.F_UserId
        <where>
            <if test="dto.checkStatus != null and dto.checkStatus == 1">
                and a.F_CheckStatus in (1)
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus == 2">
                and a.F_CheckStatus in (2)
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus == 3">
                and a.F_CheckStatus in (3)
            </if>
        </where>
        ) e
        LEFT JOIN ftb_personnels_audit_run_task AS task ON e.taskInfoId = task.F_Id
        LEFT JOIN ftb_personnels_audit_run_task_history AS his ON e.taskInfoId = his.F_Id
        INNER JOIN (
        SELECT
        config.F_Id
        FROM
        ftb_personnels_audit_carbon_recipient AS co
        INNER JOIN ftb_personnels_audit_master_config AS config ON config.F_Id = co.F_MasterConfig
        WHERE
        config.F_ConfigType = 3
        AND co.F_UserId =#{checkUserId}
        ) d ON (
        task.F_MasterAuditConfigId = d.F_Id
        OR his.F_MasterAuditConfigId = d.F_Id
        )
        ORDER BY
        e.creatorTime DESC
    </select>

    <select id="getCountForApp" resultType="java.lang.Integer">
        SELECT count(*)
        FROM `ftb_personnels_staff_transfer_position` as a
        left join ftb_personnels_staff_roster as b on a.F_UserId = b.F_UserId
        <where>
            EXISTS ( SELECT co.F_UserId FROM ftb_personnels_audit_carbon_recipient as co
            INNER JOIN ftb_personnels_audit_master_config as config
            ON config.F_Id = co.F_MasterConfig
            WHERE config.F_ConfigType =3
            AND co.F_UserId =#{checkUserId}
            )

            <if test="dto.checkStatus != null and dto.checkStatus ==0">
                and a.F_CheckStatus in (0,1)
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus ==2">
                and a.F_CheckStatus in (2)
            </if>
            <if test="dto.checkStatus != null and dto.checkStatus ==3">
                and a.F_CheckStatus in (3)
            </if>
        </where>

    </select>
    <select id="pagingQueryWebMyCheckList"
            resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        SELECT
        a.`F_Id` AS id,
        a.`F_Phone` AS phone,
        a.`F_UserId` AS userId,
        a.`F_ToOrg` AS toOrg,
        a.`F_ToPositionId` AS toPositionId,
        a.`F_ToRankId` AS toRankId,
        a.`F_ToRole` AS toRole,
        a.`F_ToManager` AS toManager,
        a.`F_FromOrg` AS fromOrg,
        a.`F_FromPositionId` AS fromPositionId,
        a.`F_FromRankId` AS fromRankId,
        a.`F_TransferDate` AS transferDate,
        a.`F_FromManager` AS fromManager,
        a.`F_ToMoney` AS toMoney,
        a.`F_Remarks` AS remarks,
        a.`F_Files` AS files,
        a.`F_IsNeedCheck` AS isNeedCheck,
        a.`F_CheckStatus` AS checkStatus,
        a.`F_EnabledMark` AS enabledMark,
        a.`F_CreatorUserId` AS createrUserId,
        a.`F_CreatorTime` AS creatorTime,
        a.`F_LastModifyUserId` AS lastModifyUserId,
        a.`F_LastModifyTime` AS lastModifyTime,
        a.`F_DeleteUserId` AS deleteUserId,
        a.`F_DeleteTime` AS deleteTime,
        a.`F_TenantId` AS tenantId,
        b.`F_Id` AS staffRosterId,
        b.`F_Name` AS `name`,
        b.`F_WorkerNo` AS workerNo,
        b.`F_CurrOrg` AS currOrg,
        b.`F_CurrPosition` AS currPosition,
        b.`F_CurrRank` AS currRank,
        b.`F_ContractType` AS contractType,
        b.`F_ActualStartDate` AS actualStartDate,
        b.`F_WorkerType` AS workerType,
        b.`F_SystemContractId` AS systemContractId,
        b.`F_ActualProbationaryDate` AS actualProbationaryDate,
        b.`F_EntrySalary` AS entrySalary,
        b.`F_SystemWokerId` AS systemWokerId,
        b.`F_WorkerStatus`     AS workerStatus,
        a.F_TaskInfoId taskInfoId
        FROM
        `ftb_personnels_staff_transfer_position` AS a
        LEFT JOIN ftb_personnels_staff_roster AS b ON a.F_UserId = b.F_UserId
        LEFT JOIN ftb_personnels_audit_run_task AS run ON run.F_BusinessId = a.F_Id
        WHERE
        a.F_EnabledMark = 0
        AND a.F_IsNeedCheck = 0
        AND run.F_UserId = #{userId}
        ORDER BY
        a.F_CreatorTime DESC
    </select>

    <select id="getApprovedList" resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
        SELECT
        a.`F_Id` AS id,
        a.`F_Phone` AS phone,
        a.`F_UserId` AS userId,
        a.`F_ToOrg` AS toOrg,
        a.`F_ToPositionId` AS toPositionId,
        a.`F_ToRankId` AS toRankId,
        a.`F_ToRole` AS toRole,
        a.`F_ToManager` AS toManager,
        a.`F_FromOrg` AS fromOrg,
        a.`F_FromPositionId` AS fromPositionId,
        a.`F_FromRankId` AS fromRankId,
        a.`F_TransferDate` AS transferDate,
        a.`F_FromManager` AS fromManager,
        a.`F_ToMoney` AS toMoney,
        a.`F_Remarks` AS remarks,
        a.`F_Files` AS files,
        a.`F_IsNeedCheck` AS isNeedCheck,
        a.`F_CheckStatus` AS checkStatus,
        info.F_ApprovalResult approvalResult,
        a.`F_EnabledMark` AS enabledMark,
        a.`F_CreatorUserId` AS createrUserId,
        a.`F_CreatorTime` AS creatorTime,
        a.`F_LastModifyUserId` AS lastModifyUserId,
        a.`F_LastModifyTime` AS lastModifyTime,
        a.`F_DeleteUserId` AS deleteUserId,
        a.`F_DeleteTime` AS deleteTime,
        a.`F_TenantId` AS tenantId,
        b.`F_Id` AS staffRosterId,
        b.`F_Name` AS `name`,
        b.`F_WorkerNo` AS workerNo,
        b.`F_CurrOrg` AS currOrg,
        b.`F_CurrPosition` AS currPosition,
        b.`F_CurrRank` AS currRank,
        b.`F_ContractType` AS contractType,
        b.`F_ActualStartDate` AS actualStartDate,
        b.`F_WorkerType` AS workerType,
        b.`F_SystemContractId` AS systemContractId,
        b.`F_ActualProbationaryDate` AS actualProbationaryDate,
        b.`F_EntrySalary` AS entrySalary,
        b.`F_SystemWokerId` AS systemWokerId,
        a.F_TaskInfoId taskInfoId
        FROM
        `ftb_personnels_staff_transfer_position` AS a
        LEFT JOIN ftb_personnels_staff_roster AS b ON a.F_UserId = b.F_UserId
        LEFT JOIN ftb_personnels_audit_run_task AS run ON run.F_BusinessId = a.F_Id
        LEFT JOIN ftb_personnels_audit_task_info AS info ON run.F_Id = info.F_RunTaskId
        INNER JOIN ftb_personnels_audit_master_config as conf ON run.F_MasterAuditConfigId = conf.F_Id
        WHERE
        a.F_EnabledMark = 0
        AND a.F_IsNeedCheck = 0
        AND info.F_UserId = #{userId}
        and a.F_CheckStatus in (1,2,3)
        AND conf.F_ConfigType = #{configType}
        ORDER BY
        info.`F_CreatorTime` DESC
    </select>

    <select id="queryAccordingToTheCorrespondingStatus"
            resultType="jnpf.model.personnels.dto.staff.transfer.TransferPositionDto">
      SELECT
        a.`F_Id` AS id,
        a.`F_Phone` AS phone,
        a.`F_UserId` AS userId,
        a.`F_ToOrg` AS toOrg,
        a.`F_ToPositionId` AS toPositionId,
        a.`F_ToRankId` AS toRankId,
        a.`F_ToRole` AS toRole,
        a.`F_ToManager` AS toManager,
        a.`F_FromOrg` AS fromOrg,
        a.`F_FromPositionId` AS fromPositionId,
        a.`F_FromRankId` AS fromRankId,
        a.`F_TransferDate` AS transferDate,
        a.`F_FromManager` AS fromManager,
        a.`F_ToMoney` AS toMoney,
        a.`F_Remarks` AS remarks,
        a.`F_Files` AS files,
        a.`F_IsNeedCheck` AS isNeedCheck,
        a.`F_CheckStatus` AS checkStatus,
        info.F_ApprovalResult approvalResult,
        a.`F_EnabledMark` AS enabledMark,
        a.`F_CreatorUserId` AS createrUserId,
        a.`F_CreatorTime` AS creatorTime,
        a.`F_LastModifyUserId` AS lastModifyUserId,
        a.`F_LastModifyTime` AS lastModifyTime,
        a.`F_DeleteUserId` AS deleteUserId,
        a.`F_DeleteTime` AS deleteTime,
        a.`F_TenantId` AS tenantId,
        b.`F_Id` AS staffRosterId,
        b.`F_Name` AS `name`,
        b.`F_WorkerNo` AS workerNo,
        b.`F_CurrOrg` AS currOrg,
        b.`F_CurrPosition` AS currPosition,
        b.`F_CurrRank` AS currRank,
        b.`F_ContractType` AS contractType,
        b.`F_ActualStartDate` AS actualStartDate,
        b.`F_WorkerType` AS workerType,
        b.`F_SystemContractId` AS systemContractId,
        b.`F_ActualProbationaryDate` AS actualProbationaryDate,
        b.`F_EntrySalary` AS entrySalary,
        b.`F_SystemWokerId` AS systemWokerId,
        b.`F_WorkerStatus`     AS workerStatus,
        a.F_TaskInfoId taskInfoId
        FROM
        `ftb_personnels_staff_transfer_position` AS a
        LEFT JOIN ftb_personnels_staff_roster AS b ON a.F_UserId = b.F_UserId
        LEFT JOIN ftb_personnels_audit_run_task AS run ON run.F_BusinessId = a.F_Id
        LEFT JOIN ftb_personnels_audit_task_info AS info ON run.F_Id = info.F_RunTaskId
        INNER JOIN ftb_personnels_audit_master_config AS mas ON mas.F_Id = run.F_MasterAuditConfigId
        WHERE
        a.F_EnabledMark = 0
        AND a.F_IsNeedCheck = 0
        AND info.F_UserId = #{userId}
        and  mas.F_ConfigType =  #{configType}
        <if test="checkStatus != null and checkStatus !='' and  checkStatus == 2 ">
            and a.F_CheckStatus = 2
        </if>
        <if test="checkStatus != null and checkStatus !='' and  checkStatus == 3 ">
            and a.F_CheckStatus = 3
        </if>
        <if test="checkStatus != null and checkStatus !='' and  checkStatus == 1 ">
            and a.F_CheckStatus = 1
        </if>
       order  by  a.F_CreatorTime desc
    </select>
</mapper>