<?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.warmer.meta.dao.MetaDataTableDao">

    <resultMap id="BaseResultMap" type="com.warmer.meta.entity.MetaDataTable">
        <!--@Table meta_data_table-->
        <result property="dataTableId" column="DataTableId" jdbcType="INTEGER"/>
        <result property="datasourceId" column="DatasourceId" jdbcType="INTEGER"/>
        <result property="dataTableCode" column="DataTableCode" jdbcType="VARCHAR"/>
        <result property="dataTableName" column="DataTableName" jdbcType="VARCHAR"/>
        <result property="status" column="Status" jdbcType="INTEGER"/>
        <result property="createUser" column="CreateUser" jdbcType="VARCHAR"/>
        <result property="createTime" column="CreateTime" jdbcType="TIMESTAMP"/>
        <result property="updateUser" column="UpdateUser" jdbcType="VARCHAR"/>
        <result property="updateTime" column="UpdateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
		DataTableId, DatasourceId, DataTableCode, DataTableName, Status, CreateUser, CreateTime, UpdateUser, UpdateTime	</sql>
    <!--查询单个-->
    <select id="queryById" resultMap="BaseResultMap">
        select
          <include refid="Base_Column_List" />
        from meta_data_table
        where DataTableId = #{datatableid}
    </select>


    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="BaseResultMap">
        select
          <include refid="Base_Column_List" />
        from meta_data_table
    </select>
    <select id="queryByDatasourceId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from meta_data_table where DatasourceId=#{datasourceId}
    </select>
    <select id="queryByDatasourceIdAndTableCode" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from meta_data_table where DatasourceId=#{datasourceId} and DataTableCode=#{dataTableCode}
    </select>
    <!--新增所有列-->
    <insert id="insert" keyProperty="dataTableId" useGeneratedKeys="true">
        insert into meta_data_table(DatasourceId, DataTableCode, DataTableName, Status, CreateUser, CreateTime, UpdateUser, UpdateTime)
        values (#{datasourceId}, #{dataTableCode}, #{dataTableName}, #{status}, #{createUser}, #{createTime}, #{updateUser}, #{updateTime})
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update meta_data_table
            set
        where DataTableId = #{datatableid}
    </update>

    <!--通过主键删除-->
    <update id="deleteById">
        update meta_data_table set Status=0 where DataTableId = #{datatableid}
    </update>

</mapper>