package com.ics.admin.service.impl.meeting;

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.DetailEquipmentMapper;
import com.ics.admin.domain.meeting.DetailEquipment;
import com.ics.admin.service.meeting.IDetailEquipmentService;

/**
 * 楼层与设备关联Service业务层处理
 * 
 * @author ics
 * @date 2024-03-27
 */
@Service
public class DetailEquipmentServiceImpl extends ServiceImpl<DetailEquipmentMapper, DetailEquipment> implements IDetailEquipmentService {
    @Autowired
    private DetailEquipmentMapper detailEquipmentMapper;

    /**
     * 查询楼层与设备关联
     * 
     * @param id 楼层与设备关联ID
     * @return 楼层与设备关联
     */
    @Override
    public DetailEquipment selectDetailEquipmentById(Long id) {
        return detailEquipmentMapper.selectById(id);
    }

    /**
     * 查询楼层与设备关联列表
     * 
     * @param detailEquipment 楼层与设备关联
     * @return 楼层与设备关联
     */
    @Override
    public List<DetailEquipment> selectDetailEquipmentList(DetailEquipment detailEquipment) {
        QueryWrapper queryWrapper = new QueryWrapper();
        return detailEquipmentMapper.selectList(queryWrapper);
    }

    /**
     * 新增楼层与设备关联
     * 
     * @param detailEquipment 楼层与设备关联
     * @return 结果
     */
    @Override
    public int insertDetailEquipment(DetailEquipment detailEquipment) {
        return detailEquipmentMapper.insert(detailEquipment);
    }

    /**
     * 修改楼层与设备关联
     * 
     * @param detailEquipment 楼层与设备关联
     * @return 结果
     */
    @Override
    public int updateDetailEquipment(DetailEquipment detailEquipment) {
        return detailEquipmentMapper.updateById(detailEquipment);
    }

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

    /**
     * 删除楼层与设备关联信息
     * 
     * @param id 楼层与设备关联ID
     * @return 结果
     */
    @Override
    public int deleteDetailEquipmentById(Long id) {
        return detailEquipmentMapper.deleteDetailEquipmentById(id);
    }

    @Override
    public DetailEquipment selectByEquipmentId(Long id) {

        QueryWrapper<DetailEquipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("equipment_id", id);
        DetailEquipment detailEquipment = detailEquipmentMapper.selectOne(queryWrapper);
        return detailEquipment;
    }

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

        QueryWrapper<DetailEquipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("building_detail_id", id);
        return detailEquipmentMapper.selectList(queryWrapper);
    }

    @Override
    public int deleteDetailEquipment(Long id) {
        QueryWrapper<DetailEquipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("equipment_id", id);
        return detailEquipmentMapper.delete(queryWrapper);
    }
}
