<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.NotifyOrderMapper">
    
    <resultMap type="NotifyOrder" id="NotifyOrderResult">
        <result property="id"    column="id"    />
        <result property="oid"    column="oid"    />
        <result property="callState"    column="callState"    />
        <result property="displayNumber"    column="displayNumber"    />
        <result property="calleeNumber"    column="calleeNumber"    />
        <result property="duration"    column="duration"    />
        <result property="callId"    column="callId"    />
        <result property="startCallTime"    column="startCallTime"    />
        <result property="endTime"    column="endTime"    />
        <result property="answeredTime"    column="answeredTime"    />
        <result property="isAccept"    column="is_accept"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectNotifyOrderVo">
        select id, oid, callState, displayNumber, calleeNumber, duration, callId, startCallTime, endTime, answeredTime, is_accept, created_at, updated_at from notify_order
    </sql>

    <select id="selectNotifyOrderList" parameterType="NotifyOrder" resultMap="NotifyOrderResult">
        <include refid="selectNotifyOrderVo"/>
        <where>  
            <if test="oid != null "> and oid = #{oid}</if>
            <if test="callState != null  and callState != ''"> and callState = #{callState}</if>
            <if test="displayNumber != null  and displayNumber != ''"> and displayNumber = #{displayNumber}</if>
            <if test="calleeNumber != null  and calleeNumber != ''"> and calleeNumber = #{calleeNumber}</if>
            <if test="duration != null  and duration != ''"> and duration = #{duration}</if>
            <if test="callId != null  and callId != ''"> and callId = #{callId}</if>
            <if test="startCallTime != null  and startCallTime != ''"> and startCallTime = #{startCallTime}</if>
            <if test="endTime != null  and endTime != ''"> and endTime = #{endTime}</if>
            <if test="answeredTime != null  and answeredTime != ''"> and answeredTime = #{answeredTime}</if>
            <if test="isAccept != null "> and is_accept = #{isAccept}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectNotifyOrderById" parameterType="Long" resultMap="NotifyOrderResult">
        <include refid="selectNotifyOrderVo"/>
        where id = #{id}
    </select>


    <select id="selectNotifyOrderCountByOid"  parameterType="long"   resultType="Integer">
        select count(1) from notify_order where oid = #{oid}
    </select>

    <select id="selectNotifyOrderByOid" parameterType="long" resultMap="NotifyOrderResult">
        <include refid="selectNotifyOrderVo"/>
        where oid = #{oid}
    </select>

    <insert id="insertNotifyOrder" parameterType="NotifyOrder" useGeneratedKeys="true" keyProperty="id">
        insert into notify_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="oid != null">oid,</if>
            <if test="callState != null">callState,</if>
            <if test="displayNumber != null">displayNumber,</if>
            <if test="calleeNumber != null and calleeNumber != ''">calleeNumber,</if>
            <if test="duration != null">duration,</if>
            <if test="callId != null">callId,</if>
            <if test="startCallTime != null">startCallTime,</if>
            <if test="endTime != null">endTime,</if>
            <if test="answeredTime != null">answeredTime,</if>
            <if test="isAccept != null">is_accept,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="oid != null">#{oid},</if>
            <if test="callState != null">#{callState},</if>
            <if test="displayNumber != null">#{displayNumber},</if>
            <if test="calleeNumber != null and calleeNumber != ''">#{calleeNumber},</if>
            <if test="duration != null">#{duration},</if>
            <if test="callId != null">#{callId},</if>
            <if test="startCallTime != null">#{startCallTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="answeredTime != null">#{answeredTime},</if>
            <if test="isAccept != null">#{isAccept},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateNotifyOrder" parameterType="NotifyOrder">
        update notify_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="oid != null">oid = #{oid},</if>
            <if test="callState != null">callState = #{callState},</if>
            <if test="displayNumber != null">displayNumber = #{displayNumber},</if>
            <if test="calleeNumber != null and calleeNumber != ''">calleeNumber = #{calleeNumber},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="callId != null">callId = #{callId},</if>
            <if test="startCallTime != null">startCallTime = #{startCallTime},</if>
            <if test="endTime != null">endTime = #{endTime},</if>
            <if test="answeredTime != null">answeredTime = #{answeredTime},</if>
            <if test="isAccept != null">is_accept = #{isAccept},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNotifyOrderById" parameterType="Long">
        delete from notify_order where id = #{id}
    </delete>

    <delete id="deleteNotifyOrderByIds" parameterType="String">
        delete from notify_order where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>