<?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="com.yeejoin.amos.knowledgebase.face.orm.dao.DocCategoryMapper">
    <select id="queryDocAndCategoryTree" parameterType="list" resultType="com.yeejoin.amos.knowledgebase.face.model.MultipleNodeModel">
      SELECT
        kdc.DOC_TITLE nodeTitle
        , kdc.SEQUENCE_NBR nodeKey
        , kdc.DIRECTORY_ID nodeParent
        , 'doc' nodeType
      FROM
        knowledge_doc_content kdc
      <where>
        <if test="docStatus != null and docStatus.length > 0">
          AND DOC_STATUS = #{docStatus}
        </if>
        <if test="categoryIds != null and categoryIds.size > 0">
          AND DIRECTORY_ID IN
            <foreach collection="categoryIds" separator="," item="categoryId" open="(" close=")">
              #{categoryId}
            </foreach>
        </if>
      </where>
      UNION
      SELECT
        dc.CATEGORY_NAME nodeTitle
        , dc.SEQUENCE_NBR nodeKey
        , dc.PARENT_ID nodeParent
        , 'category' nodeType
      FROM
        knowledge_doc_category dc
      <where>
        <if test="categoryIds != null and categoryIds.size > 0">
          AND SEQUENCE_NBR IN
            <foreach collection="categoryIds" separator="," item="categoryId" open="(" close=")">
              #{categoryId}
            </foreach>
        </if>
      </where>
    </select>
    
</mapper>
