<?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.FtbCultivateLearnTaskCourseMapper">
    <!--批量查询任务的课程数量-->
    <select id="groupCountNum" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
        SELECT
        F_TaskId selectKey,
        COUNT(*) num
        FROM
        ftb_cultivate_learn_task_course
        WHERE
        F_EnableMark = 0
        AND F_TaskId IN
        <foreach collection="taskIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        GROUP BY F_TaskId
    </select>
    <!--批量查询任务的课程列表-->
    <select id="groupListTaskCourse" resultType="jnpf.model.cultivate.po.learn.FtbCultivateLearnTaskCourse">
        select F_Id as id,
        F_TaskId as taskId,
        F_CourseId as courseId,
        F_IsRequired as isRequired,
        F_SortCode as sortCode
        from ftb_cultivate_learn_task_course
        where F_EnableMark = 0
        AND F_TaskId IN
        <foreach collection="taskIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <!--根据任务 ID 查询课程列表 (联表查询课程表，要求课程上架且未删除)-->
    <select id="listByTaskId" resultType="jnpf.model.cultivate.v2.task.vo.FtbCultivateLearnTaskCourseVo">
        SELECT
        a.F_Id as id,
        a.F_PhaseId as phaseId,
        a.F_TaskId as taskId,
        a.F_CourseId as courseId,
        a.F_IsRequired as isRequired,
        a.F_EnableMark as enableMark,
        a.F_SortCode as sortCode,
        b.F_Name as courseName
        FROM
        ftb_cultivate_learn_task_course a
        INNER JOIN
        ftb_cultivate_course b ON a.F_CourseId = b.F_Id
        WHERE
        a.F_EnableMark = 0
        AND a.F_TaskId = #{taskId}
        AND b.F_IsGrounding = 1
        AND b.F_EnabledMark = 0
        <if test="required != null">
            AND a.F_IsRequired = #{required}
        </if>
        ORDER BY
        a.F_SortCode ASC
    </select>

    <select id="listByTaskIdAndPhaseId" resultType="jnpf.model.cultivate.v2.task.vo.FtbCultivateLearnTaskCourseVo">
        SELECT a.F_Id         as id,
               a.F_PhaseId    as phaseId,
               a.F_TaskId     as taskId,
               a.F_CourseId   as courseId,
               a.F_IsRequired as isRequired,
               a.F_EnableMark as enableMark,
               a.F_SortCode   as sortCode,
               b.F_Name       as courseName
        FROM ftb_cultivate_learn_task_course a
                 INNER JOIN
             ftb_cultivate_course b ON a.F_CourseId = b.F_Id
        WHERE a.F_EnableMark = 0
          AND a.F_TaskId = #{taskId}
          AND a.F_PhaseId = #{phaseId}
          AND b.F_IsGrounding = 1
          AND b.F_EnabledMark = 0

        ORDER BY a.F_SortCode ASC
    </select>
</mapper>