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

    <!--批量根据任务id查询证书名称-->
    <select id="queryCertificateName" resultType="jnpf.model.cultivate.resp.TaskRelationCertificateVo">

        SELECT
        a.F_TaskId taskId,
        a.F_CertificateId certificateId,
        b.F_Name certificateName
        FROM
        ftb_cultivate_learn_task_certificate a
        LEFT JOIN ftb_cultivate_certificate b ON a.F_CertificateId = b.F_Id
        WHERE
        a.F_EnableMark = 0
        and  a.F_TaskId IN
        <foreach collection="taskIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO ftb_cultivate_learn_task_certificate (
         F_Id,F_TaskId, F_CertificateId, F_PhaseId,
        F_CreatorTime, F_CreatorUserId, F_LastModifyTime, F_LastModifyUserId
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id},#{item.taskId}, #{item.certificateId}, #{item.phaseId},
            #{item.creatorTime}, #{item.creatorUserId}, #{item.lastModifyTime},
            #{item.lastModifyUserId}
            )
        </foreach>
    </insert>

    <!-- 根据任务 ID 查询证书列表（关联证书表，过滤上架且未删除） -->
    <select id="listByTaskId" resultType="jnpf.model.cultivate.v2.task.vo.FtbCultivateLearnTaskCertificateVo">
        SELECT a.F_Id                 id,
               a.F_TaskId             taskId,
               a.F_CertificateId      certificateId,
               a.F_PhaseId            phaseId,
               a.F_ExamRule           examRule,
               a.F_IdentificationRule identificationRule,
               a.F_EnableMark         enableMark,
               b.F_Name               certName
        FROM ftb_cultivate_learn_task_certificate a
                 INNER JOIN ftb_cultivate_certificate b ON a.F_CertificateId = b.F_Id
        WHERE a.F_TaskId = #{taskId}
          AND a.F_EnableMark = 0
          AND b.F_Status = 1
          AND b.F_EnabledMark = 1
    </select>

    <!-- 根据任务ID和阶段ID查询证书列表（关联证书表，过滤上架且未删除） -->
    <select id="listByTaskIdAndPhaseId" resultType="jnpf.model.cultivate.v2.task.vo.FtbCultivateLearnTaskCertificateVo">
        SELECT a.F_Id                 id,
               a.F_TaskId             taskId,
               a.F_CertificateId      certificateId,
               a.F_PhaseId            phaseId,
               a.F_ExamRule           examRule,
               a.F_IdentificationRule identificationRule,
               a.F_EnableMark         enableMark,
               b.F_Name               certName
        FROM ftb_cultivate_learn_task_certificate a
                 INNER JOIN ftb_cultivate_certificate b ON a.F_CertificateId = b.F_Id
        WHERE a.F_TaskId = #{taskId}
          AND a.F_PhaseId = #{phaseId}
          AND a.F_EnableMark = 0
          AND b.F_Status = 1
          AND b.F_EnabledMark = 1
    </select>

</mapper>