<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" 
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="com.house365.beans.entity.BaseAttachment">
	<typeAlias alias="baseAttachmentEntity"
		type="com.house365.beans.entity.BaseAttachment" />
	<resultMap id="baseAttachment"
		class="com.house365.beans.entity.BaseAttachment">
		<result property="id" column="id" />
		<result property="resourceId" column="resourceId" />
		<result property="resourceType" column="resourceType" />
		<result property="bizType" column="bizType" />
		<result property="name" column="name" />
		<result property="attachmentTypeId" column="attachmentTypeId" />
		<result property="suffix" column="suffix" />
		<result property="size" column="size" />
		<result property="remotePath" column="remotePath" />
		<result property="remoteServerUrlid" column="remoteServerUrlid" />
		<result property="remark" column="remark" />
		<result property="createTime" column="createTime"/>
	</resultMap>

	<!-- 用于select查询公用抽取的列 -->
	<sql id="baseAttachment.columns">
	    <![CDATA[
        id, resourceId, resourceType,bizType, name, attachmentTypeId, suffix, size, remotePath, remoteServerUrlid, remark, createTime
	    ]]>
	</sql>

	<!-- 新增记录 -->
	<insert id="save" parameterClass="baseAttachmentEntity">
	    <![CDATA[
	        INSERT INTO base_attachment (
	        	id, 
	        	resourceId, 
	        	resourceType, 
	        	bizType,
	        	name, 
	        	attachmentTypeId, 
	        	suffix, 
	        	size, 
	        	remotePath, 
	        	remoteServerUrlid, 
	        	remark,
	        	createTime
	        ) VALUES (
	        	#id#, 
	        	#resourceId#, 
	        	#resourceType#, 
	        	#bizType#,
	        	#name#, 
	        	#attachmentTypeId#, 
	        	#suffix#, 
	        	#size#, 
	        	#remotePath#, 
	        	#remoteServerUrlid#, 
	        	#remark#,
	        	#createTime#
	        )
	    ]]>
		<selectKey resultClass="java.lang.Integer" type="post"
			keyProperty="id">
			SELECT LAST_INSERT_ID()
		</selectKey>
	</insert>

	<!-- 新增记录 -->
	<insert id="insert" parameterClass="baseAttachmentEntity">
	    <![CDATA[
	        INSERT INTO base_attachment (
	        	id, 
	        	resourceId, 
	        	resourceType, 
	        	bizType,
	        	name, 
	        	attachmentTypeId, 
	        	suffix, 
	        	size, 
	        	remotePath, 
	        	remoteServerUrlid, 
	        	remark,
	        	createTime
	        ) VALUES (
	        	#id#, 
	        	#resourceId#, 
	        	#resourceType#, 
	        	#bizType#,
	        	#name#, 
	        	#attachmentTypeId#, 
	        	#suffix#, 
	        	#size#, 
	        	#remotePath#, 
	        	#remoteServerUrlid#, 
	        	#remark#,
	        	#createTime#
	        )
	    ]]>
		<selectKey resultClass="java.lang.Integer" type="post"
			keyProperty="id">
			SELECT LAST_INSERT_ID()
		</selectKey>
	</insert>

	<!-- 通过ID修改 -->
	<update id="update" parameterClass="baseAttachmentEntity">
	    <![CDATA[
	        UPDATE base_attachment SET
		        resourceId = #resourceId#, 
		        resourceType = #resourceType#, 
		        bizType = #bizType#,
		        name = #name#, 
		        attachmentTypeId = #attachmentTypeId#, 
		        suffix = #suffix#, 
		        size = #size#, 
		        remotePath = #remotePath#, 
		        remoteServerUrlid = #remoteServerUrlid#, 
		        remark = #remark#,
		        createTime = #createTime#
	        WHERE
		        id = #id#
	    ]]>
	</update>

	<!-- 通过ID删除 -->
	<delete id="delete">
	    <![CDATA[
	        DELETE FROM base_attachment WHERE
	        id = #id#
	    ]]>
	</delete>

	<!-- 通过ID列表批量删除 -->
	<delete id="deleteByIds" parameterClass="java.lang.String">
	    <![CDATA[
	        DELETE FROM base_attachment WHERE
	        id IN ($ids$)
	    ]]>
	</delete>

	<!-- 通过ID查询 -->
	<select id="getById" resultMap="baseAttachment">
		SELECT
		<include refid="baseAttachment.columns" />
	    <![CDATA[
	        FROM base_attachment 
	        WHERE 
		        id = #id#
	    ]]>
	</select>

	<!-- 用于分页查询抽取的公共的条件 -->
	<sql id="baseAttachment.queryPage">
		<dynamic prepend="WHERE">
		    <isNotNull property="entity">
				<isNotEmpty prepend="AND" property="entity.id">
		            <![CDATA[
					id = #entity.id#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.resourceId">
		            <![CDATA[
					resourceId = #entity.resourceId#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.resourceType">
		            <![CDATA[
					resourceType = #entity.resourceType#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.bizType">
		            <![CDATA[
					bizType = #entity.bizType#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.name">
		            <![CDATA[
					name = #entity.name#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.attachmentTypeId">
		            <![CDATA[
					attachmentTypeId = #entity.attachmentTypeId#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.suffix">
		            <![CDATA[
					suffix = #entity.suffix#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.size">
		            <![CDATA[
					size = #entity.size#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.remotePath">
		            <![CDATA[
					remotePath = #entity.remotePath#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.remoteServerUrlid">
		            <![CDATA[
					remoteServerUrlid = #entity.remoteServerUrlid#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.remark">
		            <![CDATA[
					remark = #entity.remark#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.createTime">
					<![CDATA[
					createTime = #entity.createTime#
		            ]]>
				</isNotEmpty>
			</isNotNull>
		    <isNotNull property="searchFilters">
				<isNotEmpty prepend="AND" property="searchFilters.id">
		            <![CDATA[
					id $searchFilters.id.operation$ #searchFilters.id.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.resourceId">
		            <![CDATA[
					resourceId $searchFilters.resourceId.operation$ #searchFilters.resourceId.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.resourceType">
		            <![CDATA[
					resourceType $searchFilters.resourceType.operation$ #searchFilters.resourceType.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.bizType">
		            <![CDATA[
					bizType $searchFilters.bizType.operation$ #searchFilters.bizType.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.name">
		            <![CDATA[
					name $searchFilters.name.operation$ #searchFilters.name.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.attachmentTypeId">
		            <![CDATA[
					attachmentTypeId $searchFilters.attachmentTypeId.operation$ #searchFilters.attachmentTypeId.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.suffix">
		            <![CDATA[
					suffix $searchFilters.suffix.operation$ #searchFilters.suffix.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.size">
		            <![CDATA[
					size $searchFilters.size.operation$ #searchFilters.size.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.remotePath">
		            <![CDATA[
					remotePath $searchFilters.remotePath.operation$ #searchFilters.remotePath.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.remoteServerUrlid">
		            <![CDATA[
					remoteServerUrlid $searchFilters.remoteServerUrlid.operation$ #searchFilters.remoteServerUrlid.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.remark">
		            <![CDATA[
					remark $searchFilters.remark.operation$ #searchFilters.remark.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.createTime">
					<![CDATA[
					createTime $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
				</isNotEmpty>
			</isNotNull>
		</dynamic>
		<dynamic prepend="ORDER BY">
			<isNotNull property="orderColumn">
		        <![CDATA[
				$orderColumn$
				]]>
				<isNotNull property="orderMode">
				$orderMode$
				</isNotNull>
			</isNotNull>
		</dynamic>
	</sql>

	<!-- 为分页查询符合条件的记录数 -->
	<select id="queryByPage_count" resultClass="int">
		SELECT count(*) FROM base_attachment
		<include refid="baseAttachment.queryPage" />
	</select>

	<!-- 分页查询指定页记录 -->
	<select id="queryByPage" resultMap="baseAttachment">
		SELECT
		<include refid="baseAttachment.columns" />
	    <![CDATA[
	        FROM base_attachment 
	    ]]>
		<include refid="baseAttachment.queryPage" />
		<![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
	</select>

	<!-- 查询所有记录 -->
	<select id="queryAll" resultMap="baseAttachment">
		SELECT
		<include refid="baseAttachment.columns" />
	    <![CDATA[
		    FROM base_attachment
	    ]]>
	</select>
	
	<!-- 通过resourceId查询 -->
	<select id="getByResourceId" resultMap="baseAttachment">
		SELECT
		<include refid="baseAttachment.columns" />
	    <![CDATA[
	        FROM base_attachment 
	        WHERE 
		        resourceId = #resourceId# and resourceType="com_house365_beans_po_BidProductFileEntity" order by bizType
	    ]]>
	</select>
	
	<!-- 通过resourceId和resouceType查询 -->
	<select id="queryByResourceIdAndResouceType" resultMap="baseAttachment">
		SELECT
		<include refid="baseAttachment.columns" />
	    <![CDATA[
	        FROM base_attachment 
	        WHERE 
		        resourceId = #resourceId# and resourceType = #channel#
	    ]]>
	</select>

	<!-- 通过resouceType查询 -->
	<select id="queryByResouceType" resultMap="baseAttachment">
		SELECT
		<include refid="baseAttachment.columns" />
		<![CDATA[
	        FROM base_attachment
	        WHERE
		        resourceType = #channel# order by resourceId desc
	    ]]>
	</select>

    <!-- 获取数据库当前时间 -->
    <select id="getDbNow" resultClass="java.util.Date">
        <![CDATA[
            SELECT NOW() FROM DUAL
        ]]>
    </select>
</sqlMap>