<?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.supervision.phone.mapper.PhoneAccessMapper">
    
    <resultMap type="PhoneAccess" id="PhoneAccessResult">
        <result property="id"    column="id"    />
        <result property="phoneId"    column="phone_id"    />
        <result property="state"    column="state"    />
        <result property="name"    column="name"    />
        <result property="time"    column="time"    />
    </resultMap>

    <sql id="selectPhoneAccessVo">
        select id, phone_id, state, name, time from phone_access
    </sql>

    <select id="selectPhoneAccessList" parameterType="PhoneAccess" resultMap="PhoneAccessResult">
        <include refid="selectPhoneAccessVo"/>
        <where>  
            <if test="phoneId != null "> and phone_id = #{phoneId}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="time != null "> and time = #{time}</if>
        </where>
    </select>
    
    <select id="selectPhoneAccessById" parameterType="Long" resultMap="PhoneAccessResult">
        <include refid="selectPhoneAccessVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertPhoneAccess" parameterType="PhoneAccess">
        insert into phone_access
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="phoneId != null">phone_id,</if>
            <if test="state != null">state,</if>
            <if test="name != null">name,</if>
            <if test="time != null">time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="phoneId != null">#{phoneId},</if>
            <if test="state != null">#{state},</if>
            <if test="name != null">#{name},</if>
            <if test="time != null">#{time},</if>
         </trim>
    </insert>

    <update id="updatePhoneAccess" parameterType="PhoneAccess">
        update phone_access
        <trim prefix="SET" suffixOverrides=",">
            <if test="phoneId != null">phone_id = #{phoneId},</if>
            <if test="state != null">state = #{state},</if>
            <if test="name != null">name = #{name},</if>
            <if test="time != null">time = #{time},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePhoneAccessById" parameterType="Long">
        delete from phone_access where id = #{id}
    </delete>

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