package cn.iocoder.yudao.module.pms.dal.mysql.iotdevicetemplate;

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.pms.controller.admin.iotdevicetemplate.vo.IotDeviceTemplatePageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicetemplate.IotDeviceTemplateDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * PMS 功能优化 设备模板 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface IotDeviceTemplateMapper extends BaseMapperX<IotDeviceTemplateDO> {

    default PageResult<IotDeviceTemplateDO> selectPage(IotDeviceTemplatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotDeviceTemplateDO>()
                .eqIfPresent(IotDeviceTemplateDO::getDeviceCategoryId, reqVO.getDeviceCategoryId())
                .eqIfPresent(IotDeviceTemplateDO::getDeviceId, reqVO.getDeviceId())
                .likeIfPresent(IotDeviceTemplateDO::getName, reqVO.getName())
                .eqIfPresent(IotDeviceTemplateDO::getCode, reqVO.getCode())
                .eqIfPresent(IotDeviceTemplateDO::getAttrs, reqVO.getAttrs())
                .eqIfPresent(IotDeviceTemplateDO::getDescription, reqVO.getDescription())
                .eqIfPresent(IotDeviceTemplateDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotDeviceTemplateDO::getSort, reqVO.getSort())
                .eqIfPresent(IotDeviceTemplateDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotDeviceTemplateDO::getVersion, reqVO.getVersion())
                .betweenIfPresent(IotDeviceTemplateDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IotDeviceTemplateDO::getId));
    }

    default IotDeviceTemplateDO selectByDeviceCategoryId(Long deviceCategoryId){
        return selectOne(IotDeviceTemplateDO::getDeviceCategoryId, deviceCategoryId);
    };
}