<?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.keyware.shandan.bianmu.mapper.MetadataDetailsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.keyware.shandan.bianmu.entity.MetadataDetailsVo">
        <id column="ID" property="id" />
        <result column="METADATA_ID" property="metadataId" />
        <result column="TABLE_NAME" property="tableName" />
        <result column="MASTER" property="master" />
        <result column="TABLE_COMMENT" property="tableComment" />
        <result column="TABLE_PRIMARY_COLUMN" property="tablePrimaryColumn" />
        <result column="TABLE_COLUMNS" property="tableColumns" />
        <result column="FOREIGN_TABLE" property="foreignTable" />
        <result column="FOREIGN_COLUMN" property="foreignColumn" />
        <result column="CREATE_USER" property="createUser" />
        <result column="CREATE_TIME" property="createTime" />
        <result column="MODIFY_USER" property="modifyUser" />
        <result column="MODIFY_TIME" property="modifyTime" />
        <!--<association property="basic"
                     column="METADATA_ID"
                     select="com.keyware.shandan.bianmu.mapper.MetadataBasicMapper.selectById"/>-->
    </resultMap>

    <select id="selectHasForeignTableData" resultType="com.keyware.shandan.bianmu.entity.MetadataDetailsVo">
        select *
        from (
                 select BMD.*
                 from B_METADATA_BASIC BMB
                          left join B_METADATA_DETAILS BMD on BMB.ID = BMD.METADATA_ID
                 where DATA_SOURCE_ID = #{datasourceId} and REVIEW_STATUS = 'PASS'
             ) TEMP
        where exists (select 1 from B_METADATA_DETAILS BMD where BMD.TABLE_NAME = TEMP.FOREIGN_TABLE)
    </select>

    <select id="selectHasForeignTableByMetadata" resultType="com.keyware.shandan.bianmu.entity.MetadataDetailsVo">
         select BMD.*
         from B_METADATA_BASIC BMB
                  left join B_METADATA_DETAILS BMD on BMB.ID = BMD.METADATA_ID
         where METADATA_ID = #{metadataId} and (REVIEW_STATUS = 'PASS' or REVIEW_STATUS = 'SUBMITTED')
    </select>

</mapper>
