<?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.FtbCultivatePositionCourseIdentityMapper">
  
  <!--根据岗位学习 ID 列表统计鉴定数量-->
  <select id="countByPositionLearnIds" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
    SELECT F_PostLearnId as selectKey, COUNT(*) as num
    FROM ftb_cultivate_position_course_identity
    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.FtbCultivatePositionCourseIdentity">
      SELECT pci.F_Id          as id,
             pci.F_EnabledMark as enabledMark,
             pci.F_PostLearnId as postLearnId,
             pci.F_CourseId    as courseId,
             pci.F_PostRankId  as postRankId,
             pci.F_GradeId     as gradeId,
             pci.F_identityId  as identityId
      FROM ftb_cultivate_position_course_identity pci
               INNER JOIN ftb_cultivate_identify_table fcit ON pci.F_identityId = fcit.F_Id
      WHERE pci.F_PostLearnId = #{postLearnId}
        AND pci.F_EnabledMark = 0
        AND fcit.F_DeleteMark = 0
        and fcit.F_IsAbnormal = 0
  </select>
  
  <!--根据岗位学习 ID 和课程 ID 列表查询鉴定列表（关联鉴定表）-->
  <select id="listByPostLearnIdAndCourseIds" resultType="jnpf.model.cultivate.po.position.FtbCultivatePositionCourseIdentity">
      SELECT pci.F_Id          as id,
      pci.F_EnabledMark as enabledMark,
      pci.F_PostLearnId as postLearnId,
      pci.F_CourseId    as courseId,
      pci.F_PostRankId  as postRankId,
      pci.F_GradeId     as gradeId,
      pci.F_identityId  as identityId
    FROM ftb_cultivate_position_course_identity pci
    INNER JOIN ftb_cultivate_identify_table fcit ON pci.F_identityId = fcit.F_Id
    WHERE pci.F_PostLearnId = #{postLearnId}
    AND pci.F_CourseId IN
    <foreach collection="courseIds" item="courseId" separator="," open="(" close=")">
      #{courseId}
    </foreach>
      <if test="gradeId !=null and gradeId !=''">
          and pci.F_GradeId = #{gradeId}
      </if>
    AND pci.F_EnabledMark = 0
    AND fcit.F_DeleteMark = 0
    and fcit.F_IsAbnormal = 0
  </select>
  
  <!--查询所有岗位学习鉴定列表（关联鉴定表）-->
  <select id="queryAllPositionLearnIdentityLists" resultType="jnpf.model.cultivate.po.position.FtbCultivatePositionCourseIdentity">
      SELECT pci.F_Id          as id,
             pci.F_EnabledMark as enabledMark,
             pci.F_PostLearnId as postLearnId,
             pci.F_CourseId    as courseId,
             pci.F_PostRankId  as postRankId,
             pci.F_GradeId     as gradeId,
             pci.F_identityId  as identityId
    FROM ftb_cultivate_position_course_identity pci
    INNER JOIN ftb_cultivate_identify_table fcit ON pci.F_identityId = fcit.F_Id
    WHERE pci.F_EnabledMark = 0
    AND fcit.F_DeleteMark = 0
      and fcit.F_IsAbnormal = 0
  </select>

  <select id="queryPositionBindItem" resultType="java.lang.String">
      SELECT
      pci.F_identityId as identityId
      FROM ftb_cultivate_position_course_identity pci
      INNER JOIN ftb_cultivate_identify_table fcit ON pci.F_identityId = fcit.F_Id
      WHERE pci.F_EnabledMark = 0
      AND fcit.F_DeleteMark = 0
      and fcit.F_IsAbnormal = 0
      and pci.F_PostLearnId = #{position.id}
      <if test="position.isConfiguredToGrade ==1">
          and pci.F_GradeId = #{gradeId}
      </if>
  </select>

  <!--根据岗位学习ID查询鉴定列表（包含鉴定名称）-->
  <select id="listByPostLearnIdWithName" resultType="jnpf.model.cultivate.v2.position.vo.FtbCultivatePositionCourseIdentityWithNameVo">
      SELECT pci.F_Id          as id,
             pci.F_EnabledMark as enabledMark,
             pci.F_PostLearnId as postLearnId,
             pci.F_CourseId    as courseId,
             pci.F_PostRankId  as postRankId,
             pci.F_GradeId     as gradeId,
             pci.F_identityId  as identityId,
             fcit.F_Name       as identityName
      FROM ftb_cultivate_position_course_identity pci
               INNER JOIN ftb_cultivate_identify_table fcit ON pci.F_identityId = fcit.F_Id
      WHERE pci.F_PostLearnId = #{postLearnId}
        AND pci.F_EnabledMark = 0
        AND fcit.F_DeleteMark = 0
        and fcit.F_IsAbnormal = 0
  </select>

  <!--根据岗位学习 ID 和课程 ID 列表查询鉴定列表（包含鉴定名称）-->
  <select id="listByPostLearnIdAndCourseIdsWithName" resultType="jnpf.model.cultivate.v2.position.vo.FtbCultivatePositionCourseIdentityWithNameVo">
      SELECT pci.F_Id          as id,
             pci.F_EnabledMark as enabledMark,
             pci.F_PostLearnId as postLearnId,
             pci.F_CourseId    as courseId,
             pci.F_PostRankId  as postRankId,
             pci.F_GradeId     as gradeId,
             pci.F_identityId  as identityId,
             fcit.F_Name       as identityName
      FROM ftb_cultivate_position_course_identity pci
               INNER JOIN ftb_cultivate_identify_table fcit ON pci.F_identityId = fcit.F_Id
      WHERE pci.F_PostLearnId = #{postLearnId}
        AND pci.F_CourseId IN
        <foreach collection="courseIds" item="courseId" separator="," open="(" close=")">
            #{courseId}
        </foreach>
        AND pci.F_EnabledMark = 0
        AND fcit.F_DeleteMark = 0
        and fcit.F_IsAbnormal = 0
  </select>
</mapper>