<?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">
<!-- 不使用namespace的话sql搜索定位会比较方便 -->
<mapper namespace="com.blueland.dao.ModuleDao">
	<resultMap id="RM_TpfModuleEntity" type="com.blueland.bo.ModuleEntity">
        <result property="moduleId" column="module_id"/>
        <result property="code" column="code"/>
        <result property="name" column="name"/>
        <result property="appId" column="app_id"/>
        <result property="appName" column="app_name"/>
        <result property="accessUrl" column="access_url"/>
        <result property="menuSys" column="menu_sys"/>
        <result property="parentId" column="parent_id"/>
        <result property="parentName" column="parent_name"/>
        <result property="hierarchy" column="hierarchy"/>
        <result property="status" column="status"/>
        <result property="sort" column="sort"/>
        <result property="remark" column="remark"/>
        <result property="createUserId" column="create_user_id"/>
        <result property="createUserName" column="create_user_name"/>
        <result property="updateUserId" column="update_user_id"/>
        <result property="updateUserName" column="update_user_name"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
	</resultMap>

	<sql id="TpfModuleEntityColumns">
        	module_id,
        	code,
        	name,
        	app_id,
        	app_name,
        	access_url,
        	menu_sys,
        	parent_id,
        	parent_name,
        	hierarchy,
        	status,
        	sort,
        	remark,
        	create_user_id,
        	create_user_name,
        	update_user_id,
        	update_user_name,
        	create_time,
        	update_time
	</sql>
	
	<sql id="TpfModuleEntityQueryColumns">
        	module_id,
        	code,
        	name,
        	app_id,
        	app_name,
        	access_url,
        	menu_sys,
        	parent_id,
        	parent_name,
        	hierarchy,
        	status,
        	sort,
        	remark,
        	create_user_id,
        	create_user_name,
        	update_user_id,
        	update_user_name,
        	create_time,
        	update_time
	</sql>
	<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
	<insert id="insert" useGeneratedKeys="false" keyProperty="moduleId">
        INSERT INTO t_pf_module (<include refid="TpfModuleEntityColumns"/>) VALUES (
        	#{moduleId,jdbcType=VARCHAR},
        	#{code,jdbcType=VARCHAR},
        	#{name,jdbcType=VARCHAR},
        	#{appId,jdbcType=VARCHAR},
        	#{appName,jdbcType=VARCHAR},
        	#{accessUrl,jdbcType=VARCHAR},
        	#{menuSys,jdbcType=VARCHAR},
        	#{parentId,jdbcType=VARCHAR},
        	#{parentName,jdbcType=VARCHAR},
        	#{hierarchy,jdbcType=INTEGER},
        	#{status,jdbcType=VARCHAR},
        	#{sort,jdbcType=INTEGER},
        	#{remark,jdbcType=VARCHAR},
        	#{createUserId,jdbcType=VARCHAR},
        	#{createUserName,jdbcType=VARCHAR},
        	#{updateUserId,jdbcType=VARCHAR},
        	#{updateUserName,jdbcType=VARCHAR},
        	#{createTime,jdbcType=TIMESTAMP},
        	#{updateTime,jdbcType=TIMESTAMP}
        )
	</insert>
    
    <select id="get" resultMap="RM_TpfModuleEntity">
		SELECT <include refid="TpfModuleEntityQueryColumns"/>
	    FROM t_pf_module 
        WHERE 
	        module_id = #{moduleId,jdbcType=VARCHAR} 
	</select>
	
    <!--
    	分页查询已经使用Dialect进行分页,也可以不使用Dialect直接编写分页
    	因为分页查询将传 offset,pageSize,lastRows 三个参数,不同的数据库可以根于此三个参数属性应用不同的分页实现
    -->
    <select id="findList" resultMap="RM_TpfModuleEntity">
    	SELECT <include refid="TpfModuleEntityQueryColumns"/>
	    FROM t_pf_module 
		<include refid="findList_where"/>
		
		<if test="@Ognl@isNotEmpty(bo.sortColumns)">
			ORDER BY ${bo.sortColumns}
		</if>
    </select>

	<select id="findPage" resultMap="RM_TpfModuleEntity">
		SELECT <include refid="TpfModuleEntityQueryColumns"/>
		FROM t_pf_module
		<include refid="findList_where"/>

		<if test="@Ognl@isNotEmpty(bo.sortColumns)">
			ORDER BY ${bo.sortColumns}
		</if>
	</select>
	
	
	<sql id="findList_where">
		<!-- ognl访问静态方法的表达式 为@class@method(args),以下为调用rapid中的Ognl.isNotEmpty()方法,还有其它方法如isNotBlank()可以使用，具体请查看Ognl类 -->
		<where>	      				
	       <if test="@Ognl@isNotEmpty(bo.moduleId)">
				AND module_id = #{bo.moduleId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.code)">
				AND code = #{bo.code,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.name)">
				AND name = #{bo.name,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.appId)">
				AND app_id = #{bo.appId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.appName)">
				AND app_name = #{bo.appName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.accessUrl)">
				AND access_url = #{bo.accessUrl,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.menuSys)">
				AND menu_sys = #{bo.menuSys,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.parentId)">
				AND parent_id = #{bo.parentId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.parentName)">
				AND parent_name = #{bo.parentName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.hierarchy)">
				AND hierarchy = #{bo.hierarchy,jdbcType=INTEGER}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.status)">
				AND status = #{bo.status,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.sort)">
				AND sort = #{bo.sort,jdbcType=INTEGER}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.remark)">
				AND remark = #{bo.remark,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.createUserId)">
				AND create_user_id = #{bo.createUserId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.createUserName)">
				AND create_user_name = #{bo.createUserName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.updateUserId)">
				AND update_user_id = #{bo.updateUserId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.updateUserName)">
				AND update_user_name = #{bo.updateUserName,jdbcType=VARCHAR}
			</if>
	       
	       
		</where>
	</sql>
    
    
    <select id="findModuleListByAppId" resultMap="RM_TpfModuleEntity" parameterType="java.lang.String">
    	SELECT <include refid="TpfModuleEntityQueryColumns"/>
	    FROM t_pf_module where app_Id = #{appId} ORDER BY sort asc,create_time desc
    </select>
	
</mapper>

