<?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.OrderCallMapper">
    
    <resultMap type="OrderCall" id="OrderCallResult">
        <result property="id"    column="id"    />
        <result property="oid"    column="oid"    />
        <result property="type"    column="type"    />
        <result property="startCallTime"    column="start_call_time"    />
        <result property="callerstate"    column="callerstate"    />
        <result property="endTime"    column="end_time"    />
        <result property="duration"    column="duration"    />
        <result property="recurl"    column="recurl"    />
    </resultMap>

    <sql id="selectOrderCallVo">
        select id, oid, type, start_call_time, callerstate, end_time, duration, recurl from order_call
    </sql>

    <select id="selectCountOrderCallByOid" parameterType="Long" resultType="Integer">
        select count(0) from order_call where oid= #{oid}
    </select>

    <select id="selectOrderCallByOid" parameterType="Long"  resultMap="OrderCallResult">
        select * from order_call where oid= #{oid}
    </select>

    <select id="selectOrderCallList" parameterType="OrderCall" resultMap="OrderCallResult">
        <include refid="selectOrderCallVo"/>
        <where>  
            <if test="oid != null "> and oid = #{oid}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="startCallTime != null "> and start_call_time = #{startCallTime}</if>
            <if test="callerstate != null "> and callerstate = #{callerstate}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="duration != null "> and duration = #{duration}</if>
            <if test="recurl != null  and recurl != ''"> and recurl = #{recurl}</if>
        </where>
    </select>
    
    <select id="selectOrderCallById" parameterType="Integer" resultMap="OrderCallResult">
        <include refid="selectOrderCallVo"/>
        where id = #{id}
    </select>

    <insert id="insertOrderCall" parameterType="OrderCall" useGeneratedKeys="true" keyProperty="id">
        insert into order_call
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="oid != null">oid,</if>
            <if test="type != null">type,</if>
            <if test="startCallTime != null">start_call_time,</if>
            <if test="callerstate != null">callerstate,</if>
            <if test="endTime != null">end_time,</if>
            <if test="duration != null">duration,</if>
            <if test="recurl != null">recurl,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="oid != null">#{oid},</if>
            <if test="type != null">#{type},</if>
            <if test="startCallTime != null">#{startCallTime},</if>
            <if test="callerstate != null">#{callerstate},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="duration != null">#{duration},</if>
            <if test="recurl != null">#{recurl},</if>
         </trim>
    </insert>

    <update id="updateOrderCall" parameterType="OrderCall">
        update order_call
        <trim prefix="SET" suffixOverrides=",">
            <if test="oid != null">oid = #{oid},</if>
            <if test="type != null">type = #{type},</if>
            <if test="startCallTime != null">start_call_time = #{startCallTime},</if>
            <if test="callerstate != null">callerstate = #{callerstate},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="recurl != null">recurl = #{recurl},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOrderCallById" parameterType="Integer">
        delete from order_call where id = #{id}
    </delete>

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