<?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.inspur.mapper.ElevatorPbxInfoMapper">

    <resultMap type="com.inspur.domain.ElevatorPbxInfo" id="ElevatorPbxInfoResult">
        <result property="id"    column="id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceBrand"    column="device_brand"    />
        <result property="deviceModel"    column="device_model"    />
        <result property="deviceIp"    column="device_ip"    />
        <result property="deviceMac"    column="device_mac"    />
        <result property="deviceState"    column="device_state"    />
        <result property="userName"    column="user_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectElevatorPbxInfoVo">
        select id, device_name, device_brand, device_model, device_ip, device_mac, device_state, user_name, create_time, update_time from ELEVATOR_EMERGENCY.elevator_pbx_info
    </sql>

    <select id="selectElevatorPbxInfoList" parameterType="com.inspur.domain.ElevatorPbxInfo" resultMap="ElevatorPbxInfoResult">
        <include refid="selectElevatorPbxInfoVo"/>
        <where>
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="deviceBrand != null  and deviceBrand != ''"> and device_brand = #{deviceBrand}</if>
            <if test="deviceModel != null  and deviceModel != ''"> and device_model = #{deviceModel}</if>
            <if test="deviceIp != null  and deviceIp != ''"> and device_ip = #{deviceIp}</if>
            <if test="deviceMac != null  and deviceMac != ''"> and device_mac = #{deviceMac}</if>
            <if test="deviceState != null "> and device_state = #{deviceState}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
        </where>
    </select>

    <select id="selectElevatorPbxInfoById" parameterType="Long" resultMap="ElevatorPbxInfoResult">
        <include refid="selectElevatorPbxInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertElevatorPbxInfo" parameterType="com.inspur.domain.ElevatorPbxInfo" useGeneratedKeys="true" keyProperty="id">
        insert into ELEVATOR_EMERGENCY.elevator_pbx_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">device_name,</if>
            <if test="deviceBrand != null">device_brand,</if>
            <if test="deviceModel != null">device_model,</if>
            <if test="deviceIp != null">device_ip,</if>
            <if test="deviceMac != null">device_mac,</if>
            <if test="deviceState != null">device_state,</if>
            <if test="userName != null">user_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceBrand != null">#{deviceBrand},</if>
            <if test="deviceModel != null">#{deviceModel},</if>
            <if test="deviceIp != null">#{deviceIp},</if>
            <if test="deviceMac != null">#{deviceMac},</if>
            <if test="deviceState != null">#{deviceState},</if>
            <if test="userName != null">#{userName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateElevatorPbxInfo" parameterType="com.inspur.domain.ElevatorPbxInfo">
        update ELEVATOR_EMERGENCY.elevator_pbx_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceBrand != null">device_brand = #{deviceBrand},</if>
            <if test="deviceModel != null">device_model = #{deviceModel},</if>
            <if test="deviceIp != null">device_ip = #{deviceIp},</if>
            <if test="deviceMac != null">device_mac = #{deviceMac},</if>
            <if test="deviceState != null">device_state = #{deviceState},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteElevatorPbxInfoById" parameterType="Long">
        delete from ELEVATOR_EMERGENCY.elevator_pbx_info where id = #{id}
    </delete>

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