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

    <!-- 查询重复的技能点index -->
    <select id="getDistinctCountBatch" resultType="java.lang.Integer">
        select t.idx
        from (
            values
            <foreach collection="list" item="item" separator=",">
                row(#{item.index}, #{item.skillName})
            </foreach>
        ) as t (idx, skillName)
        join ftb_cultivate_teaching_skill c on t.skillName = c.F_Name and c.F_DeleteMark = 0
    </select>
    <!-- 查询技能点列表[下拉] -->
    <select id="getDownSkillList" resultType="jnpf.model.cultivate.v2.exam.vo.SkillVo">
        select F_Id skillId, F_Name skillName, F_Description skillDescription
        from ftb_cultivate_teaching_skill where (
            F_DeleteMark = 0
            <if test="null != categoryId and '' != categoryId and -1 != categoryId">
                and F_CategoryId = #{categoryId}
            </if>
            <if test="null != categoryId and '' != categoryId and -1 == categoryId">
                and COALESCE(F_CategoryId, '') = ''
            </if>
        )
        <if test="null != skillId">
            or F_Id = #{skillId}
        </if>
        order by F_Sort asc, F_CreatorTime desc
    </select>
    <!-- 查询所有技能点 -->
    <select id="getAllSkillList" resultType="jnpf.model.cultivate.vo.teaching.SkillInfoVo">
        select F_Id id, case when F_CategoryId is null then -1 else F_CategoryId end pId, F_Name `name`, 2 as `type`, F_Sort sort
        from ftb_cultivate_teaching_skill where F_DeleteMark = 0
        union all
        select F_Id id, '0' as pId, F_Name `name`, 1 as `type`, ROW_NUMBER() OVER (ORDER BY F_Id DESC) AS sort
        from ftb_cultivate_label where F_EnabledMark = 0 and F_Type = 3
    </select>
    <!-- 查询有子级的分类 -->
    <select id="getCategoryHasChild" resultType="java.lang.String">
        select distinct F_CategoryId
        from ftb_cultivate_teaching_skill
        where F_DeleteMark = 0 and F_CategoryId in
        <foreach collection="categoryIds" item="item" index="index" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
</mapper>