<?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.cultivate.mapper.CultivateIdentifyApplyMapper">
    <!--实操鉴定申请/列表-->
    <select id="getPageList" resultType="jnpf.model.cultivate.vo.identify.IdentifyApplyListDbVo">
        SELECT
        fcia.F_Id id,
        fcia.F_Name `name`,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_BeOfficialRankInfoJson beOfficialRankInfoJson,
        fcit.F_RuleId tableRuleId,
        fcit.F_Name tableName,
        fcit.F_DeleteMark tableStatus,
        fcia.F_Source source,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_OfficialRankInfoJson officialRankInfoJson,
        fcia.F_UseTime useTime,
        fcia.F_IdentifyTime identifyTime,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_IsInitiate isInitiate
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="req.innerPowerUserIds!= null and req.innerPowerUserIds.size()>0">
                and fcia.F_BeIdentifyUserId in
                <foreach collection="req.innerPowerUserIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="req.leaverUserIds != null and req.leaverUserIds.size() >0 ">
                and fcia.F_BeIdentifyUserId not in
                <foreach collection="req.leaverUserIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="req.keyword != null and req.keyword != ''">
                AND (fcia.F_Name like concat('%', #{req.keyword}, '%') or fcit.F_Name like concat('%',
                #{req.keyword},'%'))
            </if>
            <if test="req.status != null">
                AND fcia.F_Status = #{req.status}
            </if>
            <if test="req.result != null">
                AND fcia.F_Result = #{req.result}
            </if>
            <if test="req.orgCode != null and req.orgCode != ''">
                AND fcia.F_BeIdentifyOrgList like concat('%', #{req.orgCode}, '%')
            </if>
            <if test="req.source != null">
                AND fcia.F_Source = #{req.source}
            </if>
        </where>
        ORDER BY fcia.F_Status ASC,fcia.F_CreatorTime desc,fcia.F_PlanIdentifyTime ASC
    </select>
    <!--实操鉴定申请/列表-->
    <select id="getList" resultType="jnpf.model.cultivate.vo.identify.IdentifyApplyListDbVo">
        SELECT
        fcia.F_Id id,
        fcia.F_Name `name`,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_BeOfficialRankInfoJson beOfficialRankInfoJson,
        fcit.F_RuleId tableRuleId,
        fcit.F_Name tableName,
        fcit.F_DeleteMark tableStatus,
        fcia.F_Source source,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_OfficialRankInfoJson officialRankInfoJson,
        fcia.F_UseTime useTime,
        fcia.F_IdentifyTime identifyTime,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_IsInitiate isInitiate
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="ids!= null and ids.size()>0">
                and fcia.F_Id in
                <foreach collection="ids" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        ORDER BY fcia.F_Status ASC,fcia.F_PlanIdentifyTime ASC
    </select>
    <!--成员培训进展/分页列表-->
    <select id="getUserIdentifyPage" resultType="jnpf.model.cultivate.vo.identify.UserIdentifyPageVo">
        SELECT
        fcia.F_Id id,
        fcia.F_Source source,
        fcia.F_Name `name`,
        fcit.F_Name tableName,
        fcia.F_UseTime useTime,
        fcia.F_IdentifyTime identifyTime,
        fcia.F_PlanIdentifyTime planIdentifyTime,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_BeIdentifyUserId userId,
        fcia.F_IdentifyUserId identifyUserId
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="userId != null and userId != ''">
                AND fcia.F_BeIdentifyUserId = #{userId}
            </if>
        </where>
        ORDER BY fcia.F_Status ASC,fcia.F_PlanIdentifyTime ASC
    </select>
    <select id="getPageAppListCount" resultType="java.lang.Integer">
        SELECT
        count(*) as num

        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="req.keyword != null and req.keyword != ''">
                AND (fcia.F_Name like concat('%', #{req.keyword}, '%') or fcit.F_Name like concat('%',
                #{req.keyword},'%'))
            </if>
            <if test="req.source != null and req.source == 0">
                AND (fcia.F_Source = 0 or fcia.F_Source = 3)
            </if>
            <if test="req.source != null and req.source != 0">
                AND fcia.F_Source = #{req.source}
            </if>
            <choose>
                <when test="req.status == -1">
                    AND fcia.F_BeIdentifyUserId = #{userId}
                    AND fcia.F_AppraisalResults = 0
                    <!-- AND fcia.F_Status = 1-->
                </when>
                <otherwise>
                    AND fcia.F_Status = #{req.status}
                    <if test="userId != null and userId != ''">
                        AND FIND_IN_SET(#{userId},fcia.F_IdentifyUserId) > 0
                    </if>
                </otherwise>
            </choose>
        </where>
        <choose>
            <when test="req.status == -1">
                ORDER BY fcia.F_IdentifyTime desc
            </when>
            <when test="req.status == 0">
                ORDER BY fcia.F_Status ASC,fcia.F_CreatorTime desc,fcia.F_PlanIdentifyTime ASC
            </when>
            <when test="req.status == 1">
                ORDER BY fcia.F_IdentifyTime desc
            </when>
            <otherwise>
                ORDER BY fcia.F_PlanIdentifyTime ASC
            </otherwise>
        </choose>
    </select>
    <!--实操鉴定申请/app列表-->
    <select id="getPageAppList" resultType="jnpf.model.cultivate.vo.identify.IdentifyApplyListAppDbVo">
        SELECT
        fcia.F_Id id,
        fcia.F_Name `name`,
        fcit.F_Name tableName,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_BeOfficialRankInfoJson beOfficialRankInfoJson,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_OfficialRankInfoJson officialRankInfoJson,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_Source source,
        fcia.F_SourceId sourceId,
        fcia.F_StudyFinishTime studyFinishTime,
        fcia.F_IdentifyTime identifyTime,
        fcia.F_PlanIdentifyTime planIdentifyTime,
        fcia.F_PostId postId
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="req.keyword != null and req.keyword != ''">
                AND (fcia.F_Name like concat('%', #{req.keyword}, '%') or fcit.F_Name like concat('%',
                #{req.keyword},'%'))
            </if>
            <if test="req.source != null and req.source == 0">
                AND (fcia.F_Source = 0 or fcia.F_Source = 3)
            </if>
            <if test="req.source != null and req.source != 0">
                AND fcia.F_Source = #{req.source}
            </if>
            <choose>
                <when test="req.status == -1">
                    AND fcia.F_BeIdentifyUserId = #{userId}
                    AND fcia.F_AppraisalResults = 0
                    <!-- AND fcia.F_Status = 1-->
                </when>
                <when test="req.status == 0">
                    AND fcia.F_Status = #{req.status}
                    <if test="powerUserIds!= null and powerUserIds.size()>0">
                        and fcia.F_BeIdentifyUserId in
                        <foreach collection="powerUserIds" item="item" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </if>
                </when>
                <when test="req.status == 1">
                    AND fcia.F_Status = #{req.status}
                    <if test="userId != null and userId != ''">
                        AND FIND_IN_SET(#{userId},fcia.F_IdentifyUserId) > 0
                    </if>
                </when>
                <when test="req.status == 2">
                    AND fcia.F_Status = #{req.status}
                    <if test="powerUserIds!= null and powerUserIds.size()>0">
                        and fcia.F_BeIdentifyUserId in
                        <foreach collection="powerUserIds" item="item" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </if>
                </when>
            </choose>
        </where>
        <choose>
            <when test="req.status == -1">
                ORDER BY fcia.F_IdentifyTime desc
            </when>
            <when test="req.status == 0">
                ORDER BY fcia.F_Status ASC,fcia.F_CreatorTime desc,fcia.F_PlanIdentifyTime ASC
            </when>
            <when test="req.status == 1">
                ORDER BY fcia.F_IdentifyTime desc
            </when>
            <otherwise>
                ORDER BY fcia.F_PlanIdentifyTime ASC
            </otherwise>
        </choose>
    </select>
    <!--查询鉴定表有多少人使用-->
    <select id="getTableUseNumber" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM (SELECT count(*)
              FROM ftb_cultivate_identify_apply fcia
              where fcia.F_DeleteMark = 0
                and fcia.F_IsVisible = 0
                and fcia.F_TableId = #{tableId}
              group by fcia.F_BeIdentifyUserId) t
    </select>
    <!--成员培训进展/用户鉴定数据统计-->
    <select id="getUserIdentifyStatistics"
            resultType="jnpf.model.cultivate.vo.identify.IdentifyApplyStatisticsApiVo">
        SELECT
        fcia.F_BeIdentifyUserId userId,
        sum(IF(fcia.F_Status =1,1,0)) alreadyNumber,
        count(*) totalNumber
        FROM ftb_cultivate_identify_apply fcia
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="userIds!= null and userIds.size()>0">
                and fcia.F_BeIdentifyUserId in
                <foreach collection="userIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        group by fcia.F_BeIdentifyUserId
    </select>
    <!--根据岗位id查询岗位学习绑定的实操鉴定主键-->
    <select id="querAppplyUserIds" resultType="java.lang.String">
        SELECT DISTINCT a.F_IdentifyRecordId as Id
        FROM ftb_cultivate_position_identify_result a
                 JOIN ftb_cultivate_position b ON a.F_PostLearnId = b.F_Id
        WHERE a.F_EnabledMark = 0
          AND b.F_EnabledMark = 0
          AND a.F_PostRankId = #{id}
          AND a.F_UserId = #{userId}
          AND a.F_Type = 0
        ORDER BY a.F_CreatorTime DESC
        limit 1
    </select>
    <!--查询实操鉴定任务列表-->
    <select id="queryIdentifyApplyInfo"
            resultType="jnpf.model.cultivate.vo.learn.FtbCultivateLearnTaskIdentificationInfoVO">
        SELECT
        apy.F_Id as identificationId,
        apy.F_Status as identificationStatus,
        apy.F_Result as identificationResult,
        ba.F_Name as identificationName
        FROM
        ftb_cultivate_identify_apply AS apy
        LEFT JOIN ftb_cultivate_identify_apply_table_backups AS ba ON ba.F_Id = apy.F_TableId
        <where>
            apy.F_DeleteMark = 0
            AND apy.F_Source = 4
            AND apy.F_SourceId = #{taskId}
            AND apy.F_BeIdentifyUserId = #{userId}
        </where>
    </select>
    <!--统计每个鉴定的鉴定人数-->
    <select id="groupIdentifyCountNum"
            resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
        SELECT
        tas.F_TaskId as selectKey,
        count( * ) num
        FROM
        ftb_cultivate_identify_apply AS us
        LEFT JOIN ftb_cultivate_identify_apply_table_backups AS ba ON us.F_TableId = ba.F_Id
        INNER JOIN ftb_cultivate_learn_task_identification AS tas ON tas.F_IdentificationId = ba.F_TableId
        AND tas.F_TaskId = us.F_SourceId
        WHERE
        us.F_IsVisible = 0 and us.F_DeleteMark = 0 and
        tas.F_TaskId IN
        <foreach collection="taskIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        <if test="type==1">
            and us.F_Status = 1 AND us.F_Result IN ( 0, 1 )
        </if>
        GROUP BY
        tas.F_TaskId
    </select>

    <select id="getPageListV2" resultType="jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListVo">
        SELECT
        fcia.F_Id id,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcit.F_RuleId tableRuleId,
        fcit.F_Name tableName,
        fcit.F_DeleteMark tableStatus,
        fcia.F_Source source,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_UseTime useTime,
        fcia.F_IdentifyTime identifyTime,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_IsInitiate isInitiate,
        fcia.F_GradeName gradeName
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="req.innerPowerUserIds!= null and req.innerPowerUserIds.size()>0">
                and fcia.F_BeIdentifyUserId in
                <foreach collection="req.innerPowerUserIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="req.keyword != null and req.keyword != ''">
                AND (
                fcia.F_Name like concat('%', #{req.keyword}, '%')
                or fcit.F_Name like concat('%',#{req.keyword},'%')
                OR fcit.F_RuleId LIKE CONCAT('%',#{req.keyword},'%')
                <if test="req.userIdsKeyWord != null and req.userIdsKeyWord.size()>0">
                    OR(
                    (fcia.F_IdentifyUserId IN
                    <foreach collection="req.userIdsKeyWord" open="(" close=")" separator="," item="x">
                        #{x}
                    </foreach>
                    ) OR
                    (fcia.F_BeIdentifyUserId IN
                    <foreach collection="req.userIdsKeyWord" open="(" close=")" separator="," item="x">
                        #{x}
                    </foreach>
                    )
                    )
                </if>
                )
            </if>
            <if test="req.status != null">
                AND fcia.F_Status = #{req.status}
            </if>
            <if test="req.result != null">
                AND fcia.F_Result = #{req.result}
            </if>

            <if test="req.source != null">
                AND fcia.F_Source = #{req.source}
            </if>
        </where>
        ORDER BY fcia.F_Status ASC,fcia.F_CreatorTime desc,fcia.F_PlanIdentifyTime ASC
    </select>

    <select id="queryMyIdentifyApplyList" resultType="jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListAppVo">
        SELECT
        DISTINCT
        fcia.F_Id id,
        fcit.F_Name tableName,
        fcit.F_CoverUrl as coverUrl,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_Source source,
        fcia.F_SourceId sourceId,
        fcia.F_StudyFinishTime studyFinishTime,
        fcia.F_IdentifyTime identifyTime
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            AND fcia.F_BeIdentifyUserId = #{userId}
            <if test="req.keyWord != null and req.keyWord != ''">
                AND fcit.F_Name like concat('%',#{req.keyWord},'%')
            </if>
            <if test="req.status !=-1">
                AND fcit.F_Status = #{req.status}
            </if>
        </where>
        <choose>
            <when test="req.status == 0">
                order by fcia.F_CreatorTime DESC
            </when>
            <when test="req.status == 1">
                order by FIELD(fcia.F_Result, 1, 0, 2), fcia.F_CreatorTime DESC
            </when>
            <otherwise>
                order by fcia.F_Status ASC, FIELD(fcia.F_Result, 1, 0, 2), fcia.F_CreatorTime DESC
            </otherwise>
        </choose>
    </select>

    <select id="queryAppIdentifyApplyList" resultType="jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListAppVo">
        SELECT
        DISTINCT
        fcia.F_Id id,
        fcit.F_Name tableName,
        fcit.F_CoverUrl as coverUrl,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_Source source,
        fcia.F_SourceId sourceId,
        fcia.F_StudyFinishTime studyFinishTime,
        fcia.F_IdentifyTime identifyTime
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            <if test="req.keyWord != null and req.keyWord != ''">
                AND fcit.F_Name like concat('%',#{req.keyWord},'%')
            </if>

            and (
            (
            fcia.F_Status = 1
            <if test="orgUserIds!= null and orgUserIds.size()>0">
                and fcia.F_BeIdentifyUserId in
                <foreach collection="orgUserIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            and fcia.F_IdentifyUserId = #{loginUserId}
            )

            or (
            fcia.F_Status = 0
            and fcia.F_BeIdentifyUserId != #{loginUserId}
            and fcia.F_IdentifyUserId = ''
            <if test="powerUserIds!= null and powerUserIds.size()>0">
                and fcia.F_BeIdentifyUserId in
                <foreach collection="powerUserIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            )

            <if test="myUserIds!= null and myUserIds.size()>0">
                or (
                fcia.F_Status = 0
                and fcia.F_BeIdentifyUserId != #{loginUserId}
                and fcia.F_IdentifyUserId != ''
                and fcia.F_Id in
                <foreach collection="myUserIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
                )
            </if>
            )
        </where>
        order by fcia.F_Status ASC, FIELD(fcia.F_Result, 1, 0, 2), fcia.F_CreatorTime DESC
    </select>

    <select id="queryAppIdentifyApplyListWaiting"
            resultType="jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListAppVo">
        SELECT
        DISTINCT
        fcia.F_Id id,
        fcit.F_Name tableName,
        fcit.F_CoverUrl as coverUrl,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_Source source,
        fcia.F_SourceId sourceId,
        fcia.F_StudyFinishTime studyFinishTime,
        fcia.F_IdentifyTime identifyTime,
        fcia.F_CreatorTime creatorTime
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            AND fcia.F_Status = 0
            and fcia.F_BeIdentifyUserId != #{loginUserId}
            <if test="req.keyWord != null and req.keyWord != ''">
                AND fcit.F_Name like concat('%',#{req.keyWord},'%')
            </if>
            and (
            (

            fcia.F_IdentifyUserId = ''
            <if test="userIds!= null and userIds.size()>0">
                and fcia.F_BeIdentifyUserId in
                <foreach collection="userIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            )
            <if test="myUserIds!= null and myUserIds.size()>0">
            or (
               fcia.F_IdentifyUserId != ''
                and fcia.F_Id  in
                <foreach collection="myUserIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>

            )
            </if>
            )
        </where>
        order by fcia.F_CreatorTime DESC
    </select>

    <select id="queryAppIdentifyApplyListComplete"
            resultType="jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListAppVo">
        SELECT
        DISTINCT
        fcia.F_Id id,
        fcit.F_Name tableName,
        fcit.F_CoverUrl as coverUrl,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_Source source,
        fcia.F_SourceId sourceId,
        fcia.F_StudyFinishTime studyFinishTime,
        fcia.F_IdentifyTime identifyTime
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id
        <where>
            fcia.F_DeleteMark = 0
            and fcia.F_IsVisible = 0
            AND fcia.F_Status = 1
            <if test="req.keyWord != null and req.keyWord != ''">
                AND fcit.F_Name like concat('%',#{req.keyWord},'%')
            </if>
            and fcia.F_IdentifyUserId = #{loginUserId}
            <if test="userIds!= null and userIds.size()>0">
                and fcia.F_BeIdentifyUserId in
                <foreach collection="userIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="req.startTime != null and req.startTime != ''">
                AND fcia.F_IdentifyTime &gt;= #{req.startTime}
            </if>
            <if test="req.endTime != null and req.endTime != ''">
                AND fcia.F_IdentifyTime &lt;= #{req.endTime}
            </if>
        </where>
        order by FIELD(fcia.F_Result, 1, 0, 2), fcia.F_CreatorTime DESC
    </select>

    <select id="queryIdentifyApply" resultType="jnpf.entity.cultivate.CultivateIdentifyApply">
        SELECT DISTINCT fcia.F_Id id,
        fcit.F_Name name,
        fcit.F_TableId tableId,
        fcia.F_BeIdentifyUserId beIdentifyUserId,
        fcia.F_IdentifyUserId identifyUserId,
        fcia.F_Status status,
        fcia.F_Result result,
        fcia.F_Source source,
        fcia.F_SourceId sourceId,
        fcia.F_StudyFinishTime studyFinishTime,
        fcia.F_IdentifyTime identifyTime
        FROM ftb_cultivate_identify_apply fcia
        LEFT JOIN ftb_cultivate_identify_apply_table_backups fcit on fcia.F_TableId = fcit.F_Id

        <where>
            fcia.F_DeleteMark = 0
            <if test="userId!= null and userId != ''">
                AND fcia.F_BeIdentifyUserId = #{userId}
            </if>
            <if test="identifyIds!= null and identifyIds.size()>0">
                and fcit.F_TableId in
                <foreach collection="identifyIds" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

            and fcia.F_Source = #{source}
            and fcia.F_SourceId = #{sourceId}
        </where>
    </select>

    <select id="queryMyIdentifyUserList" resultType="java.lang.String">
        SELECT DISTINCT fcia.F_Id beIdentifyUserId
        FROM ftb_cultivate_identify_apply fcia
        where fcia.F_DeleteMark = 0
          AND FIND_IN_SET(#{loginUserId}, fcia.F_IdentifyUserId) > 0
    </select>

    <!--查询用户已完成的鉴定列表（关联查询鉴定表信息）-->
    <select id="queryCompletedIdentitiesWithInfo" resultType="jnpf.model.cultivate.v2.course.vo.UserLearningStatusVo$IdentityInfo">
        SELECT
            fcia.F_TableId AS tableId,
            fcit.F_Name AS identityName
        FROM
            ftb_cultivate_identify_apply fcia
        INNER JOIN ftb_cultivate_identify_apply_table_backups fcit ON fcia.F_TableId = fcit.F_Id
        WHERE
            fcia.F_DeleteMark = 0
          AND fcit.F_DeleteMark = 0
          AND fcia.F_Status = 1
          AND fcia.F_BeIdentifyUserId = #{userId}
        ORDER BY fcia.F_IdentifyTime DESC
    </select>

    <!--统计岗位学习中已完成的鉴定数量（关联查询鉴定表和备份表）-->
    <select id="countCompletedIdentifyByPost" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM ftb_cultivate_identify_apply fcia
        INNER JOIN ftb_cultivate_identify_apply_table_backups fcit ON fcia.F_TableId = fcit.F_Id
        WHERE
            fcia.F_DeleteMark = 0
          AND fcit.F_DeleteMark = 0
          AND fcia.F_BeIdentifyUserId = #{userId}
          AND fcia.F_Source = #{source}
          AND fcia.F_SourceId = #{sourceId}
          AND fcia.F_Status = 1
          AND fcit.F_TableId IN
        <foreach collection="courseIdentityIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>