<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.base.system.gentable.dao.ibatis.GentableDaoImpl">

    <select id="selectDbTableList" parameterType="paramDto" resultMap="GentableEntity-Map">
        select a.table_name As tableName, a.table_comment as tableComment, a.create_time as createTime, a.update_time as updateTime
        from information_schema.tables a
        <trim suffixOverrides="where" suffix="">
            where table_schema = (select database())
            AND table_name NOT LIKE 'act_%'
            <!--过滤初始系统表-->
           <!-- AND table_name NOT IN (
            'mortals_xhx_gentable',
            'mortals_xhx_gentable_column',
            'mortals_xhx_idgenerator',
            'mortals_xhx_menu',
            'mortals_xhx_oper_log',
            'mortals_xhx_param',
            'mortals_xhx_resource',
            'mortals_xhx_role',
            'mortals_xhx_role_auth',
            'mortals_xhx_role_user',
            'mortals_xhx_table_index',
            'mortals_xhx_task',
            'mortals_xhx_uploadfile',
            'mortals_xhx_user',
            'mortals_xhx_valid_code',
            'mortals_xhx_area'
            )-->

<!--            AND table_name NOT LIKE 'mortals_xhx_gen%'-->
            AND table_name NOT IN (select tableName from mortals_xhx_gentable
        <trim suffixOverrides="where" suffix="">
            <if test="condition.containsKey('appId')">
                <if test="condition.appId != null and condition.appId != ''">
                    where appId like #{condition.appId}
                </if>

            </if>
        </trim>

            )
            <if test="condition.containsKey('tableName')">
                <if test="condition.tableName != null and condition.tableName != ''">
                    and a.table_name like #{condition.tableName}
                </if>

            </if>


        </trim>
    </select>

    <select id="selectDbTableListByNames" resultMap="GentableEntity-Map">
        select table_name As tableName, table_comment as tableComment, create_time as createTime, update_time as updateTime
        from information_schema.tables
        where table_name NOT LIKE 'act_%'
<!--        and table_name NOT LIKE 'mortals_xhx_gen%' -->
        and table_schema = (select database())
        and table_name in
        <foreach collection="array" item="name" open="(" separator="," close=")">
            #{name}
        </foreach>
    </select>

    <!--查询所有表关联数据 -->
    <select id="selectGenTableAll" parameterType="Long" resultMap="GentableEntity-Map">
        SELECT
            t.id,
            t.tableName,
            t.tableComment,
            t.subTableName,
            t.subTableFkName,
            t.className,
            t.tplCategory,
            t.packageName,
            t.moduleName,
            t.businessName,
            t.functionName,
            t.functionAuthor,
            t.cacheServiceType,
            t.genType,
            t.dividedTableType,
            t.genFeign,
            t.feignAppName,
            t.genApi,
            t.isGenExport,
            t.isShowControl,
            t.options,
            t.remark,
            t.appId,
            c.id,
            c.columnName,
            c.columnComment,
            c.columnType,
            c.javaType,
            c.javaField,
            c.isPrimaryKey,
            c.isIncrement,
            c.isRequired,
            c.isInsert,
            c.isEdit,
            c.isList,
            c.isQuery,
            c.isExport,
            c.htmlType,
            c.queryType,
            c.sort
        FROM mortals_xhx_gentable t
        LEFT JOIN mortals_xhx_gentable_column c ON t.id = c.tableId
        WHERE t.appId=#{appId}
        ORDER BY
            c.sort
    </select>


    <update id="createTable" parameterType="String">
       ${createTableSql}
    </update>

</mapper>