<?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.RushCustomerPushLogEntity">
    <typeAlias alias="rushCustomerPushLogEntity"
               type="com.house365.beans.entity.RushCustomerPushLogEntity"/>
    <resultMap id="rushCustomerPushLog"
               class="com.house365.beans.entity.RushCustomerPushLogEntity">
        <result property="id" column="id"/>
        <result property="rushCustomerId" column="rush_customer_id"/>
        <result property="departmentId" column="department_id"/>
        <result property="rushCustomerRuleId" column="rush_customer_rule_id"/>
        <result property="crmSource" column="crm_source"/>
        <result property="project" column="project"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="rushCustomerPushLog.columns">
	    <![CDATA[

        id, rush_customer_id, department_id, rush_customer_rule_id, crm_source, project, create_time

        ]]>
	</sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="rushCustomerPushLogEntity">
        <![CDATA[
	        INSERT INTO rush_customer_push_log (
	        	id, 
	        	rush_customer_id, 
	        	department_id, 
	        	rush_customer_rule_id, 
	        	crm_source, 
	        	project, 
	        	create_time
	        ) VALUES (
	        	#id#, 
	        	#rushCustomerId#, 
	        	#departmentId#, 
	        	#rushCustomerRuleId#, 
	        	#crmSource#, 
	        	#project#, 
	        	#createTime#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post"
                   keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="rushCustomerPushLogEntity">
	    <![CDATA[

	        UPDATE rush_customer_push_log SET
		        rush_customer_id = #rushCustomerId#, 
		        department_id = #departmentId#, 
		        rush_customer_rule_id = #rushCustomerRuleId#, 
		        crm_source = #crmSource#, 
		        project = #project#, 
		        create_time = #createTime#
	        WHERE 
		        id = #id#

        ]]>
	</update>

    <!-- 通过ID删除 -->
    <delete id="delete">
	    <![CDATA[

	        DELETE FROM rush_customer_push_log WHERE
	        id = #id#

        ]]>
	</delete>

    <!-- 通过ID列表批量删除 -->
    <delete id="deleteByIds" parameterClass="java.lang.String">
	    <![CDATA[

	        DELETE FROM rush_customer_push_log WHERE
	        id IN ($ids$)

        ]]>
	</delete>

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

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="rushCustomerPushLog.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <!--
            <isNotNull property="entity">
                <isNotEmpty prepend="AND" property="entity.id">
                    <![CDATA[
                    id = #entity.id#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.rushCustomerId">
                    <![CDATA[
                    rush_customer_id = #entity.rushCustomerId#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.departmentId">
                    <![CDATA[
                    department_id = #entity.departmentId#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.rushCustomerRuleId">
                    <![CDATA[
                    rush_customer_rule_id = #entity.rushCustomerRuleId#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.crmSource">
                    <![CDATA[
                    crm_source = #entity.crmSource#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.project">
                    <![CDATA[
                    project = #entity.project#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.createTime">
                    <![CDATA[
                    create_time = #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.rushCustomerId">
                    <![CDATA[
					rush_customer_id $searchFilters.rushCustomerId.operation$ #searchFilters.rushCustomerId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.departmentId">
                    <![CDATA[
					department_id $searchFilters.departmentId.operation$ #searchFilters.departmentId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.rushCustomerRuleId">
                    <![CDATA[
					rush_customer_rule_id $searchFilters.rushCustomerRuleId.operation$ #searchFilters.rushCustomerRuleId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.crmSource">
                    <![CDATA[
					crm_source $searchFilters.crmSource.operation$ #searchFilters.crmSource.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.project">
                    <![CDATA[
					project $searchFilters.project.operation$ #searchFilters.project.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					create_time $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 rush_customer_push_log
        <include refid="rushCustomerPushLog.queryPage"/>
    </select>

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

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