<?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.FtbCultivatePromotionMemberNewMapper">
    <!--查询当前人的学习地图等级-->
    <select id="queryTheCurrentUserLearningMapLevel" resultType="java.lang.Integer">
        SELECT  DISTINCT
        me.F_CurrentLearningStage
        FROM
        ftb_cultivate_promotion_post_new AS post
        INNER JOIN ftb_cultivate_promotion_member_new AS me ON  post.F_PromotionId = me.F_PromotionId
        WHERE
        (me.F_DeleteMark is null or me.F_DeleteMark = 0)
        and me.F_UserId = #{userId}
        AND post.F_PostId = #{postId}
        and  me.F_PromotionId = #{promtionId}
        AND post.F_Level = 1
        ORDER BY me.F_CurrentLearningStage DESC limit 1
    </select>
    <select id="selectStudyStep" resultType="jnpf.model.cultivate.po.promotion.FtbCultivatePromotionMemberNew">
        select F_Id as id, F_PromotionId as promotionId, F_UserId as userId, F_UserName as userName, F_OrgId as orgId, F_OrgName as orgName, F_PositionId as positionId, F_PositionName as positionName, F_GradeId as gradeId, F_GradeName as gradeName, F_CurrentLearningStage as currentLearningStage
        from ftb_cultivate_promotion_member_new
        where (F_DeleteMark is null or F_DeleteMark = 0) and F_UserId = #{userId} and F_PositionId = #{mainPositionId}
    </select>
    <select id="queryHasStudyMap" resultType="java.lang.String">
        select prop.F_Id from ftb_cultivate_promotion_new as prop join ftb_cultivate_promotion_post_new as prop_post on prop.F_Id = prop_post.F_PromotionId
                         WHERE prop.F_EnableMark=0 and prop_post.F_PostId=#{mainPositionId} and prop_post.F_Level=1
    </select>
    <select id="queryCurrLevel" resultType="java.lang.Integer">
        select DISTINCT F_CurrentLearningStage as currentLearningStage
        from ftb_cultivate_promotion_member_new
        where (F_DeleteMark is null or F_DeleteMark = 0) and F_UserId = #{userId} and F_PromotionId = #{pomotionId} limit 1
    </select>
    <select id="queryRelationMap" resultType="jnpf.model.cultivate.po.promotion.FtbCultivatePromotionPostNew">
        select F_PromotionId as promotionId,
            F_PostId as postId,
            F_PostName as postName,
            F_GradeId as gradeId,
            F_GradeName as gradeName
        from ftb_cultivate_promotion_post_new
        where F_PostId = #{postId}
    </select>

    <select id="queryMyCurrentPhase" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
        SELECT F_PromotionId as selectKey,  MAX(CONVERT(F_CurrentLearningStage, SIGNED)) as num
        FROM ftb_cultivate_promotion_member_new
        WHERE
        F_DeleteMark = 0
        <if test="promotionIds != null">
            and  F_PromotionId IN
            <foreach collection="promotionIds" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
        </if>
        and F_UserId = #{userId}

        GROUP BY F_PromotionId
    </select>

    <select id="queryMyAllSelectPosition" resultType="jnpf.model.cultivate.po.promotion.FtbCultivatePromotionMemberNew">
        select F_Id as id,
               F_PromotionId as promotionId,
               F_PromotionPostId as promotionPostId,
               F_UserId as userId,
               F_CurrentLearningStage as currentLearningStage
        from ftb_cultivate_promotion_member_new
        where (F_DeleteMark is null or F_DeleteMark = 0) and F_UserId = #{userId}
    </select>
</mapper>