<?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.FtbCultivatePromotionPostNewMapper">
    <!--
    查询配置状态
    通过给定的岗位ID（postId）和是否为基础岗位（IsGrounding）来判断配置状态
    结果类型为java.lang.String
    -->
    <select id="isConfigured" resultType="java.lang.String">
        SELECT a.F_CourseId
        FROM ftb_cultivate_position_course a JOIN ftb_cultivate_position b ON a.F_PostLearnId = b.F_Id
        join ftb_cultivate_course c on c.F_Id = a.F_CourseId
        WHERE a.F_PostRankId=#{postId} AND b.F_IsGrounding = 1 and a.F_EnabledMark=0 and b.F_EnabledMark=0
        and c.F_EnabledMark = 0
    </select>

    <!--
    查询学习进度
    根据用户ID（userId）查询学习课程的数量，可选地根据课程ID列表（couseIds）和学习状态（states）进行过滤
    结果类型为java.lang.Integer
    -->
    <select id="learningProgress" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM ftb_cultivate_position_cource_learning WHERE F_UserId = #{userId} and F_EnabledMark=0
        <if test="couseIds != null and couseIds.size() > 0">
            and F_CourceId IN
            <foreach collection="couseIds" item="courseId" open="(" separator="," close=")">
                #{courseId}
            </foreach>
        </if>
        <if test="states != null and states.size() > 0">
            and F_State IN
            <foreach collection="states" item="state" open="(" separator="," close=")">
                #{state}
            </foreach>
        </if>
    </select>

</mapper>