<?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.ElevatorPersonInfoMapper">

    <resultMap type="com.inspur.domain.ElevatorPersonInfo" id="ElevatorPersonInfoResult">
        <result property="id"    column="id"    />
        <result property="personName"    column="person_name"    />
        <result property="unitName"    column="unit_name"    />
        <result property="phoneNo"    column="phone_no"    />
        <result property="safeCode"    column="safe_code"    />
        <result property="rescueCode"    column="rescue_code"    />
        <result property="personType"    column="person_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="elevatorId"    column="elevator_id"    />
    </resultMap>

    <sql id="selectElevatorPersonInfoVo">
        select id, person_name, unit_name, phone_no, safe_code, rescue_code, person_type, create_time, update_time,elevator_id from ELEVATOR_EMERGENCY.elevator_person_info
    </sql>

    <select id="selectElevatorPersonInfoList" parameterType="com.inspur.domain.ElevatorPersonInfo" resultMap="ElevatorPersonInfoResult">
        <include refid="selectElevatorPersonInfoVo"/>
        <where>
            <if test="personName != null  and personName != ''"> and person_name like concat('%', #{personName}, '%')</if>
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="phoneNo != null  and phoneNo != ''"> and phone_no = #{phoneNo}</if>
            <if test="safeCode != null  and safeCode != ''"> and safe_code = #{safeCode}</if>
            <if test="rescueCode != null  and rescueCode != ''"> and rescue_code = #{rescueCode}</if>
            <if test="personType != null "> and person_type = #{personType}</if>
            <if test="elevatorId != null "> and elevator_id = #{elevatorId}</if>
        </where>
    </select>

    <select id="selectElevatorPersonInfoById" parameterType="Long" resultMap="ElevatorPersonInfoResult">
        <include refid="selectElevatorPersonInfoVo"/>
        where id = #{id}
    </select>

    <select id="selectElevatorPersonInfoByElevatorId" parameterType="java.lang.String" resultMap="ElevatorPersonInfoResult">
        <include refid="selectElevatorPersonInfoVo"/>
        where elevator_id = #{elevatorId}
    </select>

    <insert id="insertElevatorPersonInfo" parameterType="com.inspur.domain.ElevatorPersonInfo">
        insert into ELEVATOR_EMERGENCY.elevator_person_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="personName != null">person_name,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="phoneNo != null">phone_no,</if>
            <if test="safeCode != null">safe_code,</if>
            <if test="rescueCode != null">rescue_code,</if>
            <if test="personType != null">person_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="elevatorId != null">elevator_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="personName != null">#{personName},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="phoneNo != null">#{phoneNo},</if>
            <if test="safeCode != null">#{safeCode},</if>
            <if test="rescueCode != null">#{rescueCode},</if>
            <if test="personType != null">#{personType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="elevatorId != null">#{elevatorId},</if>
        </trim>
    </insert>

    <update id="updateElevatorPersonInfo" parameterType="com.inspur.domain.ElevatorPersonInfo">
        update ELEVATOR_EMERGENCY.elevator_person_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="personName != null">person_name = #{personName},</if>
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="phoneNo != null">phone_no = #{phoneNo},</if>
            <if test="safeCode != null">safe_code = #{safeCode},</if>
            <if test="rescueCode != null">rescue_code = #{rescueCode},</if>
            <if test="personType != null">person_type = #{personType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="elevatorId != null">elevator_id = #{elevatorId},</if>
        </trim>
        where id = #{id}
    </update>

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

    <delete id="deleteElevatorPersonInfoByDeviceId" parameterType="String">
        delete from ELEVATOR_EMERGENCY.elevator_person_info where elevator_id = #{deviceId}
    </delete>

    <select id="selectElevatorIdsByHandler" parameterType="java.lang.String" resultType="java.lang.String">
        select distinct elevator_id from ELEVATOR_EMERGENCY.elevator_person_info where person_name like concat('%', #{personName}, '%')
    </select>

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