<?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.ym.mec.biz.dal.dao.ResourceRespositoryDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.ResourceRespository" id="ResourceRespository">
		<result column="id_" property="id" />
		<result column="name_" property="name" />
		<result column="url_" property="url" />
		<result column="order_" property="order" />
		<result column="subject_id_" property="subjectId" />
		<result column="level_" property="level" />
		<result column="parent_id_" property="parentId" />
		<result column="del_flag_" property="delFlag" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
        <result column="tenant_id_" property="tenantId"/>
	</resultMap>
	
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="ResourceRespository">
		SELECT * FROM resource_respository where tenant_id_ = #{tenantId}
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ResourceRespository" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO resource_respository (id_,name_,url_,order_,subject_id_,level_,parent_id_,del_flag_,create_time_,update_time_,tenant_id_)
		VALUES(#{id},#{name},#{url},#{order},#{subjectId},#{level},#{parentId},#{delFlag},now(),now(),#{tenantId})
	</insert>
	
	
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="ResourceRespository" parameterType="map">
		SELECT * FROM resource_respository
		<where>
			del_flag_ != 1 and tenant_id_ = #{tenantId}
			<if test="search != null">
				AND name_ LIKE CONCAT('%',#{search},'%')
			</if>
		</where>
		<include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(id_) FROM resource_respository
		<where>
			del_flag_ != 1 and tenant_id_ = #{tenantId}
			<if test="search != null">
				AND name_ LIKE CONCAT('%',#{search},'%')
			</if>
		</where>
	</select>
    <select id="findList" resultMap="ResourceRespository">
		SELECT * FROM resource_respository
		<where>
			tenant_id_ = #{tenantId}
			<if test="delFlag != null">
				AND del_flag_ = #{delFlag}
			</if>
			<if test="parentId != null">
				AND parent_id_ = #{parentId}
			</if>
			<if test="subjectId != null">
				AND (subject_id_ = #{subjectId} OR subject_id_ IS NULL)
			</if>
		</where>
		ORDER BY order_ ASC
	</select>
</mapper>
