<?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.yeejoin.amos.boot.module.tzs.api.mapper.ElevatorRelationMapper">

    <select id="hasFocusElevator" resultType="java.lang.Integer">
        select count(1) from tz_elevator_relation el
        where el.elevator_id = #{elevatorId} and el.open_id = #{openId}
    </select>

    <insert id="focusElevator" >
        insert into tz_elevator_relation values (#{openId}, #{elevatorId})
    </insert>


    <delete id="cancelFocusElevator" >
        delete el from tz_elevator_relation el where  el.open_id =  #{openId}  and el.elevator_id = #{elevatorId}
    </delete>


    <select id="getMyFocusElevator" resultType="com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorListDto">
    SELECT
	e.sequence_nbr AS elevatorId,
	e.address AS elevatorAddress,
	e.rescue_code AS rescueCode
    FROM
        tz_elevator_relation el
    LEFT JOIN tcb_elevator e ON e.sequence_nbr = el.elevator_id
    WHERE
        el.open_id = #{openId}
    </select>


</mapper>
