<?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.RushCustomerRuleEntity">
	<typeAlias alias="rushCustomerRuleEntity"
               type="com.house365.beans.entity.RushCustomerRuleEntity"/>
	<resultMap id="rushCustomerRule"
               class="com.house365.beans.entity.RushCustomerRuleEntity">
        <result property="id" column="id"/>
        <result property="department" column="department"/>
        <result property="activeTime" column="active_time"/>
        <result property="project" column="project"/>
        <result property="source" column="source"/>
        <result property="status" column="status"/>
        <result property="projectName" column="project_name"/>
        <result property="sourceName" column="source_name"/>
        <result property="activeTimeName" column="active_time_name"/>
        <result property="departmentName" column="department_name"/>
        <result property="createUserId" column="create_user_id"/>
        <result property="createUserName" column="create_user_name"/>
        <result property="createTime" column="create_time"/>
        <result property="updateUserId" column="update_user_id"/>
        <result property="updateUserName" column="update_user_name"/>
        <result property="updateTime" column="update_time"/>
		<result property="cityCode" column="city_code"/>
	</resultMap>

	<!-- 用于select查询公用抽取的列 -->
	<sql id="rushCustomerRule.columns">
	    <![CDATA[
        id, department, active_time, project, source, status, project_name, source_name, active_time_name,
        department_name, create_user_id, create_user_name, create_time, update_user_id, update_user_name,
        update_time, city_code
	    ]]>
	</sql>

	<!-- 新增记录 -->
	<insert id="save" parameterClass="rushCustomerRuleEntity">
        <![CDATA[
	        INSERT INTO rush_customer_rule (
	        	id, 
	        	department, 
	        	active_time, 
	        	project, 
	        	source, 
	        	status, 
	        	project_name, 
	        	source_name, 
	        	active_time_name, 
	        	department_name, 
	        	create_user_id, 
	        	create_user_name, 
	        	create_time, 
	        	update_user_id, 
	        	update_user_name, 
	        	update_time,
	        	city_code
	        ) VALUES (
	        	#id#, 
	        	#department#, 
	        	#activeTime#, 
	        	#project#, 
	        	#source#, 
	        	#status#, 
	        	#projectName#, 
	        	#sourceName#, 
	        	#activeTimeName#, 
	        	#departmentName#, 
	        	#createUserId#, 
	        	#createUserName#, 
	        	#createTime#, 
	        	#updateUserId#, 
	        	#updateUserName#, 
	        	#updateTime#,
	        	#cityCode#
	        )
	    ]]>
		<selectKey resultClass="java.lang.Integer" type="post"
                   keyProperty="id">
			SELECT LAST_INSERT_ID()
		</selectKey>
	</insert>

	<!-- 通过ID修改 -->
	<update id="update" parameterClass="rushCustomerRuleEntity">
	    <![CDATA[
	        UPDATE rush_customer_rule SET
		        department = #department#, 
		        active_time = #activeTime#, 
		        project = #project#, 
		        source = #source#, 
		        status = #status#, 
		        project_name = #projectName#, 
		        source_name = #sourceName#, 
		        active_time_name = #activeTimeName#, 
		        department_name = #departmentName#, 
		        create_user_id = #createUserId#, 
		        create_user_name = #createUserName#, 
		        create_time = #createTime#, 
		        update_user_id = #updateUserId#, 
		        update_user_name = #updateUserName#, 
		        update_time = #updateTime#,
		        city_code = #cityCode#
	        WHERE
		        id = #id#
	    ]]>
	</update>

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

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

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

	<!-- 用于分页查询抽取的公共的条件 -->
	<sql id="rushCustomerRule.queryPage">
		<dynamic prepend="WHERE">
			<!-- 默认不开启实体作为条件 -->
			<!-- 
		    <isNotNull property="entity">
				<isNotEmpty prepend="AND" property="entity.id">
		            <![CDATA[
					id = #entity.id#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.department">
		            <![CDATA[
					department = #entity.department#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.activeTime">
		            <![CDATA[
					active_time = #entity.activeTime#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.project">
		            <![CDATA[
					project = #entity.project#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.source">
		            <![CDATA[
					source = #entity.source#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.status">
		            <![CDATA[
					status = #entity.status#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.projectName">
		            <![CDATA[
					project_name = #entity.projectName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.sourceName">
		            <![CDATA[
					source_name = #entity.sourceName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.activeTimeName">
		            <![CDATA[
					active_time_name = #entity.activeTimeName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.departmentName">
		            <![CDATA[
					department_name = #entity.departmentName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.createUserId">
		            <![CDATA[
					create_user_id = #entity.createUserId#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.createUserName">
		            <![CDATA[
					create_user_name = #entity.createUserName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.createTime">
		            <![CDATA[
					create_time = #entity.createTime#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.updateUserId">
		            <![CDATA[
					update_user_id = #entity.updateUserId#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.updateUserName">
		            <![CDATA[
					update_user_name = #entity.updateUserName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.updateTime">
		            <![CDATA[
					update_time = #entity.updateTime#
		            ]]>
				</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.department">
                    <![CDATA[
					department $searchFilters.department.operation$ #searchFilters.department.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.activeTime">
                    <![CDATA[
					active_time $searchFilters.activeTime.operation$ #searchFilters.activeTime.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.project">
                    <![CDATA[
					project $searchFilters.project.operation$ #searchFilters.project.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.source">
                    <![CDATA[
					source $searchFilters.source.operation$ #searchFilters.source.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.status">
                    <![CDATA[
					status $searchFilters.status.operation$ #searchFilters.status.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.projectName">
                    <![CDATA[
					project_name $searchFilters.projectName.operation$ #searchFilters.projectName.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.sourceName">
                    <![CDATA[
					source_name $searchFilters.sourceName.operation$ #searchFilters.sourceName.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.activeTimeName">
                    <![CDATA[
					active_time_name $searchFilters.activeTimeName.operation$ #searchFilters.activeTimeName.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.departmentName">
                    <![CDATA[
					department_name $searchFilters.departmentName.operation$ #searchFilters.departmentName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createUserId">
                    <![CDATA[
					create_user_id $searchFilters.createUserId.operation$ #searchFilters.createUserId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createUserName">
                    <![CDATA[
					create_user_name $searchFilters.createUserName.operation$ #searchFilters.createUserName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateUserId">
                    <![CDATA[
					update_user_id $searchFilters.updateUserId.operation$ #searchFilters.updateUserId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateUserName">
                    <![CDATA[
					update_user_name $searchFilters.updateUserName.operation$ #searchFilters.updateUserName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateTime">
                    <![CDATA[
					update_time $searchFilters.updateTime.operation$ #searchFilters.updateTime.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.cityCode">
					<![CDATA[
					city_code $searchFilters.cityCode.operation$ #searchFilters.cityCode.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.departments">
                    <![CDATA[
					department in (select id from department where urlPath regexp #searchFilters.departments.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 rush_customer_rule
        <include refid="rushCustomerRule.queryPage"/>
	</select>

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

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