<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<!-- 不使用namespace的话sql搜索定位会比较方便 -->
<mapper namespace="com.blueland.dao.AttachmentDao">
	<resultMap id="RM_AttachmentEntity" type="com.blueland.bo.AttachmentEntity">
        <result property="attId" column="att_id"/>
        <result property="appId" column="app_id"/>
        <result property="attName" column="att_name"/>
        <result property="attUrl" column="att_url"/>
        <result property="attType" column="att_type"/>
        <result property="bizId" column="biz_id"/>
        <result property="bizName" column="biz_name"/>
        <result property="attShow" column="att_show"/>
        <result property="createTime" column="create_time"/>
        <result property="createUserId" column="create_user_id"/>
        <result property="createUserName" column="create_user_name"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateUserId" column="update_user_id"/>
        <result property="updateUserName" column="update_user_name"/>
        <result property="attRemark" column="att_remark"/>
        <result property="sdkAppId" column="sdk_app_id"/>
	</resultMap>

	<sql id="AttachmentEntityColumns">
        	att_id,
        	app_id,
        	att_name,
        	att_url,
        	att_type,
        	biz_id,
        	biz_name,
        	att_show,
        	create_time,
        	create_user_id,
        	create_user_name,
        	update_time,
        	update_user_id,
        	update_user_name,
        	att_remark,
        	sdk_app_id
	</sql>
	
	<sql id="AttachmentEntityQueryColumns">
        	att_id,
        	app_id,
        	att_name,
        	att_url,
        	att_type,
        	biz_id,
        	biz_name,
        	att_show,
        	create_time,
        	create_user_id,
        	create_user_name,
        	update_time,
        	update_user_id,
        	update_user_name,
        	att_remark,
        	sdk_app_id
	</sql>
	<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
	<insert id="insert" useGeneratedKeys="false" keyProperty="attId">
        INSERT INTO t_pf_attachment (<include refid="AttachmentEntityColumns"/>) VALUES (
        	#{attId,jdbcType=VARCHAR},
        	#{appId,jdbcType=VARCHAR},
        	#{attName,jdbcType=VARCHAR},
        	#{attUrl,jdbcType=VARCHAR},
        	#{attType,jdbcType=VARCHAR},
        	#{bizId,jdbcType=VARCHAR},
        	#{bizName,jdbcType=VARCHAR},
        	#{attShow,jdbcType=VARCHAR},
        	#{createTime,jdbcType=TIMESTAMP},
        	#{createUserId,jdbcType=VARCHAR},
        	#{createUserName,jdbcType=VARCHAR},
        	#{updateTime,jdbcType=TIMESTAMP},
        	#{updateUserId,jdbcType=VARCHAR},
        	#{updateUserName,jdbcType=VARCHAR},
        	#{attRemark,jdbcType=VARCHAR},
        	#{sdkAppId,jdbcType=VARCHAR}
        )
	</insert>

    <select id="get" resultMap="RM_AttachmentEntity">
		SELECT <include refid="AttachmentEntityQueryColumns"/>
	    FROM t_pf_attachment 
        WHERE 
	        att_id = #{attId,jdbcType=VARCHAR} 
	</select>
	
	 <select id="findPageList" resultMap="RM_AttachmentEntity">
		SELECT <include refid="AttachmentEntityQueryColumns"/>
	    FROM t_pf_attachment <include refid="findList_where"/> 
	    order by create_time desc
	</select>

	<select id="findPage" resultMap="RM_AttachmentEntity">
		SELECT <include refid="AttachmentEntityQueryColumns"/>
		FROM t_pf_attachment <include refid="findList_where"/>
		order by create_time desc
	</select>
    <!--
    	分页查询已经使用Dialect进行分页,也可以不使用Dialect直接编写分页
    	因为分页查询将传 offset,pageSize,lastRows 三个参数,不同的数据库可以根于此三个参数属性应用不同的分页实现
    -->
    <select id="findList" resultMap="RM_AttachmentEntity">
    	SELECT <include refid="AttachmentEntityQueryColumns"/>
	    FROM t_pf_attachment 
		<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.attId)">
				AND att_id = #{bo.attId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.appId)">
				AND app_id = #{bo.appId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.attName)">
				AND att_name = #{bo.attName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.attUrl)">
				AND att_url = #{bo.attUrl,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.attType)">
				AND att_type = #{bo.attType,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.bizId)">
				AND biz_id = #{bo.bizId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.bizName)">
				AND biz_name = #{bo.bizName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.attShow)">
				AND att_show = #{bo.attShow,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>
	       <if test="@Ognl@isNotEmpty(bo.attRemark)">
				AND att_remark = #{bo.attRemark,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.sdkAppId)">
				AND sdk_app_id = #{bo.sdkAppId,jdbcType=VARCHAR}
			</if>
		</where>
	</sql>
    
	
</mapper>

