package com.sunyard.chsm.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sunyard.chsm.enums.DeviceTmkStatus;
import com.sunyard.chsm.model.entity.Device;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * @author liulu
 * @since 2024/10/17
 */
@Mapper
public interface SpDeviceMapper extends BaseMapper<Device> {

    default Device selectOneByStatus(DeviceTmkStatus status) {
        Page<Device> devicePage = selectPage(
                Page.of(1L, 1L),
                new LambdaQueryWrapper<Device>().eq(Device::getTmkStatus, status.name())
        );
        List<Device> records = devicePage.getRecords();
        if (records.isEmpty()) {
            return null;
        }
        return records.iterator().next();
    };





}
