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

    <!--个人维度统计-->
    <select id="personListStatistics"
            resultType="jnpf.model.cultivate.vo.position.FtbCultivatePositionPersonStatisticesVO">
        SELECT a.F_UserId as userId,IFNULL(SUM(a.F_LearnTime),0) as studyDuration
        FROM ftb_cultivate_position_cource_learning a
        <where> a.F_EnabledMark=0
            <if test="params.innerCourseIds != null and params.innerCourseIds.size() > 0">
                and a.F_CourceId in
                <foreach collection="params.innerCourseIds" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="params.userIds != null and params.userIds.size() > 0">
                and a.F_UserId IN
                <foreach collection="params.userIds" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="params.startTime != null and params.endTime != null">
                and a.F_LastModifyTime BETWEEN #{params.startTime} and #{params.endTime}
            </if>
        </where>
        GROUP BY a.F_UserId
    </select>
    <!--查询岗位关联的所有课程id-->
    <select id="queryCourseIds"  resultType="jnpf.model.cultivate.v2.position.vo.CultivatePositionCourseVo">
        SELECT
            b.F_CourseId AS courseId,
            b.F_GradeId as gradeId,
            b.F_PostRankId AS postId,
            b.F_Compulsory AS compulsory
        FROM
            ftb_cultivate_position_course b
                JOIN ftb_cultivate_course c ON b.F_CourseId = c.F_Id
                JOIN ftb_cultivate_position p ON b.F_PostLearnId = p.F_Id
        WHERE
            b.F_EnabledMark = 0
          AND c.F_EnabledMark = 0 
          AND c.F_IsGrounding = 1
          AND p.F_EnabledMark = 0
          AND p.F_IsGrounding = 1
    </select>
    <!--个人维度统计-->
    <select id="personListStatistics1"
            resultType="jnpf.model.cultivate.vo.position.FtbCultivatePositionPersonStatisticesVO">
        SELECT a.F_UserId as userId,IFNULL(SUM(a.F_LearnTime),0) as studyDuration
        FROM ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        <where>
         b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0
        <if test="params.userIds != null and params.userIds.size() > 0">
            and F_UserId IN
            <foreach collection="params.userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="params.startTime != null and params.endTime != null">
            and a.F_LastModifyTime BETWEEN #{params.startTime} and #{params.endTime}
        </if>
        </where>
        GROUP BY F_UserId
    </select>
   <!--下属参与学习人数-->
    <select id="numberOfPeopleParticipatingInTheStudy1" resultType="java.lang.Integer">
        SELECT COUNT(distinct a.F_UserId) FROM
        ftb_cultivate_position_cource_learning a
        WHERE
        a.F_EnabledMark=0 and
        a.F_state in (1,2) and a.F_UserId IN
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>

        <if test="innerCourseIds != null and innerCourseIds.size() > 0">
            AND  a.F_CourceId in
            <foreach collection="innerCourseIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
    <!--下属人均学习时长-->
    <select id="averageStudyHoursPerSubordinate1" resultType="java.lang.Integer">
        SELECT IFNULL(SUM(a.F_LearnTime),0)
        FROM  ftb_cultivate_position_cource_learning a
        WHERE
        a.F_EnabledMark=0 and
        a.F_UserId IN
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>

        <if test="innerCourseIds != null and innerCourseIds.size() > 0">
            AND  a.F_CourceId in
            <foreach collection="innerCourseIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
    <!--统计课程数-->
    <select id="numberOfStudyCourses" resultType="java.lang.Integer">
        SELECT
        COUNT(DISTINCT a.F_CourceId)
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        <where>
            b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and
            a.F_UserId = #{userId} and a.F_EnabledMark=0
            <if test="type == 0">
                and a.F_state in (1,2)
            </if>
            <if test="type == 1">
                and a.F_state = 1
            </if>
        </where>
    </select>
    <!--统计课程数-->
    <select id="batchNumberOfStudyCourses2" resultType="jnpf.model.cultivate.vo.position.PersonStatisticesDto">
        SELECT
        a.F_UserId as userId ,COUNT( DISTINCT a.F_CourceId ) as num
        FROM
        ftb_cultivate_position_cource_learning a
        <where>
             a.F_EnabledMark=0
            <if test="innerCourseIds != null and innerCourseIds.size() > 0">
              AND  a.F_CourceId in
                <foreach collection="innerCourseIds" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="userIds != null and userIds.size() > 0">
           AND   a.F_UserId in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
            </if>
            <if test="type == 0">
                and a.F_state in (1,2)
            </if>
            <if test="type == 1">
                and a.F_state = 1
            </if>
        </where>
        group by a.F_UserId
    </select>
    <!--统计课程数-->
    <select id="batchNumberOfStudyCourses1" resultType="jnpf.model.cultivate.vo.position.PersonStatisticesDto">
        SELECT
        a.F_UserId as userId ,COUNT( DISTINCT a.F_CourceId ) as num
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        <where>
            b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0 and
            a.F_UserId in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
            <if test="type == 0">
                and a.F_state in (1,2)
            </if>
            <if test="type == 1">
                and a.F_state = 1
            </if>
        </where>
        group by a.F_UserId
    </select>
    <!--岗位维度统计-->
    <select id="positionListStatistics" resultType="jnpf.model.cultivate.vo.position.FtbCultivatePersonStatisticesVO">
        SELECT F_PostId as positionId,F_Id as postLearnId FROM ftb_cultivate_position
        WHERE F_EnabledMark = 0
        <if test="params.powerPositionList != null and params.powerPositionList.size() > 0 ">
        and F_PostId in
        <foreach collection="params.powerPositionList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        </if>
    </select>
    <!--岗位学习课程总数-->
    <select id="totalNumberOfOnTheJobLearningCourses" resultType="jnpf.model.cultivate.vo.position.FtbCultivatePersonStatisticesVO$TotalNumberOfOnTheJobLearningCourses">
        SELECT
        COUNT( DISTINCT a.F_CourseId ) as totalNumberOfOnTheJobLearningCourses
        ,F_PostLearnId as positionId
        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 F_PostLearnId in
        <foreach collection="postLearnIds" item="postLearnId" open="(" close=")" separator=",">
            #{postLearnId}
        </foreach>
        GROUP BY F_PostLearnId
    </select>
    <!--已学习课程数-->
    <select id="numberOfCoursesTaken" resultType="jnpf.model.cultivate.vo.position.FtbCultivatePersonStatisticesVO$NumberOfCoursesTaken">
        SELECT COUNT(distinct a.F_CourceId) as numberOfCoursesTaken,b.F_PostRankId as positionId
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE
        b.F_EnabledMark = 0 and c.F_EnabledMark = 0  and a.F_EnabledMark=0 AND
        a.F_state = 1 and
        b.F_PostRankId in
        <foreach collection="postLearnIds" item="postLearnId" open="(" close=")" separator=",">
            #{postLearnId}
        </foreach>
        GROUP BY b.F_PostRankId
    </select>

    <select id="numberOfCoursesTakenStoreIndex" resultType="java.lang.Long">
        SELECT COUNT(distinct a.F_CourceId) as numberOfCoursesTaken
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        join ftb_cultivate_position posi on posi.F_Id = b.F_PostLearnId
        WHERE
        b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0 AND
        a.F_state = 1 and
        c.F_IsGrounding=1 AND
        posi.F_IsGrounding=1 and
        b.F_PostRankId in
        <foreach collection="postLearnIds" item="postLearnId" open="(" close=")" separator=",">
            #{postLearnId}
        </foreach>
        AND a.F_UserId =#{userId}
    </select>

    <select id="courseTotleNum" resultType="java.lang.Long">
        SELECT
        COUNT( DISTINCT a.F_CourseId )
        FROM
        ftb_cultivate_position_course a
        JOIN ftb_cultivate_course b ON a.F_CourseId = b.F_Id
        join ftb_cultivate_position c on c.F_Id = a.F_PostLearnId
        WHERE
        a.F_EnabledMark = 0
        And c.F_IsGrounding=1
        AND b.F_EnabledMark = 0
        and  b.F_IsGrounding=1
        AND b.F_Label = 2
        and a.F_PostRankId in
        <foreach collection="positionIds" item="postLearnId" open="(" close=")" separator=",">
            #{postLearnId}
        </foreach>
    </select>
    <!--岗位学习人数-->
    <select id="numberOfPeopleStudyingOnTheJob" resultType="java.lang.String">
        SELECT distinct a.F_UserId FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE b.F_EnabledMark = 0 and c.F_EnabledMark = 0  and a.F_EnabledMark=0
        and a.F_state in (1,2)
        and a.F_UserId in
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <!--学习时长-->
    <select id="studyDuration" resultType="java.lang.Long">
        SELECT IFNULL(SUM(F_LearnTime),0)
        FROM ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE
        b.F_EnabledMark = 0 and c.F_EnabledMark = 0  and a.F_EnabledMark=0
        and a.F_UserId in
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <!--参与学习人数-->
    <select id="numberOfPeopleParticipatingInTheStudyOrg" resultType="java.lang.String">
        SELECT distinct a.F_UserId
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0 and a.F_state in (1,2)
        and a.F_UserId IN
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and FIND_IN_SET(b.F_PostRankId,#{positionIds}) > 0
        <if test="params.startTime != null and params.endTime != null">
            and a.F_LastModifyTime between #{params.startTime} and #{params.endTime}
        </if>
    </select>
    <!--学习总时长-->
    <select id="totalStudyTime" resultType="java.lang.Integer">
        SELECT IFNULL(SUM(a.F_LearnTime),0) FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0 and a.F_state in (1,2)
        and a.F_UserId in
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and FIND_IN_SET(b.F_PostRankId,#{postionIds}) > 0
        <if test="params.startTime != null and params.endTime != null">
            and a.F_LastModifyTime between #{params.startTime} and #{params.endTime}
        </if>
    </select>
    <!--已学课程数-->
    <select id="numberOfCoursesTakens" resultType="java.lang.Integer">
        SELECT count(distinct a.F_CourceId)
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE b.F_EnabledMark = 0 and a.F_state = 1 and c.F_EnabledMark = 0 and a.F_EnabledMark=0 and c.F_Label = 2
        and a.F_UserId in
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="params.startTime != null and params.endTime != null">
            and a.F_LastModifyTime between #{params.startTime} and #{params.endTime}
        </if>
        and FIND_IN_SET(b.F_PostRankId,#{postionIds}) > 0
    </select>
    <!--课程总数-->
    <select id="totalNumberOfCourses" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM ftb_cultivate_course WHERE F_EnabledMark = 0
    </select>
    <!--组织课程信息-->
    <select id="organizeCourseDetails" resultType="jnpf.model.cultivate.vo.position.OrganizeCourseDetails">
        SELECT a.F_CourceId as courseId,b.F_Name as courseTitle,
        SUM(a.F_LearnTime) as studyDuration,
        GROUP_CONCAT(DISTINCT c.F_PostRankId) AS positionIds
        FROM ftb_cultivate_position_cource_learning a JOIN ftb_cultivate_course b ON a.F_CourceId = b.F_Id
        join ftb_cultivate_position_course c on a.F_CourceId = c.F_CourseId
        WHERE c.F_EnabledMark = 0 and b.F_EnabledMark = 0 and b.F_Label = 2 and a.F_EnabledMark=0
        and a.F_state = 1
        and FIND_IN_SET(c.F_PostRankId,#{postionIds}) > 0
        and a.F_UserId in
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="startDate != null and endDate != null">
            and a.F_LastModifyTime between #{startDate} and #{endDate}
        </if>
        GROUP BY a.F_CourceId
    </select>
    <!--已参与学习人数-->
    <select id="numberOfPeopleParticipatingInTheFinishStudy" resultType="jnpf.model.cultivate.vo.position.CourseStudyCountVO">
        SELECT
        a.F_CourceId AS courseId,
        COUNT( DISTINCT a.F_UserId ) AS num
        from ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        WHERE b.F_EnabledMark = 0
        and F_CourceId in
        <foreach collection="courseIds" open="(" close=")" item="item" separator=",">
            #{item}
        </foreach>
        and find_in_set(b.F_PostRankId,#{postionIds}) > 0
        and a.F_EnabledMark=0
        and F_state in
        <foreach collection="states" open="(" close=")" item="item" separator=",">
            #{item}
        </foreach>
        <if test="userIds != null and userIds.size()>0">
            and a.F_UserId in
            <foreach collection="userIds" open="(" close=")" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY a.F_CourceId
    </select>
    <!--个人维度-课程详情-->
    <select id="personalDimensionCourseDetails"
            resultType="jnpf.model.cultivate.vo.position.PersonalDimensionCourseDetails">
        SELECT a.F_CourceId as courseId,b.F_Name as courseTitle,
        SUM(a.F_LearnTime) as studyDuration,
        a.F_state as state
        FROM ftb_cultivate_position_cource_learning a JOIN ftb_cultivate_course b ON a.F_CourceId = b.F_Id
        JOIN ftb_cultivate_position_course c on a.F_CourceId = c.F_CourseId
        WHERE b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and b.F_Label = 2 and a.F_state in (1,2) and a.F_EnabledMark=0 and a.F_UserId = #{userId}
        <if test="startDate != null and endDate != null">
            and a.F_LastModifyTime between #{startDate} and #{endDate}
        </if>
        GROUP BY a.F_CourceId
    </select>
    <!--课程学习进度-->
    <select id="courseLearningProgress" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM ftb_cultivate_position_cource_chapter_learning WHERE F_UserId = #{userId}
        and F_CourceId = #{courseId} and F_EnabledMark = 0
        <if test="type == 1">
            and F_state = 1
        </if>
    </select>
    <!--岗位学习总数-->
    <select id="jobLearningProgress" resultType="java.lang.Integer">
        SELECT COUNT(distinct a.F_CourceId) FROM
        ftb_cultivate_position_cource_learning a JOIN ftb_cultivate_position_course b ON a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0 and F_UserId = #{userId} and b.F_PostRankId=#{postId}
        <if test="type == 1">
            and a.F_state = 1
        </if>
    </select>
    <!--学习地图课程总数-->
    <select id="totalNumberOfLearningMapCourses1" resultType="java.lang.Integer">
        SELECT COUNT(DISTINCT a.F_CourceId) FROM
        ftb_cultivate_position_cource_learning a JOIN ftb_cultivate_position_course b
        ON a.F_CourceId = b.F_CourseId
        WHERE b.F_EnabledMark = 0 and a.F_EnabledMark=0

        <if test="postIds != null and postIds.size() != 0">
            AND
            b.F_PostRankId in
            <foreach collection="postIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>

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

    </select>
    <!--员工姓名和员工ID-->
    <select id="fuzzySearchForRosterKeywords" resultType="java.util.Map">
        SELECT F_UserId as userId,F_Name as userName FROM ftb_personnels_staff_roster WHERE
        F_SystemWokerId like concat('%',#{keyWords},'%') or F_Name like concat('%',#{keyWords},'%')
    </select>

    <select id="numberOfPeopleWhoCompletedTheStudy" resultType="java.lang.Integer">
        SELECT count(distinct a.F_UserId) FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0
        and a.F_state = 1 and a.F_UserId in
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <!--岗位考试合格率-->
    <select id="checkJobQualificationRate"
            resultType="jnpf.model.cultivate.vo.position.FtbCultivatePersonStatisticesVO$PassedTheExam">
        SELECT
            t.F_RelationPositionId AS positionId,
            IFNULL(ROUND(t.hege / t.total, 2) * 100, 0) AS averageStudyHoursPerSubordinate
        FROM
            (
            SELECT
            F_RelationPositionId,
            ( SELECT COUNT(*) FROM ftb_cultivate_exam_user WHERE F_Status IN ( 3, 5 ) AND F_RelationPositionId = a.F_RelationPositionId ) AS hege,
            ( SELECT COUNT(*) FROM ftb_cultivate_exam_user WHERE F_RelationPositionId = a.F_RelationPositionId AND F_Status NOT IN ( 0, 2 )) AS total
            FROM
            ftb_cultivate_exam_user a
            WHERE
            F_EnabledMark = 1
            AND F_ExamSource IN ( 1, 2 )
            AND a.F_RelationPositionId IN
            <foreach collection="postIds" item="postId" open="(" close=")" separator=",">
                #{postId}
            </foreach>
            GROUP BY
            F_RelationPositionId
            ) as t
    </select>
    <!--获取岗位名称-->
    <select id="getPostIds" resultType="java.lang.String">
        SELECT F_PostId as positionId FROM ftb_cultivate_position
        WHERE F_EnabledMark = 0
       and F_PostId in
        <foreach collection="postIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <!--查询岗位下课程完成情况-->
    <select id="queryCourseCompletionStatusOfThePosition"
            resultType="jnpf.model.cultivate.vo.position.PersonStatisticesDto">
            SELECT
            a.F_UserId AS userId,
            COUNT( DISTINCT a.F_CourceId ) AS num
            FROM
            ftb_cultivate_position_cource_learning a
            JOIN ftb_cultivate_position_course b ON a.F_CourceId = b.F_CourseId
            JOIN ftb_cultivate_course c ON b.F_CourseId = c.F_Id
            JOIN ftb_cultivate_position_course AS d ON a.F_CourceId = d.F_CourseId
            WHERE
            b.F_EnabledMark = 0 and a.F_EnabledMark=0
            AND c.F_EnabledMark = 0
            AND c.F_Label = 2
            AND d.F_PostRankId = #{positionId}
            AND a.F_UserId in
            <foreach collection="idsByGradesId" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
            <if test="type == 0">
                and a.F_state in (1,2)
            </if>
            <if test="type == 1">
                and a.F_state = 1
            </if>
            GROUP BY
            a.F_UserId
    </select>
    <select id="queryComplateCourseLists" resultType="java.lang.String">
        SELECT distinct a.F_CourceId
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        join ftb_cultivate_position posi on posi.F_Id = b.F_PostLearnId
        WHERE
        b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0 AND
        a.F_state = 1 and
        c.F_IsGrounding=1 AND
        posi.F_IsGrounding=1 and
        b.F_PostRankId in
        <foreach collection="postLearnIds" item="postLearnId" open="(" close=")" separator=",">
            #{postLearnId}
        </foreach>
        AND a.F_UserId =#{userId}
    </select>
    <select id="queryComplateAndStudyingCourseLists" resultType="java.lang.String">
        SELECT distinct a.F_CourceId
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        join ftb_cultivate_position posi on posi.F_Id = b.F_PostLearnId
        WHERE
        b.F_EnabledMark = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and a.F_EnabledMark=0 AND
        a.F_state != 0 and
        c.F_IsGrounding=1 AND
        posi.F_IsGrounding=1 and
        b.F_PostRankId in
        <foreach collection="postLearnIds" item="postLearnId" open="(" close=")" separator=",">
            #{postLearnId}
        </foreach>
        AND a.F_UserId =#{userId}
    </select>
    <select id="queryAllNeedStudyCourseForPost" resultType="java.lang.String">
        select distinct b.F_CourseId as courseId from  ftb_cultivate_position_course b
                                                           join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        where b.F_EnabledMark = 0   and b.F_Compulsory = 0 and c.F_EnabledMark = 0 and c.F_Label = 2 and c.F_IsGrounding=1 and
              b.F_PostRankId in
        <foreach collection="positionIds" item="postLearnId" open="(" close=")" separator=",">
            #{postLearnId}
        </foreach>
    </select>

    <select id="batchQueryAllCourseStudyV2" resultType="jnpf.model.cultivate.v2.statistics.V2UserCourseStudyVo">
        SELECT
        a.F_CourceId AS courseId,
        a.F_UserId AS userId,
        a.F_State AS state
        FROM
        ftb_cultivate_position_cource_learning a
        join ftb_cultivate_course c on a.F_CourceId = c.F_Id JOIN ftb_cultivate_position_course b ON a.F_CourceId=b.F_CourseId
        WHERE
        a.F_EnabledMark=0 and c.F_IsGrounding=1 and c.F_EnabledMark=0 AND c.F_Label = 2
        <if test="userIds != null and userIds.size() > 0">
            AND   a.F_UserId in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        GROUP BY a.F_CourceId,a.F_UserId,a.F_State
    </select>

    <select id="queryAllNextUser" resultType="jnpf.model.cultivate.v2.position.vo.PersonForLeaderVo">
        select F_UserId AS userId,
        F_leaderId AS leaderId
        from  base_user_relation where F_leaderId in
        <foreach collection="leaderUserIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>
    <select id="batchQueryAllCourseStudy" resultType="jnpf.model.cultivate.vo.course.web.UserCourseStudyVo">
        SELECT
        a.F_CourceId AS courseId,
        a.F_UserId AS userId,
        a.F_State AS state,
        b.F_PostRankId AS positionId
        FROM
        ftb_cultivate_position_cource_learning a join ftb_cultivate_position_course b on a.F_CourceId = b.F_CourseId
        join ftb_cultivate_course c on b.F_CourseId = c.F_Id
        WHERE
        b.F_EnabledMark = 0  and a.F_EnabledMark=0 and c.F_IsGrounding=1 and c.F_EnabledMark=0
        <if test="userIds != null and userIds.size() > 0">
            AND   a.F_UserId in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="numberOfPeopleParticipatingInTheStudy" resultType="jnpf.model.cultivate.v2.position.vo.V2StudyCountVo">
        SELECT COUNT(distinct a.F_UserId) as userNumber,IFNULL(SUM(a.F_LearnTime),0) as totalSeconds  FROM
        ftb_cultivate_position_cource_learning a
        WHERE
        a.F_EnabledMark=0 and
        a.F_state in (1,2) and a.F_UserId IN
        <foreach collection="userIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>

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