package com.ics.admin.service.impl;

import java.util.List;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ics.admin.mapper.meeting.RoomEquipmentMapper;
import com.ics.admin.domain.meeting.RoomEquipment;
import com.ics.admin.service.meeting.IRoomEquipmentService;

/**
 * 房间和设备关联Service业务层处理
 * 
 * @author chen
 * @date 2024-02-25
 */
@Service
public class RoomEquipmentServiceImpl extends ServiceImpl<RoomEquipmentMapper, RoomEquipment> implements IRoomEquipmentService {
    @Autowired
    private RoomEquipmentMapper roomEquipmentMapper;

    /**
     * 查询房间和设备关联
     * 
     * @param id 房间和设备关联ID
     * @return 房间和设备关联
     */
    @Override
    public RoomEquipment selectRoomEquipmentById(Long id) {
        return roomEquipmentMapper.selectById(id);
    }

    /**
     * 查询房间和设备关联列表
     * 
     * @param roomEquipment 房间和设备关联
     * @return 房间和设备关联
     */
    @Override
    public List<RoomEquipment> selectRoomEquipmentList(RoomEquipment roomEquipment) {
        QueryWrapper queryWrapper = new QueryWrapper();
        return roomEquipmentMapper.selectList(queryWrapper);
    }

    /**
     * 新增房间和设备关联
     * 
     * @param roomEquipment 房间和设备关联
     * @return 结果
     */
    @Override
    public int insertRoomEquipment(RoomEquipment roomEquipment) {
        return roomEquipmentMapper.insert(roomEquipment);
    }

    /**
     * 修改房间和设备关联
     * 
     * @param roomEquipment 房间和设备关联
     * @return 结果
     */
    @Override
    public int updateRoomEquipment(RoomEquipment roomEquipment) {
        return roomEquipmentMapper.updateById(roomEquipment);
    }

    /**
     * 删除房间和设备关联对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteRoomEquipmentByIds(String ids) {
        String[] idsArray = StrUtil.split(ids,",");
        return roomEquipmentMapper.deleteBatchIds(CollUtil.toList(idsArray));
    }

    /**
     * 删除房间和设备关联信息
     * 
     * @param id 房间和设备关联ID
     * @return 结果
     */
    @Override
    public int deleteRoomEquipmentById(Long id) {
        return roomEquipmentMapper.deleteRoomEquipmentById(id);
    }

    @Override
    public RoomEquipment selectByEquipmentId(Long id) {


        QueryWrapper<RoomEquipment> wrapper = new QueryWrapper<>();
        wrapper.eq("equipment_id",id);
        return roomEquipmentMapper.selectOne(wrapper);
    }

    @Override
    public RoomEquipment selectRoomId(Long roomId) {

        QueryWrapper<RoomEquipment> wrapper = new QueryWrapper<>();
        wrapper.eq("room_id",roomId);
        return roomEquipmentMapper.selectOne(wrapper);
    }

    @Override
    public RoomEquipment selectByEquipmentIdAndRoomId(RoomEquipment roomEquipment) {

        QueryWrapper<RoomEquipment> wrapper = new QueryWrapper<>();
        wrapper.eq("room_id",roomEquipment.getRoomId());
        wrapper.eq("equipment_id",roomEquipment.getEquipmentId());
        return roomEquipmentMapper.selectOne(wrapper);
    }

    @Override
    public List<RoomEquipment> selectByRoomId(Long id) {

        QueryWrapper<RoomEquipment> wrapper = new QueryWrapper<>();
        wrapper.eq("room_id",id);
        return roomEquipmentMapper.selectList(wrapper);
    }

    @Override
    public List<RoomEquipment> selectListByRoomId(Long aLong) {
        QueryWrapper<RoomEquipment> wrapper = new QueryWrapper<>();
        wrapper.eq("room_id",aLong);
        return roomEquipmentMapper.selectList(wrapper);
    }

    @Override
    public int deleteRoomEquipment(Long id) {


        QueryWrapper<RoomEquipment> wrapper = new QueryWrapper<>();
        wrapper.eq("equipment_id",id);
        int delete = roomEquipmentMapper.delete(wrapper);
        return delete;
    }


}
