package com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.vo.tunnelEquipment.TunnelEquipmentPageReqVO;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.dataobject.TunnelEquipmentDO;
import com.cico.nest.lcdp.framework.common.pojo.PageResult;
import com.cico.nest.lcdp.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cico.nest.lcdp.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 隧道设备 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface TunnelEquipmentMapper extends BaseMapperX<TunnelEquipmentDO> {

    default PageResult<TunnelEquipmentDO> selectPage(TunnelEquipmentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TunnelEquipmentDO>()
                .likeIfPresent(TunnelEquipmentDO::getEquipmentName,reqVO.getEquipmentName())
                .likeIfPresent(TunnelEquipmentDO::getEquipmentEncode, reqVO.getEquipmentEncode())
                .eqIfPresent(TunnelEquipmentDO::getManagementCenter, reqVO.getManagementCenter())
                .eqIfPresent(TunnelEquipmentDO::getAssociateMappingSubclass, reqVO.getAssociateMappingSubclass())
                .eqIfPresent(TunnelEquipmentDO::getTunnelDept, reqVO.getTunnelDept())
                .eqIfPresent(TunnelEquipmentDO::getBelongFacilityId, reqVO.getBelongFacilityId())
                .eqIfPresent(TunnelEquipmentDO::getUplinkDownlinkRoad, reqVO.getUplinkDownlinkRoad())
                .eqIfPresent(TunnelEquipmentDO::getEquipmentStation, reqVO.getEquipmentStation())
                .eqIfPresent(TunnelEquipmentDO::getIpAddress, reqVO.getIpAddress())
                .eqIfPresent(TunnelEquipmentDO::getEquipmentUuid, reqVO.getEquipmentUuid())
                .inIfPresent(TunnelEquipmentDO::getId,reqVO.getIds())
                .orderByDesc(TunnelEquipmentDO::getId));
    }

    default boolean existsEncode(String equipmentEncode){
        return selectCount(TunnelEquipmentDO::getEquipmentEncode, equipmentEncode) > 0;
    }

    default List<TunnelEquipmentDO> facilityCamera(String facilityId, Integer uplinkDownlinkRoad){
        LambdaQueryWrapper<TunnelEquipmentDO> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TunnelEquipmentDO::getBelongFacilityId,facilityId);
        queryWrapper.eq(TunnelEquipmentDO::getUplinkDownlinkRoad,uplinkDownlinkRoad);
        queryWrapper.eq(TunnelEquipmentDO::getAssociateMappingSubclass,"x0");
        return selectList(queryWrapper);
    }

    default List<TunnelEquipmentDO> getEquipmentList(TunnelEquipmentDO tunnelEquipmentDO){
        LambdaQueryWrapperX<TunnelEquipmentDO> queryWrapperX = new LambdaQueryWrapperX<>();
        queryWrapperX.eqIfPresent(TunnelEquipmentDO::getBelongFacilityId,tunnelEquipmentDO.getBelongFacilityId());
        queryWrapperX.eqIfPresent(TunnelEquipmentDO::getUplinkDownlinkRoad,tunnelEquipmentDO.getUplinkDownlinkRoad());
        queryWrapperX.eqIfPresent(TunnelEquipmentDO::getEquipmentStation,tunnelEquipmentDO.getEquipmentStation());
        return selectList(queryWrapperX);

    }

}
