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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
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.iotmainworkorderbom.vo.IotMainWorkOrderBomPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbom.IotMainWorkOrderBomDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * PMS 保养工单明细BOM Mapper
 *
 * @author ruiqi
 */
@Mapper
public interface IotMainWorkOrderBomMapper extends BaseMapperX<IotMainWorkOrderBomDO> {

    default PageResult<IotMainWorkOrderBomDO> selectPage(IotMainWorkOrderBomPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotMainWorkOrderBomDO>()
                .eqIfPresent(IotMainWorkOrderBomDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(IotMainWorkOrderBomDO::getPlanDetailId, reqVO.getPlanDetailId())
                .eqIfPresent(IotMainWorkOrderBomDO::getWorkOrderId, reqVO.getWorkOrderId())
                .eqIfPresent(IotMainWorkOrderBomDO::getDeviceCategoryId, reqVO.getDeviceCategoryId())
                .eqIfPresent(IotMainWorkOrderBomDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(IotMainWorkOrderBomDO::getRule, reqVO.getRule())
                .eqIfPresent(IotMainWorkOrderBomDO::getMileageRule, reqVO.getMileageRule())
                .eqIfPresent(IotMainWorkOrderBomDO::getNaturalDateRule, reqVO.getNaturalDateRule())
                .eqIfPresent(IotMainWorkOrderBomDO::getRunningTimeRule, reqVO.getRunningTimeRule())
                .betweenIfPresent(IotMainWorkOrderBomDO::getLastRunningTime, reqVO.getLastRunningTime())
                .betweenIfPresent(IotMainWorkOrderBomDO::getNextRunningTime, reqVO.getNextRunningTime())
                .eqIfPresent(IotMainWorkOrderBomDO::getDelayDuration, reqVO.getDelayDuration())
                .eqIfPresent(IotMainWorkOrderBomDO::getLastRunningKilometers, reqVO.getLastRunningKilometers())
                .eqIfPresent(IotMainWorkOrderBomDO::getNextRunningKilometers, reqVO.getNextRunningKilometers())
                .eqIfPresent(IotMainWorkOrderBomDO::getDelayKilometers, reqVO.getDelayKilometers())
                .betweenIfPresent(IotMainWorkOrderBomDO::getLastNaturalDate, reqVO.getLastNaturalDate())
                .betweenIfPresent(IotMainWorkOrderBomDO::getNextNaturalDate, reqVO.getNextNaturalDate())
                .betweenIfPresent(IotMainWorkOrderBomDO::getDelayNaturalDate, reqVO.getDelayNaturalDate())
                .eqIfPresent(IotMainWorkOrderBomDO::getDelayReason, reqVO.getDelayReason())
                .betweenIfPresent(IotMainWorkOrderBomDO::getLastMainDate, reqVO.getLastMainDate())
                .eqIfPresent(IotMainWorkOrderBomDO::getTimePeriod, reqVO.getTimePeriod())
                .eqIfPresent(IotMainWorkOrderBomDO::getTimePeriodLead, reqVO.getTimePeriodLead())
                .eqIfPresent(IotMainWorkOrderBomDO::getKilometerCycle, reqVO.getKilometerCycle())
                .eqIfPresent(IotMainWorkOrderBomDO::getKiloCycleLead, reqVO.getKiloCycleLead())
                .eqIfPresent(IotMainWorkOrderBomDO::getNaturalDatePeriod, reqVO.getNaturalDatePeriod())
                .eqIfPresent(IotMainWorkOrderBomDO::getNaturalDatePeriodLead, reqVO.getNaturalDatePeriodLead())
                .eqIfPresent(IotMainWorkOrderBomDO::getBomNodeId, reqVO.getBomNodeId())
                .likeIfPresent(IotMainWorkOrderBomDO::getName, reqVO.getName())
                .eqIfPresent(IotMainWorkOrderBomDO::getCode, reqVO.getCode())
                .eqIfPresent(IotMainWorkOrderBomDO::getParentId, reqVO.getParentId())
                .eqIfPresent(IotMainWorkOrderBomDO::getChildIds, reqVO.getChildIds())
                .eqIfPresent(IotMainWorkOrderBomDO::getLevel, reqVO.getLevel())
                .eqIfPresent(IotMainWorkOrderBomDO::getLeafFlag, reqVO.getLeafFlag())
                .eqIfPresent(IotMainWorkOrderBomDO::getSort, reqVO.getSort())
                .eqIfPresent(IotMainWorkOrderBomDO::getType, reqVO.getType())
                .eqIfPresent(IotMainWorkOrderBomDO::getMainType, reqVO.getMainType())
                .eqIfPresent(IotMainWorkOrderBomDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotMainWorkOrderBomDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotMainWorkOrderBomDO::getVersion, reqVO.getVersion())
                .betweenIfPresent(IotMainWorkOrderBomDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IotMainWorkOrderBomDO::getId));
    }

    default List<IotMainWorkOrderBomDO> selectList(IotMainWorkOrderBomPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<IotMainWorkOrderBomDO>()
                .eqIfPresent(IotMainWorkOrderBomDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(IotMainWorkOrderBomDO::getPlanDetailId, reqVO.getPlanDetailId())
                .eqIfPresent(IotMainWorkOrderBomDO::getWorkOrderId, reqVO.getWorkOrderId())
                .inIfPresent(IotMainWorkOrderBomDO::getWorkOrderId, reqVO.getWorkOrderIds())
                .eqIfPresent(IotMainWorkOrderBomDO::getDeviceCategoryId, reqVO.getDeviceCategoryId())
                .eqIfPresent(IotMainWorkOrderBomDO::getDeviceId, reqVO.getDeviceId())
                .inIfPresent(IotMainWorkOrderBomDO::getDeviceId, reqVO.getDeviceIds())
                .eqIfPresent(IotMainWorkOrderBomDO::getRule, reqVO.getRule())
                .eqIfPresent(IotMainWorkOrderBomDO::getMileageRule, reqVO.getMileageRule())
                .eqIfPresent(IotMainWorkOrderBomDO::getNaturalDateRule, reqVO.getNaturalDateRule())
                .eqIfPresent(IotMainWorkOrderBomDO::getRunningTimeRule, reqVO.getRunningTimeRule())
                .betweenIfPresent(IotMainWorkOrderBomDO::getLastRunningTime, reqVO.getLastRunningTime())
                .betweenIfPresent(IotMainWorkOrderBomDO::getNextRunningTime, reqVO.getNextRunningTime())
                .eqIfPresent(IotMainWorkOrderBomDO::getDelayDuration, reqVO.getDelayDuration())
                .eqIfPresent(IotMainWorkOrderBomDO::getLastRunningKilometers, reqVO.getLastRunningKilometers())
                .eqIfPresent(IotMainWorkOrderBomDO::getNextRunningKilometers, reqVO.getNextRunningKilometers())
                .eqIfPresent(IotMainWorkOrderBomDO::getDelayKilometers, reqVO.getDelayKilometers())
                .betweenIfPresent(IotMainWorkOrderBomDO::getLastNaturalDate, reqVO.getLastNaturalDate())
                .betweenIfPresent(IotMainWorkOrderBomDO::getNextNaturalDate, reqVO.getNextNaturalDate())
                .betweenIfPresent(IotMainWorkOrderBomDO::getDelayNaturalDate, reqVO.getDelayNaturalDate())
                .eqIfPresent(IotMainWorkOrderBomDO::getDelayReason, reqVO.getDelayReason())
                .betweenIfPresent(IotMainWorkOrderBomDO::getLastMainDate, reqVO.getLastMainDate())
                .eqIfPresent(IotMainWorkOrderBomDO::getTimePeriod, reqVO.getTimePeriod())
                .eqIfPresent(IotMainWorkOrderBomDO::getTimePeriodLead, reqVO.getTimePeriodLead())
                .eqIfPresent(IotMainWorkOrderBomDO::getKilometerCycle, reqVO.getKilometerCycle())
                .eqIfPresent(IotMainWorkOrderBomDO::getKiloCycleLead, reqVO.getKiloCycleLead())
                .eqIfPresent(IotMainWorkOrderBomDO::getNaturalDatePeriod, reqVO.getNaturalDatePeriod())
                .eqIfPresent(IotMainWorkOrderBomDO::getNaturalDatePeriodLead, reqVO.getNaturalDatePeriodLead())
                .eqIfPresent(IotMainWorkOrderBomDO::getBomNodeId, reqVO.getBomNodeId())
                .inIfPresent(IotMainWorkOrderBomDO::getBomNodeId, reqVO.getBomNodeIds())
                .likeIfPresent(IotMainWorkOrderBomDO::getName, reqVO.getName())
                .eqIfPresent(IotMainWorkOrderBomDO::getCode, reqVO.getCode())
                .eqIfPresent(IotMainWorkOrderBomDO::getParentId, reqVO.getParentId())
                .eqIfPresent(IotMainWorkOrderBomDO::getChildIds, reqVO.getChildIds())
                .eqIfPresent(IotMainWorkOrderBomDO::getLevel, reqVO.getLevel())
                .eqIfPresent(IotMainWorkOrderBomDO::getLeafFlag, reqVO.getLeafFlag())
                .eqIfPresent(IotMainWorkOrderBomDO::getSort, reqVO.getSort())
                .eqIfPresent(IotMainWorkOrderBomDO::getType, reqVO.getType())
                .eqIfPresent(IotMainWorkOrderBomDO::getMainType, reqVO.getMainType())
                .eqIfPresent(IotMainWorkOrderBomDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotMainWorkOrderBomDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotMainWorkOrderBomDO::getVersion, reqVO.getVersion())
                .betweenIfPresent(IotMainWorkOrderBomDO::getCreateTime, reqVO.getCreateTime()));
    }

    @DataPermission(enable = false)
    List<IotMainWorkOrderBomDO> historyWorkOrderBomS(@Param("deptIds") List<Long> deptIds, @Param("deviceIds") List<Long> deviceIds);

    @DataPermission(enable = false)
    List<IotMainWorkOrderBomDO> runningWorkOrderBomS(@Param("deptIds") List<Long> deptIds, @Param("deviceIds") List<Long> deviceIds);

    List<IotMainWorkOrderBomDO> latestWorkOrderBomS(@Param("req") IotMainWorkOrderBomPageReqVO reqVO);
}