<?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.fs.company.mapper.CompanyVoiceRoboticCalleesMapper">
    
    <resultMap type="CompanyVoiceRoboticCallees" id="CompanyVoiceRoboticCalleesResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="phone"    column="phone"    />
        <result property="roboticId"    column="robotic_id"    />
        <result property="params"    column="params"    />
    </resultMap>

    <sql id="selectCompanyVoiceRoboticCalleesVo">
        select id, user_id, user_name, phone, robotic_id, params from company_voice_robotic_callees
    </sql>

    <select id="selectCompanyVoiceRoboticCalleesList" parameterType="CompanyVoiceRoboticCallees" resultType="CompanyVoiceRoboticCallees">
        select a.* from company_voice_robotic_callees a
        <where>
            <if test="userId != null "> and a.user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and a.user_name = #{userName}</if>
            <if test="phone != null  and phone != ''"> and a.phone = #{phone}</if>
            <if test="roboticId != null "> and a.robotic_id = #{roboticId}</if>
            <if test="params != null  and params != ''"> and a.params = #{params}</if>
        </where>
    </select>
    
    <select id="selectCompanyVoiceRoboticCalleesById" parameterType="Long" resultMap="CompanyVoiceRoboticCalleesResult">
        <include refid="selectCompanyVoiceRoboticCalleesVo"/>
        where id = #{id}
    </select>
    <select id="selectByRoboticId" resultType="com.fs.company.domain.CompanyVoiceRoboticCallees">
        select * from company_voice_robotic_callees where robotic_id = #{id}
    </select>

    <insert id="insertCompanyVoiceRoboticCallees" parameterType="CompanyVoiceRoboticCallees" useGeneratedKeys="true" keyProperty="id">
        insert into company_voice_robotic_callees
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="phone != null">phone,</if>
            <if test="roboticId != null">robotic_id,</if>
            <if test="params != null">params,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="roboticId != null">#{roboticId},</if>
            <if test="params != null">#{params},</if>
         </trim>
    </insert>
    <insert id="insertCompanyVoiceRoboticCalleesList" keyProperty="id">
        insert into company_voice_robotic_callees (user_id, user_name, phone, robotic_id, params) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.userId},#{item.userName},#{item.phone},#{item.roboticId},#{item.params})
        </foreach>
    </insert>

    <update id="updateCompanyVoiceRoboticCallees" parameterType="CompanyVoiceRoboticCallees">
        update company_voice_robotic_callees
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="roboticId != null">robotic_id = #{roboticId},</if>
            <if test="params != null">params = #{params},</if>
            <if test="uuid != null">uuid = #{uuid},</if>
            <if test="result != null">result = #{result},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanyVoiceRoboticCalleesById" parameterType="Long">
        delete from company_voice_robotic_callees where id = #{id}
    </delete>

    <delete id="deleteCompanyVoiceRoboticCalleesByIds" parameterType="String">
        delete from company_voice_robotic_callees where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteByRoboticId">
        delete from company_voice_robotic_callees where robotic_id = #{id}
    </delete>

    <select id="countByRoboticIdNotUuid" resultType="long">
        select count(*) from company_voice_robotic_callees where robotic_id = #{roboticId} and result = 0
    </select>
</mapper>