package cn.iocoder.yudao.module.smartfactory.dal.mysql.device.cameradevice;

import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraDevicePageReqVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 设备-监控摄像头 Mapper
 *
 * @author 艾楷
 */
@Mapper
public interface CameraDeviceMapper extends BaseMapperX<CameraDeviceDO> {

    default PageResult<CameraDeviceDO> selectPage(CameraDevicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CameraDeviceDO>()
                .eqIfPresent(CameraDeviceDO::getFactoryId, reqVO.getFactoryId())
                .likeIfPresent(CameraDeviceDO::getName, reqVO.getName())
                .eqIfPresent(CameraDeviceDO::getCode, reqVO.getCode())
                .eqIfPresent(CameraDeviceDO::getType, reqVO.getType())
                .eqIfPresent(CameraDeviceDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CameraDeviceDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(CameraDeviceDO::getSort));
    }

    default List<CameraDeviceDO> selectListCameraByStatus(List<Long> factoryIds) {
        return selectList(new LambdaQueryWrapperX<CameraDeviceDO>()
                .inIfPresent(CameraDeviceDO::getFactoryId, factoryIds)
                .eq(CameraDeviceDO::getStatus, CommonStatusEnum.ENABLE.getStatus()));
    }

    default List<CameraDeviceDO> selectListCameraByFactoryId(Long factoryId) {
        return selectList(new LambdaQueryWrapperX<CameraDeviceDO>()
                .eq(factoryId != null, CameraDeviceDO::getFactoryId, factoryId)
                .eq(CameraDeviceDO::getStatus, CommonStatusEnum.ENABLE.getStatus())
                .eq(CameraDeviceDO::getIsShow, 1));
    }
}
