<?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.FtbCultivatePositionCoursePracticeMapper">
  
  <!--根据岗位学习 ID 列表统计练习数量-->
  <select id="countByPositionLearnIds" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
    SELECT F_PostLearnId as selectKey, COUNT(*) as num
    FROM ftb_cultivate_position_course_practice
    WHERE F_PostLearnId IN
    <foreach collection="positionLearnIds" item="id" separator="," open="(" close=")">
      #{id}
    </foreach>
    AND F_EnabledMark = 0
    GROUP BY F_PostLearnId
  </select>

  <!--根据岗位学习 ID 查询练习列表（关联技能表）-->
  <select id="listByPostLearnId" resultType="jnpf.model.cultivate.po.position.FtbCultivatePositionCoursePractice">
      SELECT p.F_Id          AS id,
             p.F_EnabledMark AS enabledMark,
             p.F_Num         AS   num,
             p.F_CourseId    AS   courseId,
             p.F_GradeId     AS   gradeId,
             p.F_PostRankId  AS   postRankId,
             p.F_PostLearnId AS   postLearnId,
             p.F_BusinessId  AS   businessId
      FROM ftb_cultivate_position_course_practice p
               INNER JOIN ftb_cultivate_teaching_skill s ON p.F_BusinessId = s.F_Id
      WHERE p.F_PostLearnId = #{postLearnId}
        AND p.F_EnabledMark = 0
        AND s.F_DeleteMark = 0
  </select>

  <!--根据岗位学习 ID 和课程 ID 列表查询练习列表（关联技能表）-->
  <select id="listByPostLearnIdAndCourseIds" resultType="jnpf.model.cultivate.po.position.FtbCultivatePositionCoursePractice">
      SELECT p.F_Id          AS id,
      p.F_EnabledMark AS enabledMark,
      p.F_Num         AS   num,
      p.F_CourseId    AS   courseId,
      p.F_GradeId     AS   gradeId,
      p.F_PostRankId  AS   postRankId,
      p.F_PostLearnId AS   postLearnId,
      p.F_BusinessId  AS   businessId
      FROM ftb_cultivate_position_course_practice p
      INNER JOIN ftb_cultivate_teaching_skill s ON p.F_BusinessId = s.F_Id
      WHERE p.F_PostLearnId = #{postLearnId}
      AND p.F_CourseId IN
      <foreach collection="courseIds" item="courseId" separator="," open="(" close=")">
          #{courseId}
      </foreach>
      AND p.F_EnabledMark = 0
      AND s.F_DeleteMark = 0
  </select>

  <!--查询所有岗位学习课程练习列表（关联技能表）-->
  <select id="queryAllPositionLearnParacticeLists" resultType="jnpf.model.cultivate.po.position.FtbCultivatePositionCoursePractice">
      SELECT p.F_Id          AS id,
             p.F_EnabledMark AS enabledMark,
             p.F_Num         AS   num,
             p.F_CourseId    AS   courseId,
             p.F_GradeId     AS   gradeId,
             p.F_PostRankId  AS   postRankId,
             p.F_PostLearnId AS   postLearnId,
             p.F_BusinessId  AS   businessId
    FROM ftb_cultivate_position_course_practice p
    INNER JOIN ftb_cultivate_teaching_skill s ON p.F_BusinessId = s.F_Id
    WHERE p.F_EnabledMark = 0
    AND s.F_DeleteMark = 0
  </select>

  <select id="queryPositionBindItem" resultType="jnpf.model.cultivate.po.position.FtbCultivatePositionCoursePractice">

      SELECT
            p.F_BusinessId  AS   businessId,
            p.F_Num         AS   num
      FROM ftb_cultivate_position_course_practice p
               INNER JOIN ftb_cultivate_teaching_skill s ON p.F_BusinessId = s.F_Id
      WHERE p.F_EnabledMark = 0
        AND s.F_DeleteMark = 0

      and p.F_PostLearnId = #{position.id}
      <if test="position.isConfiguredToGrade ==1">
          and p.F_GradeId = #{gradeId}
      </if>

    </select>

  <!--根据岗位学习ID查询练习列表（包含技能点名称）-->
  <select id="listByPostLearnIdWithName" resultType="jnpf.model.cultivate.v2.position.vo.FtbCultivatePositionCoursePracticeWithNameVo">
      SELECT p.F_Id          AS id,
             p.F_EnabledMark AS enabledMark,
             p.F_Num         AS   num,
             p.F_CourseId    AS   courseId,
             p.F_GradeId     AS   gradeId,
             p.F_PostRankId  AS   postRankId,
             p.F_PostLearnId AS   postLearnId,
             p.F_BusinessId  AS   businessId,
             s.F_Name        AS   businessName
      FROM ftb_cultivate_position_course_practice p
               INNER JOIN ftb_cultivate_teaching_skill s ON p.F_BusinessId = s.F_Id
      WHERE p.F_PostLearnId = #{postLearnId}
        AND p.F_EnabledMark = 0
        AND s.F_DeleteMark = 0
  </select>

  <!--根据岗位学习 ID 和课程 ID 列表查询练习列表（包含技能点名称）-->
  <select id="listByPostLearnIdAndCourseIdsWithName" resultType="jnpf.model.cultivate.v2.position.vo.FtbCultivatePositionCoursePracticeWithNameVo">
      SELECT p.F_Id          AS id,
             p.F_EnabledMark AS enabledMark,
             p.F_Num         AS   num,
             p.F_CourseId    AS   courseId,
             p.F_GradeId     AS   gradeId,
             p.F_PostRankId  AS   postRankId,
             p.F_PostLearnId AS   postLearnId,
             p.F_BusinessId  AS   businessId,
             s.F_Name        AS   businessName
      FROM ftb_cultivate_position_course_practice p
               INNER JOIN ftb_cultivate_teaching_skill s ON p.F_BusinessId = s.F_Id
      WHERE p.F_PostLearnId = #{postLearnId}
        AND p.F_CourseId IN
        <foreach collection="courseIds" item="courseId" separator="," open="(" close=")">
            #{courseId}
        </foreach>
        AND p.F_EnabledMark = 0
        AND s.F_DeleteMark = 0
  </select>
</mapper>