<?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.ReportChannelEntity">
	<typeAlias alias="reportChannelEntity"
		type="com.house365.beans.entity.ReportChannelEntity" />
	<resultMap id="reportChannel"
		class="com.house365.beans.entity.ReportChannelEntity">
		<result property="id" column="id" />
		<result property="name" column="name" />
		<result property="channelType" column="channel_type" />
		<result property="creater" column="creater" />
		<result property="createTime" column="create_time" />
		<result property="lastModifier" column="last_modifier" />
		<result property="upateTime" column="upate_time" />
		<result property="city" column="city" />
		<result property="status" column="status" />
	</resultMap>

	<!-- 用于select查询公用抽取的列 -->
	<sql id="reportChannel.columns">
	    <![CDATA[
        id, name, channel_type, creater, create_time, last_modifier, upate_time, city, status
	    ]]>
	</sql>

	<!-- 新增记录 -->
	<insert id="save" parameterClass="reportChannelEntity">
	    <![CDATA[
	        INSERT INTO report_channel (
	        	id, 
	        	name, 
	        	channel_type, 
	        	creater, 
	        	create_time, 
	        	last_modifier, 
	        	upate_time, 
	        	city, 
	        	status
	        ) VALUES (
	        	#id#, 
	        	#name#, 
	        	#channelType#, 
	        	#creater#, 
	        	#createTime#, 
	        	#lastModifier#, 
	        	#upateTime#, 
	        	#city#, 
	        	#status#
	        )
	    ]]>
		<selectKey resultClass="java.lang.Integer" type="post"
			keyProperty="id">
			SELECT LAST_INSERT_ID()
		</selectKey>
	</insert>

	<!-- 通过ID修改 -->
	<update id="update" parameterClass="reportChannelEntity">
	    <![CDATA[
	        UPDATE report_channel SET
		        name = #name#, 
		        channel_type = #channelType#, 
		        last_modifier = #lastModifier#,
		        upate_time = #upateTime#, 
		        city = #city#, 
		        status = #status#
	        WHERE 
		        id = #id#
	    ]]>
	</update>

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

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

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

	<!-- 用于分页查询抽取的公共的条件 -->
	<sql id="reportChannel.queryPage">
		<dynamic prepend="WHERE">
			<!-- 默认不开启实体作为条件 -->
			<!-- 
		    <isNotNull property="entity">
				<isNotEmpty prepend="AND" property="entity.id">
		            <![CDATA[
					id = #entity.id#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.name">
		            <![CDATA[
					name = #entity.name#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.channelType">
		            <![CDATA[
					channel_type = #entity.channelType#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.creater">
		            <![CDATA[
					creater = #entity.creater#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.createTime">
		            <![CDATA[
					create_time = #entity.createTime#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.lastModifier">
		            <![CDATA[
					last_modifier = #entity.lastModifier#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.upateTime">
		            <![CDATA[
					upate_time = #entity.upateTime#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.city">
		            <![CDATA[
					city = #entity.city#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.status">
		            <![CDATA[
					status = #entity.status#
		            ]]>
				</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.name">
		            <![CDATA[
					name $searchFilters.name.operation$ #searchFilters.name.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.channelType">
		            <![CDATA[
					channel_type $searchFilters.channelType.operation$ #searchFilters.channelType.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.creater">
		            <![CDATA[
					creater $searchFilters.creater.operation$ #searchFilters.creater.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.createTime">
		            <![CDATA[
					create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.lastModifier">
		            <![CDATA[
					last_modifier $searchFilters.lastModifier.operation$ #searchFilters.lastModifier.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.upateTime">
		            <![CDATA[
					upate_time $searchFilters.upateTime.operation$ #searchFilters.upateTime.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.city">
		            <![CDATA[
					city $searchFilters.city.operation$ #searchFilters.city.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.status">
		            <![CDATA[
					status $searchFilters.status.operation$ #searchFilters.status.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 report_channel
		<include refid="reportChannel.queryPage" />
	</select>

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

	<!-- 查询所有记录 -->
	<select id="queryAll" resultMap="reportChannel">
		SELECT
		<include refid="reportChannel.columns" />
	    <![CDATA[
		    FROM report_channel
	    ]]>
	    <include refid="reportChannel.queryPage" />
	</select>
</sqlMap>
