package com.org.web.room.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.org.web.room.domain.BcRoomBed;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BcRoomBedMapper extends BaseMapper<BcRoomBed> {

    @Select("select * " +
            "from bc_room_bed " +
            "where is_delete = 0 " +
            "and room_id = #{roomId} ")
    List<BcRoomBed> listByRoomId(@Param("roomId") Long roomId);

    @Select("select * " +
            "from bc_room_bed " +
            "where is_delete = 0 ")
    List<BcRoomBed> listAllRoom();

    @Update("update bc_room_bed set is_delete = 1, delete_by = #{deleteBy}, delete_time = now() " +
            "where is_delete = 0 " +
            "and room_id = #{roomId} ")
    void deleteByRoomId(@Param("roomId") Long roomId, @Param("deleteBy") Long deleteBy);

    @Update("<script>" +
            "update bc_room_bed set is_delete = 1, delete_by = #{deleteBy}, delete_time = now() " +
            "where is_delete = 0 " +
            "and room_id = #{roomId} " +

            "  <if test = 'idList != null and idList.size() > 0'> " +
            "   and id not in " +
            "       <foreach item='item' collection='idList' separator=',' open='(' close=')' index='index'> " +
            "           #{item} " +
            "       </foreach> " +
            "  </if> " +

            "</script>")
    void deleteWithout(@Param("roomId") Long roomId, @Param("idList") List<Long> idList, @Param("deleteBy") Long deleteBy);

}
