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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.LibraryInfo">
        <id column="id" property="id" />
        <result column="is_deleted" property="isDeleted" />
        <result column="gmt_created" property="gmtCreated" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="creator" property="creator" />
        <result column="modifier" property="modifier" />
        <result column="name" property="name" />
        <result column="type" property="type" />
        <result column="remark" property="remark" />
        <result column="concept_id" property="conceptId" />
        <result column="is_concept" property="isConcept" />
    </resultMap>

    <select id="getAllConcept" resultType="com.diagbot.entity.LibraryInfo">
        SELECT * FROM library_info WHERE is_concept = 1
    </select>

    <select id="getAllInfor" resultType="com.diagbot.dto.LibraryInfoDTO">
        SELECT
        id,
        is_deleted,
        gmt_created,
        gmt_modified,
        creator,
        modifier,
        name,
        b.synonymous,
        type,
        remark,
        a.concept_id,
        a.is_concept
        FROM library_info a,
        (SELECT concept_id, GROUP_CONCAT(name separator ', ') as synonymous FROM library_info
        WHERE is_concept is NULL AND concept_id IS NOT NULL AND is_deleted = "N"
        GROUP BY concept_id ORDER BY concept_id) b
        WHERE a.concept_id = b.concept_id AND a.is_deleted = "N" AND a.is_concept = 1
        <if test = "term != ''">
            AND a.name like concat('%',#{term},'%')
        </if>
        <if test = "type != ''">
            AND a.type = #{type}
        </if>
    </select>

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