<?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.diagbot.mapper.LibraryDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.LibraryDetail">
        <id column="id" property="id" />
        <result column="is_deleted" property="isDeleted" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="creator" property="creator" />
        <result column="modifier" property="modifier" />
        <result column="concept_id" property="conceptId" />
        <result column="source" property="source" />
        <result column="title" property="title" />
        <result column="content" property="content" />
        <result column="text" property="text" />
        <result column="order_no" property="orderNo" />
        <result column="position" property="position" />
        <result column="is_reason" property="isReason" />
    </resultMap>

    <select id="getAllKnowledge" resultType="com.diagbot.dto.LibraryDetailDTO">
        SELECT
        a.id,
        a.is_deleted,
        a.gmt_create,
        a.gmt_modified,
        a.creator,
        a.modifier,
        b.name,
        b.type,
        a.concept_id,
        a.source,
        a.title,
        a.content,
        a.text,
        a.order_no,
        a.position,
        a.is_reason
        FROM library_detail a, library_info b
        WHERE a.is_deleted = "N" AND a.concept_id = b.concept_id AND b.is_concept=1
        ORDER BY a.concept_id
    </select>

    <update id="truncateDetail">
        Truncate Table library_detail
    </update>

    <select id="getLimboItems" resultType="com.diagbot.entity.LibraryDetail">
        SELECT * FROM library_detail WHERE concept_id in
        (
            SELECT id FROM concept WHERE id NOT in
            (
                SELECT DISTINCT(concept_id) FROM library_info
            )
        )
    </select>

</mapper>
