<?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.ReceiveCallRecordEntity">
    <typeAlias alias="receiveCallRecordEntity"
               type="com.house365.beans.entity.ReceiveCallRecordEntity"/>
    <resultMap id="receiveCallRecord"
               class="com.house365.beans.entity.ReceiveCallRecordEntity">
        <result property="id" column="id"/>
        <result property="caller" column="caller"/>
        <result property="pid" column="pid"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="duration" column="duration"/>
        <result property="record" column="record"/>
        <result property="status" column="status"/>
    </resultMap>

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

        id, caller, pid, start_time, end_time, duration, record, status

        ]]>
	</sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="receiveCallRecordEntity">
        <![CDATA[
	        INSERT INTO receive_call_record (
	        	id, 
	        	caller,
	        	pid, 
	        	start_time, 
	        	end_time, 
	        	duration, 
	        	record, 
	        	status
	        ) VALUES (
	        	#id#, 
	        	#caller#,
	        	#pid#, 
	        	#startTime#, 
	        	#endTime#, 
	        	#duration#, 
	        	#record#, 
	        	#status#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post"
                   keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

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

	        UPDATE receive_call_record SET
		        caller = #caller#,
		        pid = #pid#, 
		        start_time = #startTime#, 
		        end_time = #endTime#, 
		        duration = #duration#, 
		        record = #record#, 
		        status = #status#
	        WHERE 
		        id = #id#

        ]]>
	</update>

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

	        DELETE FROM receive_call_record WHERE
	        id = #id#

        ]]>
	</delete>

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

	        DELETE FROM receive_call_record WHERE
	        id IN ($ids$)

        ]]>
	</delete>

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

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="receiveCallRecord.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <!--
            <isNotNull property="entity">
                <isNotEmpty prepend="AND" property="entity.id">
                    <![CDATA[
                    id = #entity.id#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.caller">
                    <![CDATA[
                    caller = #entity.caller#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.pid">
                    <![CDATA[
                    pid = #entity.pid#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.startTime">
                    <![CDATA[
                    start_time = #entity.startTime#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.endTime">
                    <![CDATA[
                    end_time = #entity.endTime#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.duration">
                    <![CDATA[
                    duration = #entity.duration#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.record">
                    <![CDATA[
                    record = #entity.record#
                    ]]>
                </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.caller">
                    <![CDATA[
					caller $searchFilters.caller.operation$ #searchFilters.caller.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.pid">
                    <![CDATA[
					pid $searchFilters.pid.operation$ #searchFilters.pid.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.startTime">
                    <![CDATA[
					start_time $searchFilters.startTime.operation$ #searchFilters.startTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.endTime">
                    <![CDATA[
					end_time $searchFilters.endTime.operation$ #searchFilters.endTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.duration">
                    <![CDATA[
					duration $searchFilters.duration.operation$ #searchFilters.duration.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.record">
                    <![CDATA[
					record $searchFilters.record.operation$ #searchFilters.record.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 receive_call_record
        <include refid="receiveCallRecord.queryPage"/>
    </select>

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

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