<?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.FtbCultivatePositionMapper">
    <!--岗位学习已学习课程列表-->
    <select id="jobLearningCourseList"
            resultType="jnpf.model.cultivate.vo.position.FtbCultivatePositionJobLearnCourseVO">
        SELECT F_ID as id,F_Name as `name`,F_ChapterNumber as chapterNumber,F_Format as format,
        F_Label as label,F_IsGrounding as isGroundIng,F_CourseId as courseId,F_LastModifyTime as updateTime
        from ftb_cultivate_course
        WHERE F_EnabledMark = 0 and (F_Label=1 OR FIND_IN_SET(#{params.postId},F_LearnJob)>0)
        <if test="params.searchValue != null">
            and F_Name like concat('%',#{params.searchValue},'%')
        </if>
        <if test="params.label!= null">
            and F_Label = #{params.label}
        </if>
    </select>
    <!--岗位学习中课程列表页-->
    <select id="jobLevelCourseList" resultType="jnpf.model.cultivate.vo.position.FtbCultivatePositionLearnLevelVO">
        SELECT a.F_Id             as id,
               b.F_Id             as courseId,
               b.F_Name           as `name`,
               b.F_Format         as format,
               b.F_Label          as label,
               b.F_CourseId       as courseCustomId,
               b.F_LastModifyTime as updateTime,
               a.F_Compulsory     as compulsory
        FROM ftb_cultivate_position_course a
                 JOIN ftb_cultivate_course b ON a.F_CourseId = b.F_Id
        WHERE a.F_EnabledMark = 0
          and b.F_EnabledMark = 0
          and b.F_IsGrounding = 1
          and b.F_Label = 2
          and a.F_PostRankId = #{params.postRankId}
          and a.F_PostLearnId = #{params.jobLearningId}
    </select>
    <!--岗位学习分页列表-->
    <select id="jobLearningPaginatedList" resultType="jnpf.model.cultivate.vo.position.FtbJobLearningPaginatedVO">
        select F_Id as jobLearningId,F_PostId as postId,F_LastModifyTime as updateTime,F_IsGrounding as isGrounding
        from ftb_cultivate_position where F_EnabledMark = 0
        <if test="params.postId != null and params.postId != ''">
            and F_PostId = #{params.postId}
        </if>
        <if test="params.isGrounding!= null">
            and F_IsGrounding = #{params.isGrounding}
        </if>
    </select>
    <!--实操鉴定，根据岗位id+用户id查询，解决换绑问题-->
    <select id="queryPracticalAppraisalByPostId" resultType="java.lang.String">
        SELECT F_IdentifyId FROM ftb_cultivate_position_identify_result
        WHERE F_PostRankId = #{postId} AND F_UserId = #{userId} AND F_Type = 0 limit 1

        <!--    SELECT a.F_IdentifyId-->
        <!--    FROM ftb_cultivate_position_exam_identify a join ftb_cultivate_position b on a.F_PostRankId = b.F_PostId-->
        <!--    WHERE a.F_EnabledMark = 0 and b.F_IsGrounding = 1 and b.F_EnabledMark = 0 AND a.F_PostRankId = #{postId}-->
    </select>
    <!--是否已经鉴定-->
    <select id="queryIdentificationResults" resultType="java.lang.Integer">
        SELECT COUNT(0)
        FROM ftb_cultivate_identify_apply AS apy
                 JOIN ftb_cultivate_position_identify_result AS re ON re.F_IdentifyRecordId = apy.F_Id
        WHERE apy.F_IsVisible = 0
          and apy.F_Status = 1
          AND re.F_EnabledMark = 0
          AND apy.F_DeleteMark = 0
          AND re.F_PostRankId = #{postId}
          AND re.F_UserId = #{userId}
          AND re.F_IdentifyId = #{identifyId}
    </select>

    <select id="webPageList" resultType="jnpf.model.cultivate.v2.position.vo.WebPositionLearningListVo">
        select F_Id as id,F_PostId as postId,F_LastModifyTime as lastModifyTime
        from ftb_cultivate_position where F_EnabledMark = 0 and F_IsGrounding=1
        <if test="params.postId != null and params.postId != ''">
            and F_PostId = #{params.postId}
        </if>
        order by F_CreatorTime desc
    </select>

    <select id="allCompleteCourseLists" resultType="jnpf.model.cultivate.v2.course.vo.app.AppCourseSimpleVo">
        select a.F_Id as courseId,
        a.F_Name as `courseName`,
        a.F_CoverUrl as coverUrl,
        c.F_LastModifyTime as lastModifyTime
        from ftb_cultivate_course a
        left join ftb_cultivate_position_cource_learning c on a.F_Id = c.F_CourceId
        where a.F_EnabledMark = 0
        and a.F_IsGrounding = 1
        and c.F_EnabledMark = 0
        and c.F_state = 1
        and c.F_UserId = #{req.userId}
        <if test="courseIds != null and courseIds.size()>0">
            AND a.F_Id in
            <foreach collection="courseIds" item="value" separator="," open="(" close=")">
                #{value}
            </foreach>
        </if>
    </select>

    <select id="allCompleteExamLists" resultType="jnpf.model.cultivate.v2.course.vo.app.AppCultivateCourseExamVo">
        select a.F_Id as examId,
        a.F_ExamName as examName,
        a.F_ExamType as examType,
        a.F_Cover as coverUrl,
        c.F_Status as examStatus,
        c.F_FinishTime as examCompleteDate,
        c.F_LastModifyTime as lastModifyTime,
        c.F_Id as userExamId,
        c.F_TotalScore AS examTotalScore,
        c.F_Score AS userExamScore,
        c.F_Duration AS userExamDuration
        from ftb_cultivate_exam a
        join ftb_cultivate_exam_user c on a.F_Id = c.F_ExamId
        where a.F_EnabledMark = 1
        and c.F_EnabledMark = 0
        and c.F_Status in (3,4,5)
        and c.F_UserId = #{req.userId}
        <if test="examIds != null and examIds.size()>0">
            AND a.F_Id in
            <foreach collection="examIds" item="value" separator="," open="(" close=")">
                #{value}
            </foreach>
        </if>
    </select>

    <select id="allCompleteIdentityLists"
            resultType="jnpf.model.cultivate.v2.course.vo.app.AppCultivateCourseIdentityVo">
        select a.F_Id           as userIdentityId,
               a.F_Result       as identificationResult,
               a.F_Status       as identificationStatus,
               a.F_IdentifyTime as identityCompleteTime,
               b.F_TableId      as identityId,
               b.F_Name         as identityName,
               b.F_CoverUrl     as coverUrl
        from ftb_cultivate_identify_apply as a
                 join ftb_cultivate_identify_apply_table_backups as b on a.F_TableId = b.F_Id
        where a.F_Status = 1
          and a.F_DeleteMark = 0
          and a.F_IsVisible = 0
         and a.F_Source=2
          and a.F_BeIdentifyUserId = #{req.userId}
        <if test="identityIds != null and identityIds.size()>0">
            AND b.F_TableId in
            <foreach collection="identityIds" item="value" separator="," open="(" close=")">
                #{value}
            </foreach>
        </if>

        <if test="positionLearnIds != null and positionLearnIds.size()>0">
            AND a.F_SourceId in
            <foreach collection="positionLearnIds" item="value" separator="," open="(" close=")">
                #{value}
            </foreach>
        </if>
    </select>

    <select id="allCompletePracticeLists"
            resultType="jnpf.model.cultivate.v2.position.vo.AppPracticeCountVo">
        select
        a.F_SkillId as id,
        b.F_Name as name,
        count(1) as num
        from ftb_cultivate_teaching_record as a
        join ftb_cultivate_teaching_skill as b on a.F_SkillId = b.F_Id
        where a.F_Type =2
        and a.F_DeleteMark=0
        and b.F_DeleteMark=0
        and a.F_UserId = #{req.userId}
        <if test="practiceIds != null and practiceIds.size()>0">
            AND a.F_SkillId in
            <foreach collection="practiceIds" item="value" separator="," open="(" close=")">
                #{value}
            </foreach>
        </if>
        group by a.F_SkillId
    </select>
</mapper>