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

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.controller.admin.gateway.vo.GatewayPageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.gateway.GatewayDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 网关 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface GatewayMapper extends BaseMapperX<GatewayDO> {

    default PageResult<GatewayDO> selectPage(GatewayPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<GatewayDO>()
                .eqIfPresent(GatewayDO::getAdminIp, reqVO.getAdminIp())
                .likeIfPresent(GatewayDO::getUsername, reqVO.getUsername())
                .eqIfPresent(GatewayDO::getPassword, reqVO.getPassword())
                .likeIfPresent(GatewayDO::getGatewayName, reqVO.getGatewayName())
                .eqIfPresent(GatewayDO::getRemark, reqVO.getRemark())
                .eqIfPresent(GatewayDO::getIsEnable, reqVO.getIsEnable())
                .betweenIfPresent(GatewayDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(GatewayDO::getGatewayCode, reqVO.getGatewayCode())
                .eqIfPresent(GatewayDO::getGatewayStatus, reqVO.getGatewayStatus())
                .eqIfPresent(GatewayDO::getTopic, reqVO.getTopic())
                .orderByDesc(GatewayDO::getId));
    }

    default List<GatewayDO> selectListByIsEnable(boolean isEnable) {
        return selectList(GatewayDO::getIsEnable, isEnable);
    }

}