package cn.iocoder.yudao.module.system.api.deviceInfo;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.api.deviceInfo.dto.DeviceInfoDto;
import cn.iocoder.yudao.module.system.dal.dataobject.deviceInfo.DeviceInfoDO;
import cn.iocoder.yudao.module.system.dal.mysql.deviceInfo.DeviceInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:qjq
 * @Date:2024/4/12 下午3:55
 */
@Service
public class DeviceInfoApiImpl implements DeviceInfoApi {
    @Resource
    private DeviceInfoMapper deviceInfoMapper;
    @Override
    public List<DeviceInfoDto> getDeviceInfoList(Long carteenId) {
        return BeanUtils.toBean(deviceInfoMapper.selectList(new LambdaQueryWrapperX<DeviceInfoDO>()
                .eqIfPresent(DeviceInfoDO::getCarteenId, carteenId)), DeviceInfoDto.class);
    }

    /**
     * @param deviceIp
     * @return
     * @Description: 根据设备ip获取设备名称
     * @Author: qjq
     * @Date: 2024/4/16 下午5:26
     */
    @Override
    public String getDeviceInfoName(String deviceIp) {
        return deviceInfoMapper.selectOne(new LambdaQueryWrapperX<DeviceInfoDO>()
                .eq(DeviceInfoDO::getDeviceIp, deviceIp)
                 .last(" limit 1"))
                .getDeviceName();
    }

    @Override
    public DeviceInfoDto getDevice(String deviceIp) {
        DeviceInfoDO deviceInfoDO = deviceInfoMapper.selectOne(new LambdaQueryWrapperX<DeviceInfoDO>()
                .eq(DeviceInfoDO::getDeviceIp, deviceIp)
                .last(" limit 1"));
        return BeanUtils.toBean(deviceInfoDO,DeviceInfoDto.class);
    }

    @Override
    public List<DeviceInfoDto> getDevice() {
        List<DeviceInfoDO> deviceInfoDOS = deviceInfoMapper.selectList();
        return BeanUtils.toBean(deviceInfoDOS,DeviceInfoDto.class);
    }
}
