<?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.AppDao">
	<resultMap id="RM_AppEntity" type="com.blueland.bo.AppEntity">
        <result property="appId" column="APP_ID"/>
        <result property="appName" column="APP_NAME"/>
        <result property="appDesc" column="APP_DESC"/>
        <result property="appVisitUrl" column="APP_VISIT_URL"/>
        <result property="appType" column="APP_TYPE"/>
        <result property="appPriority" column="APP_PRIORITY"/>
        <result property="status" column="STATUS"/>
        <result property="creatorId" column="CREATOR_ID"/>
        <result property="createDate" column="CREATE_DATE"/>
        <result property="updatorId" column="UPDATOR_ID"/>
        <result property="updateDate" column="UPDATE_DATE"/>
        <result property="isApply" column="IS_APPLY"/>
        <result property="isSync" column="IS_SYNC"/>
	</resultMap>

	<sql id="AppEntityColumns">
        	APP_ID,
        	APP_NAME,
        	APP_DESC,
        	APP_VISIT_URL,
        	APP_TYPE,
        	APP_PRIORITY,
        	STATUS,
        	CREATOR_ID,
        	CREATE_DATE,
        	UPDATOR_ID,
        	UPDATE_DATE,
        	IS_APPLY,
        	IS_SYNC
	</sql>
	
	<sql id="AppEntityQueryColumns">
        	APP_ID,
        	APP_NAME,
        	APP_DESC,
        	APP_VISIT_URL,
        	APP_TYPE,
        	APP_PRIORITY,
        	STATUS,
        	CREATOR_ID,
        	CREATE_DATE,
        	UPDATOR_ID,
        	UPDATE_DATE,
        	IS_APPLY,
        	IS_SYNC
	</sql>
	<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
	<insert id="insert" useGeneratedKeys="false" keyProperty="appId">
        INSERT INTO t_pf_app (<include refid="AppEntityColumns"/>) VALUES (
        	#{appId,jdbcType=VARCHAR},
        	#{appName,jdbcType=VARCHAR},
        	#{appDesc,jdbcType=VARCHAR},
        	#{appVisitUrl,jdbcType=VARCHAR},
        	#{appType,jdbcType=VARCHAR},
        	#{appPriority,jdbcType=INTEGER},
        	#{status,jdbcType=VARCHAR},
        	#{creatorId,jdbcType=VARCHAR},
        	#{createDate,jdbcType=TIMESTAMP},
        	#{updatorId,jdbcType=VARCHAR},
        	#{updateDate,jdbcType=TIMESTAMP},
        	#{isApply,jdbcType=VARCHAR},
        	#{isSync,jdbcType=VARCHAR}
        )
	</insert>

    
    <select id="get" resultMap="RM_AppEntity">
		SELECT <include refid="AppEntityQueryColumns"/>
	    FROM t_pf_app 
        WHERE 
	        APP_ID = #{appId,jdbcType=VARCHAR} 
	</select>
	
    <!--
    	分页查询已经使用Dialect进行分页,也可以不使用Dialect直接编写分页
    	因为分页查询将传 offset,pageSize,lastRows 三个参数,不同的数据库可以根于此三个参数属性应用不同的分页实现
    -->
    <select id="findList" resultMap="RM_AppEntity">
    	SELECT <include refid="AppEntityQueryColumns"/>
	    FROM t_pf_app 
		<include refid="findList_where"/>
		
		<if test="@Ognl@isNotEmpty(bo.sortColumns)">
			ORDER BY ${bo.sortColumns}
		</if>
    </select>

	<select id="findPage" resultMap="RM_AppEntity">
		SELECT <include refid="AppEntityQueryColumns"/>
		FROM t_pf_app
		<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.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.appDesc)">
				AND APP_DESC = #{bo.appDesc,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.appVisitUrl)">
				AND APP_VISIT_URL = #{bo.appVisitUrl,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.appType)">
				AND APP_TYPE = #{bo.appType,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.appPriority)">
				AND APP_PRIORITY = #{bo.appPriority,jdbcType=INTEGER}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.status)">
				AND STATUS = #{bo.status,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.creatorId)">
				AND CREATOR_ID = #{bo.creatorId,jdbcType=VARCHAR}
			</if>
	       
	       <if test="@Ognl@isNotEmpty(bo.updatorId)">
				AND UPDATOR_ID = #{bo.updatorId,jdbcType=VARCHAR}
			</if>
	       
	       <if test="@Ognl@isNotEmpty(bo.isApply)">
				AND IS_APPLY = #{bo.isApply,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.isSync)">
				AND IS_SYNC = #{bo.isSync,jdbcType=VARCHAR}
			</if>
		</where>
	</sql>
    
	
</mapper>

