<?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.bofeng.dao.UserPlaceMapper">
    <select id="getByUserId" resultType="com.bofeng.entity.UserPlace">
        select tb_user_place.*, tb_place.place_name as placeName from tb_user_place left join tb_place on(tb_place.place_id=tb_user_place.place_id) where tb_user_place.user_id = #{userId}
    </select>

    <select id="getByUserIdAndPlaceId" resultType="com.bofeng.entity.UserPlace">
        select * from tb_user_place where user_id = #{userId} and place_id = #{placeId}
    </select>

    <select id="getCurrentPlacesByUserId" resultType="map">
        select up.place_id, p.place_name, r.room_id, r.room_name, r.room_capacity, r.be_use from
        tb_user_place up
        inner join tb_place p on up.place_id=p.place_id
        inner join tb_room r on up.place_id=r.place_id
        where up.user_id=#{userId}
    </select>

    <delete id="deleteByUserIdAndPlaceId">
        delete from tb_user_place where place_id = #{placeId} and user_id = #{userId}
    </delete>

    <delete id="deleteByUserId">
        delete from tb_user_place where user_id = #{userId}
    </delete>

</mapper>