<?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.LevelDao">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="io.renren.modules.levelManage.entity.LevelEntity" id="levelMap">
        <result property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="name" column="name"/>
        <result property="hasHbasetable" column="has_hbasetable"/>
        <result property="createDate" column="create_date"/>
        <result property="uid" column="uid"/>
        <result property="createTable" column="create_table"/>
        <result property="enabled" column="enabled"/>
        <result property="projectId" column="project_id"/>
    </resultMap>


    <select id="selectByName" resultMap="levelMap">
        SELECT * FROM level WHERE
         name like concat('%',#{name},'%')
         limit #{page}, #{size};
    </select>

    <select id="getCountByName" resultType="INTEGER">
        SELECT count(*) from level
        WHERE name like concat('%',#{name},'%');
    </select>

    <select id="getSonLevel" resultMap="levelMap">
        SELECT * FROM level where parent_id=#{id};
    </select>

    <select id="queryEnabledCount" resultType="INTEGER">
        SELECT count(*) FROM level WHERE enabled=1;
    </select>

    <select id="getEnabledLevels" resultMap="levelMap">
        SELECT * FROM level WHERE enabled=1;
    </select>

    <select id="queryEnabledCountWithParentId" resultType="INTEGER">
        SELECT COUNT(*) FROM `level` WHERE enabled=1 AND parent_id=#{id};
    </select>

    <select id="getEnabledSon" resultMap="levelMap">
        SELECT * FROM level where enabled=1 AND parent_id=#{id};
    </select>

    <select id="getEnabledLevelByProject" resultMap="levelMap">
	    SELECT * FROM level where project_id in
	    <foreach collection="ids" item="id" open="(" close=")" separator=",">
        ${id}
        </foreach>
	</select>
</mapper>