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

import java.util.ArrayList;
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.EquipmentMapper;
import com.ics.admin.domain.meeting.Equipment;
import com.ics.admin.service.meeting.IEquipmentService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 设备Service业务层处理
 * 
 * @author chen
 * @date 2024-02-25
 */
@Service
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService {
    @Autowired
    private EquipmentMapper equipmentMapper;

    /**
     * 查询设备
     * 
     * @param id 设备ID
     * @return 设备
     */
    @Override
    public Equipment selectEquipmentById(Long id) {
        return equipmentMapper.selectById(id);
    }

    /**
     * 查询设备列表
     * 
     * @param equipment 设备
     * @return 设备
     */
    @Override
    public List<Equipment> selectEquipmentList(Equipment equipment) {
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq(equipment.getParkId() !=null,"park_id", equipment.getParkId());
//        queryWrapper.eq(equipment.getTenantId() !=null,"tenant_id", equipment.getTenantId());
//
        return equipmentMapper.selectEquipmentList(equipment);
    }

    /**
     * 新增设备
     * 
     * @param equipment 设备
     * @return 结果
     */
    @Override
    public int insertEquipment(Equipment equipment) {
        return equipmentMapper.insert(equipment);
    }

    /**
     * 修改设备
     * 
     * @param equipment 设备
     * @return 结果
     */
    @Override
    public int updateEquipment(Equipment equipment) {
        return equipmentMapper.updateById(equipment);
    }

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

    /**
     * 删除设备信息
     * 
     * @param id 设备ID
     * @return 结果
     */
    @Override
    public int deleteEquipmentById(Long id) {
        return equipmentMapper.deleteEquipmentById(id);
    }

    @Override
    public List<Equipment> selectListByIds(List<Long> ids) {
                QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.in("id", ids);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Equipment selectByDeviceCode(String deviceCode) {

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("equipment_num", deviceCode);
        return baseMapper.selectOne(queryWrapper);
    }
}
