<?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="io.renren.modules.levelManage.dao.LevelTableDao">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="io.renren.modules.levelManage.entity.LevelTableEntity" id="levelTableMap">
        <result property="id" column="id"/>
        <result property="levelId" column="level_id"/>
        <result property="name" column="name"/>
        <result property="type" column="type"/>
        <result property="createDate" column="create_date"/>
        <result property="createUser" column="create_user"/>
        <result property="remark" column="remark"/>
        <result property="tableName" column="table_name"/>
        <result property="isLeaf" column="is_leaf"/>
    </resultMap>

    <update id="createTable" parameterType="map">
        CREATE TABLE ${tableName}
        (
            <foreach collection="cols" item="listItem" separator=",">
                ${listItem.name} ${listItem.type} COMMENT #{listItem.comment}
                <if test="listItem.name == 'id'">
                     auto_increment PRIMARY KEY
                </if>
            </foreach>
        );
    </update>

    <select id="listByLevelId" resultType="map">
        select name,type,remark from level_table WHERE level_id=#{id};
    </select>

    <select id="listColsByLevelId" resultType="String">
        select name,remark FROM level_table WHERE level_id=#{id};
    </select>

    <select id="listCommentByLevelId" resultType="String">
        select remark FROM level_table WHERE level_id=#{id};
    </select>

    <select id="listTypeByLevelId" resultType="String">
        SELECT type from level_table WHERE level_id=#{id};
    </select>

    <delete id="removeByIdsFromTableName" parameterType="List">
        DELETE from ${tableName} where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            ${id}
        </foreach>
        ;
    </delete>

    <select id="listBoolColsByLevelId" resultType="String">
        SELECT name FROM level_table WHERE level_id=#{id} and type='bool'
    </select>
</mapper>