<?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.shkj.wms.mapper.TableHeaderMapper">

    <resultMap type="com.shkj.wms.domain.TableHeader" id="TableHeaderResult">
        <result property="id" column="id"/>
        <result property="formCode" column="form_code"/>
        <result property="tableName" column="table_name"/>
        <result property="fieldCode" column="field_code"/>
        <result property="fieldName" column="field_name"/>
        <result property="entityName" column="entity_name"/>
        <result property="fieldOrder" column="field_order"/>
        <result property="fieldShow" column="field_show"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <select id="getTable" resultType="java.lang.Integer" parameterType="java.lang.String">
                SELECT
                    count(1)
                FROM
                    information_schema. TABLES
                WHERE
                    table_schema = (SELECT DATABASE())
                AND table_name NOT LIKE 'qrtz_%'
                AND table_name NOT LIKE 'gen_%'
                AND table_name != 'sys_table_header'
                AND table_name = #{tableName}
    </select>
    <select id="getTableColumn" resultType="com.shkj.wms.vo.TableColumnVo" parameterType="java.lang.String">
        SELECT
                        TABLE_NAME,
                        COLUMN_COMMENT,
                        COLUMN_NAME,
                        ordinal_position
                    FROM
                        information_schema. COLUMNS
                    WHERE
                        table_schema = (SELECT DATABASE())
                    AND table_name = #{tableName}
                    ORDER BY
                        ordinal_position
    </select>
    <select id="getTableOption" resultType="com.shkj.wms.vo.TableListVo"
            parameterType="com.shkj.wms.bo.SyncTableHeaderBo">

        SELECT
        `TABLE_NAME` as tableName, TABLE_COMMENT as tableComment
        FROM
        information_schema. TABLES
        WHERE
        table_schema = (SELECT DATABASE())
        AND table_name NOT LIKE 'qrtz_%'
        AND table_name NOT LIKE 'gen_%'
        AND table_name != 'sys_table_header'
        <if test="tableName != null and tableName != ''">
            and `TABLE_NAME` like CONCAT('%',#{tableName},'%')
        </if>
        order by `TABLE_NAME`
    </select>
    <select id="queryTableList" resultType="com.shkj.wms.vo.TableHeaderVo"
            parameterType="com.shkj.wms.bo.TableHeaderQueryBo">
        SELECT

        `table_name`,
        MAX(id) as id,
        MAX(table_desc) as table_desc,
        MAX(update_time) as update_time
        FROM
        sys_table_header
        WHERE
        1 = 1
        <if test="tableName != null and tableName != ''">
            and `table_name` like CONCAT('%',#{tableName},'%')
        </if>
        GROUP BY
        `table_name`
    </select>

</mapper>