<?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.FtbPersonnelsStaffRegistrationFormDataMapper">
    <!--查询健康证是否到期-->
    <select id="queryHasHealthExpire"
            resultType="jnpf.model.personnels.po.FtbPersonnelsStaffRegistrationFormData">
        select F_Id          as id,
               F_RosterId    as rosterId,
               F_Phone       as phone,
               F_FormTypeId  as formTypeId,
               F_FormFieldId as formFieldId,
               F_Value       as `value`
        from ftb_personnels_staff_registration_form_data
        where F_FormFieldId = 'endHealthDate'
          and F_Value != ''  and F_RosterId !=''

    </select>

    <select id="queryTheUserSRegularizationDate" resultType="java.util.Date">
        SELECT F_ActualConverDate FROM ftb_personnels_regular_management
        WHERE F_UserId = #{userId} AND F_TransferStatus IN (2,6)
        ORDER BY F_ActualConverDate DESC LIMIT 1
    </select>

    <select id="queryUserTransferDate" resultType="java.util.Date">
        SELECT F_TransferDate FROM ftb_personnels_staff_transfer_position
        WHERE F_UserId = #{userId}
        AND (F_IsNeedCheck = 1 OR (F_CheckStatus = 2 AND F_IsNeedCheck = 0)) AND F_EnabledMark = 0
        ORDER BY F_TransferDate LIMIT 1
    </select>

    <select id="queryUserPromotionDate" resultType="java.util.Date">
        SELECT F_CreatorTime FROM ftb_personnels_post_apply WHERE F_UserId = #{userId} AND F_State IN (2,6)
        ORDER BY F_CreatorTime LIMIT 1
    </select>

    <select id="verifyWhetherTheDataExistsWithStaff" resultType="java.lang.Integer">
        SELECT
        COUNT( da.F_Id )
        FROM
        ftb_personnels_staff_registration_form_data AS da
        inner JOIN ftb_personnels_staff_roster AS ros ON ros.F_Phone = da.F_Phone and  ros.F_EnabledMark = 0
        WHERE
         da.F_Phone != #{phone} and da.F_FormFieldId = #{formFieldId} and da.F_Value = #{value}
    </select>

    <select id="queryStaffRosterList" resultType="jnpf.model.personnels.po.FtbPersonnelsStaffRoster">
        SELECT
        r.F_Id AS id,
        r.F_Phone AS phone,
        r.F_WorkerType AS workerType,
        r.F_WorkerStatus AS workerStatus,
        r.F_ActualStartDate AS actualStartDate,
        r.F_Name as name,
        r.F_Phone as phone
        FROM ftb_personnels_staff_roster r
                 LEFT JOIN ftb_personnels_staff_registration_form_data d ON r.F_Id = d.F_RosterId
            AND d.F_FormFieldId = #{formFieldId}
        WHERE (d.F_Value IS NULL OR d.F_Value = '') AND r.F_EnabledMark = 0 AND F_WorkerStatus != '305';
    </select>

    <select id="verifyWhetherTheDataExistsWithIdCard" resultType="java.lang.Integer">
        SELECT
        COUNT( da.F_Id )
        FROM
        ftb_personnels_staff_registration_form_data AS da
        INNER JOIN ftb_personnels_staff_employment_apply AS ros ON ros.F_Phone = da.F_Phone
        WHERE
        da.F_Phone != #{phone}
        AND da.F_FormFieldId = 'idCardNum'
        AND da.F_Value = #{value}
        AND ros.F_EnabledMark = 0
    </select>

    <select id="queryStaffRoster" resultType="java.lang.Integer">
        SELECT
        COUNT( da.F_Id )
        FROM
        ftb_personnels_staff_registration_form_data AS da
        INNER JOIN ftb_personnels_staff_roster AS ros ON ros.F_Phone = da.F_Phone
        WHERE
        da.F_Phone !=#{phone}
        AND da.F_FormFieldId = 'idCardNum'
        AND da.F_Value = #{value}
        AND ros.F_EnabledMark = 0
        AND ros.F_WorkerStatus != '305'

    </select>
</mapper>