<?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.CustomerCallbackLogEntity">
    <typeAlias alias="customerCallbackLogEntity"
               type="com.house365.beans.entity.CustomerCallbackLogEntity"/>
    <resultMap id="customerCallbackLog"
               class="com.house365.beans.entity.CustomerCallbackLogEntity">
        <result property="id" column="id"/>
        <result property="customerId" column="customer_id"/>
        <result property="managerId" column="manager_id"/>
        <result property="managerName" column="manager_name"/>
        <result property="content" column="content"/>
        <result property="createTime" column="create_time"/>
        <result property="result" column="result"/>
        <result property="creater" column="creater"/>
        <result property="projectId" column="project_id"/>
        <result property="callRecordId" column="call_record_id"/>
        <result property="callRecordName" column="call_record_name"/>
        <result property="callRecordDuration" column="call_record_duration"/>
        <result property="source" column="source"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="customerCallbackLog.columns">
        <![CDATA[
        id, customer_id, manager_id, manager_name, content, create_time, result, creater, project_id,
        call_record_id, call_record_name, call_record_duration, source
	    ]]>
    </sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="customerCallbackLogEntity">
        <![CDATA[
	        INSERT INTO customer_callback_log (
	        	id,
	        	customer_id,
	        	manager_id,
	        	manager_name,
	        	content,
	        	create_time,
	        	result,
	        	creater,
	        	project_id,
	        	call_record_id,
	        	call_record_name,
	        	call_record_duration,
	        	source
	        ) VALUES (
	        	#id#,
	        	#customerId#,
	        	#managerId#,
	        	#managerName#,
	        	#content#,
	        	#createTime#,
	        	#result#,
	        	#creater#,
	        	#projectId#,
	        	#callRecordId#,
	        	#callRecordName#,
	        	#callRecordDuration#,
	        	#source#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post"
                   keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="customerCallbackLogEntity">
        <![CDATA[
	        UPDATE customer_callback_log SET
		        customer_id = #customerId#,
		        manager_id = #managerId#,
		        manager_name = #managerName#,
		        content = #content#,
		        create_time = #createTime#,
		        result = #result#,
		        creater = #creater#,
		        project_id = #projectId#,
		        call_record_id = #callRecordId#,
		        call_record_name = #callRecordName#,
		        call_record_duration = #callRecordDuration#,
		        source = #source#
	        WHERE
		        id = #id#
	    ]]>
    </update>

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

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

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

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="customerCallbackLog.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.id">
                    <![CDATA[
					id $searchFilters.id.operation$ #searchFilters.id.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerId">
                    <![CDATA[
					customer_id $searchFilters.customerId.operation$ #searchFilters.customerId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerId">
                    <![CDATA[
					manager_id $searchFilters.managerId.operation$ #searchFilters.managerId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.managerName">
                    <![CDATA[
					manager_name $searchFilters.managerName.operation$ #searchFilters.managerName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.content">
                    <![CDATA[
					content $searchFilters.content.operation$ #searchFilters.content.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.result">
                    <![CDATA[
					result $searchFilters.result.operation$ #searchFilters.result.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.creater">
                    <![CDATA[
					creater $searchFilters.creater.operation$ #searchFilters.creater.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectId">
                    <![CDATA[
					project_id $searchFilters.projectId.operation$ #searchFilters.projectId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.callRecordId">
                    <![CDATA[
					call_record_id $searchFilters.callRecordId.operation$ #searchFilters.callRecordId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.callRecordName">
                    <![CDATA[
					call_record_name $searchFilters.callRecordName.operation$ #searchFilters.callRecordName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.callRecordDuration">
                    <![CDATA[
					call_record_duration $searchFilters.callRecordDuration.operation$ #searchFilters.callRecordDuration.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.source">
                    <![CDATA[
					source $searchFilters.source.operation$ #searchFilters.source.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 customer_callback_log
        <include refid="customerCallbackLog.queryPage"/>
    </select>

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

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