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

import java.util.*;

import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.vo.tunnelBase.TunnelBasePageReqVO;
import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.vo.tunnelBase.TunnelBaseRespVO;
import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.vo.tunnelDevice.TunnelDevicePageReqVO;
import com.cico.nest.lcdp.boot.core.qxsd.adapter.web.vo.tunnelDevice.TunnelDeviceRespVO;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.dataobject.TunnelBaseDO;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.database.dataobject.TunnelDeviceDO;
import com.cico.nest.lcdp.boot.core.system.dal.dataobject.dept.DeptDO;
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 com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 隧道设备信息 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface TunnelDeviceMapper extends BaseMapperX<TunnelDeviceDO> {

    default PageResult<TunnelDeviceDO> selectPage(TunnelDevicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TunnelDeviceDO>()
                .eqIfPresent(TunnelDeviceDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(TunnelDeviceDO::getTunnelCode, reqVO.getTunnelCode())
                .eqIfPresent(TunnelDeviceDO::getHoleId, reqVO.getHoleId())
                .eqIfPresent(TunnelDeviceDO::getHolePosition, reqVO.getHolePosition())
                .likeIfPresent(TunnelDeviceDO::getDirectionName, reqVO.getDirectionName())
                .eqIfPresent(TunnelDeviceDO::getDeviceCode, reqVO.getDeviceCode())
                .likeIfPresent(TunnelDeviceDO::getDeviceName, reqVO.getDeviceName())
                .eqIfPresent(TunnelDeviceDO::getDeviceType, reqVO.getDeviceType())
                .eqIfPresent(TunnelDeviceDO::getDeviceIp, reqVO.getDeviceIp())
                .eqIfPresent(TunnelDeviceDO::getDeviceUuid, reqVO.getDeviceUuid())
                .eqIfPresent(TunnelDeviceDO::getModule, reqVO.getModule())
                .eqIfPresent(TunnelDeviceDO::getMileStart, reqVO.getMileStart())
                .eqIfPresent(TunnelDeviceDO::getMileEnd, reqVO.getMileEnd())
                .eqIfPresent(TunnelDeviceDO::getMileStartOffset, reqVO.getMileStartOffset())
                .eqIfPresent(TunnelDeviceDO::getLine, reqVO.getLine())
                .eqIfPresent(TunnelDeviceDO::getAxisX, reqVO.getAxisX())
                .eqIfPresent(TunnelDeviceDO::getAxisY, reqVO.getAxisY())
                .eqIfPresent(TunnelDeviceDO::getLength, reqVO.getLength())
                .eqIfPresent(TunnelDeviceDO::getModelVersion, reqVO.getModelVersion())
                .eqIfPresent(TunnelDeviceDO::getPlcCode, reqVO.getPlcCode())
                .eqIfPresent(TunnelDeviceDO::getNeedCamera, reqVO.getNeedCamera())
                .eqIfPresent(TunnelDeviceDO::getTrafficEventDeviceId, reqVO.getTrafficEventDeviceId())
                .eqIfPresent(TunnelDeviceDO::getLaneInfo, reqVO.getLaneInfo())
                .betweenIfPresent(TunnelDeviceDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TunnelDeviceDO::getId));
    }
    default PageResult<TunnelDeviceRespVO> selectPageV2(TunnelDevicePageReqVO pageReqVO){
        MPJLambdaWrapper<TunnelDeviceDO> wrapper = new MPJLambdaWrapper<TunnelDeviceDO>()
                .selectAll(TunnelDeviceDO.class)
                .selectAs(DeptDO::getName, TunnelDeviceRespVO::getDeptName)
                .leftJoin(DeptDO.class,DeptDO::getId,TunnelDeviceDO::getDeptId)
                .likeIfExists(TunnelDeviceDO::getDeviceCode, pageReqVO.getDeviceCode())
                .likeIfExists(TunnelDeviceDO::getDeviceName, pageReqVO.getDeviceName())
                .eqIfExists(TunnelDeviceDO::getDeptId,pageReqVO.getDeptId())
                .likeIfExists(TunnelDeviceDO::getDirectionName, pageReqVO.getDirectionName())
                .eqIfExists(TunnelDeviceDO::getDirectionUpdown,pageReqVO.getDirectionUpdown())
                .eqIfExists(TunnelDeviceDO::getTunnelgroup,pageReqVO.getTunnelgroup())
                .likeIfExists(TunnelDeviceDO::getDeviceIp, pageReqVO.getDeviceIp())
                .likeIfExists(TunnelDeviceDO::getDeviceUuid, pageReqVO.getDeviceUuid())
                .eq(TunnelDeviceDO::getDeleted, 0)
                .orderByDesc(TunnelBaseDO::getCreateTime);
        PageResult<TunnelDeviceRespVO> result = selectJoinPage(pageReqVO,TunnelDeviceRespVO.class,wrapper);
        return result ;
    };
}
