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

  <!--根据岗位学习 ID 列表统计证书数量-->
  <select id="countByPositionLearnIds" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
    SELECT F_PostLearnId as selectKey, COUNT(*) as num
    FROM ftb_cultivate_position_course_certificate
    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.FtbCultivatePositionCourseCertificate">
      SELECT pcc.F_Id            as id,
             pcc.F_PostLearnId   as postLearnId,
             pcc.F_GradeId       as gradeId,
             pcc.F_CourseId      as courseId,
             pcc.F_CertificateId as certificateId,
             pcc.F_PostRankId    as postRankId,
             pcc.F_EnabledMark   as enabledMark
    FROM ftb_cultivate_position_course_certificate pcc
    INNER JOIN ftb_cultivate_certificate cc ON pcc.F_CertificateId = cc.F_Id
    WHERE pcc.F_PostLearnId = #{postLearnId}
    AND pcc.F_EnabledMark = 0
    AND cc.F_Status = 1
    AND cc.F_EnabledMark = 1
  </select>

  <!--根据岗位学习 ID 和课程 IDs 查询证书列表（关联证书表，过滤上架且未删除）-->
  <select id="listByPostLearnIdAndCourseIds" resultType="jnpf.model.cultivate.po.FtbCultivatePositionCourseCertificate">
      SELECT pcc.F_Id            as id,
      pcc.F_PostLearnId   as postLearnId,
      pcc.F_GradeId       as gradeId,
      pcc.F_CourseId      as courseId,
      pcc.F_CertificateId as certificateId,
      pcc.F_PostRankId    as postRankId,
      pcc.F_EnabledMark   as enabledMark
    FROM ftb_cultivate_position_course_certificate pcc
    INNER JOIN ftb_cultivate_certificate cc ON pcc.F_CertificateId = cc.F_Id
    WHERE pcc.F_PostLearnId = #{postLearnId}
    AND pcc.F_CourseId IN
    <foreach collection="courseIds" item="courseId" separator="," open="(" close=")">
      #{courseId}
    </foreach>
    AND pcc.F_EnabledMark = 0
    AND cc.F_Status = 1
    AND cc.F_EnabledMark = 1
  </select>

  <!--根据岗位学习ID查询证书列表（包含证书名称）-->
  <select id="listByPostLearnIdWithName" resultType="jnpf.model.cultivate.v2.position.vo.FtbCultivatePositionCourseCertificateWithNameVo">
      SELECT pcc.F_Id            as id,
             pcc.F_PostLearnId   as postLearnId,
             pcc.F_GradeId       as gradeId,
             pcc.F_CourseId      as courseId,
             pcc.F_CertificateId as certificateId,
             pcc.F_PostRankId    as postRankId,
             pcc.F_EnabledMark   as enabledMark,
             cc.F_Name           as certificateName
    FROM ftb_cultivate_position_course_certificate pcc
    INNER JOIN ftb_cultivate_certificate cc ON pcc.F_CertificateId = cc.F_Id
    WHERE pcc.F_PostLearnId = #{postLearnId}
    AND pcc.F_EnabledMark = 0
    AND cc.F_Status = 1
    AND cc.F_EnabledMark = 1
  </select>

  <!--根据岗位学习 ID 和课程 IDs 查询证书列表（包含证书名称）-->
  <select id="listByPostLearnIdAndCourseIdsWithName" resultType="jnpf.model.cultivate.v2.position.vo.FtbCultivatePositionCourseCertificateWithNameVo">
      SELECT pcc.F_Id            as id,
             pcc.F_PostLearnId   as postLearnId,
             pcc.F_GradeId       as gradeId,
             pcc.F_CourseId      as courseId,
             pcc.F_CertificateId as certificateId,
             pcc.F_PostRankId    as postRankId,
             pcc.F_EnabledMark   as enabledMark,
             cc.F_Name           as certificateName
    FROM ftb_cultivate_position_course_certificate pcc
    INNER JOIN ftb_cultivate_certificate cc ON pcc.F_CertificateId = cc.F_Id
    WHERE pcc.F_PostLearnId = #{postLearnId}
    AND pcc.F_CourseId IN
    <foreach collection="courseIds" item="courseId" separator="," open="(" close=")">
      #{courseId}
    </foreach>
    AND pcc.F_EnabledMark = 0
    AND cc.F_Status = 1
    AND cc.F_EnabledMark = 1
  </select>
</mapper>