package cn.iocoder.yudao.module.iot.dal.mysql.device;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
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.iot.dal.dataobject.device.DeviceAttributeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 设备属性 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface DeviceAttributeMapper extends BaseMapperX<DeviceAttributeDO> {

    default PageResult<DeviceAttributeDO> selectPage(PageParam reqVO, Long deviceId) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceAttributeDO>()
            .eq(DeviceAttributeDO::getDeviceId, deviceId)
            .orderByDesc(DeviceAttributeDO::getId));
    }

    default int deleteByDeviceId(Long deviceId) {
        return delete(DeviceAttributeDO::getDeviceId, deviceId);
    }

    default List<DeviceAttributeDO> selectList(DeviceAttributeDO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeviceAttributeDO>()
                .eqIfPresent(DeviceAttributeDO::getDeviceId, reqVO.getDeviceId())
                .likeIfPresent(DeviceAttributeDO::getAttributeName, reqVO.getAttributeName())
                .eqIfPresent(DeviceAttributeDO::getAlertId, reqVO.getAlertId())
                .eqIfPresent(DeviceAttributeDO::getGatewayId, reqVO.getGatewayId())
                .eqIfPresent(DeviceAttributeDO::getIsEnable, reqVO.getIsEnable())
                .eqIfPresent(DeviceAttributeDO::getIoType, reqVO.getIoType())
                .orderByDesc(DeviceAttributeDO::getId));
    }
    default List<DeviceAttributeDO> selectAlertList(DeviceAttributeDO reqVO) {
        return selectList(new LambdaQueryWrapperX<DeviceAttributeDO>()
                .eqIfPresent(DeviceAttributeDO::getDeviceId, reqVO.getDeviceId())
                .likeIfPresent(DeviceAttributeDO::getAttributeName, reqVO.getAttributeName())
                .eqIfPresent(DeviceAttributeDO::getGatewayId, reqVO.getGatewayId())
                .eqIfPresent(DeviceAttributeDO::getIsEnable, reqVO.getIsEnable())
                .eqIfPresent(DeviceAttributeDO::getIoType, reqVO.getIoType())
                .gtIfPresent(DeviceAttributeDO::getAlertId, 0)
                .orderByDesc(DeviceAttributeDO::getId));
    }
}