package com.mx.cneeds.server.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.pager.Query;
import com.mx.cneeds.server.dao.DeviceChannelDao;
import com.mx.cneeds.server.device.service.DeviceChannelService;
import com.mx.cneeds.server.entity.DeviceChannelEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("deviceChannelService")
public class DeviceChannelServiceImpl extends ServiceImpl<DeviceChannelDao, DeviceChannelEntity> implements DeviceChannelService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<DeviceChannelEntity> queryWrapper = new QueryWrapper<>();

        String channelNum = (String) params.get("channelNum");
        if (channelNum != null && !"".equals(channelNum)){
            queryWrapper.eq("channel_num",channelNum);
        }

        IPage<DeviceChannelEntity> page = this.page(
                new Query<DeviceChannelEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }


    @Override
    public DeviceChannelEntity queryDeviceChannel(String channelNum){
        DeviceChannelEntity channelEntity = getOne(new QueryWrapper<DeviceChannelEntity>().eq("channel_num", channelNum));
        return channelEntity;
    }

    @Override
    public List<DeviceChannelEntity> queryDeviceChannelByids(List<Long> deviceIds){
        List<DeviceChannelEntity> deviceChannelEntities = getBaseMapper().selectBatchIds(deviceIds);
        return deviceChannelEntities;
    }
}
