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

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.pms.controller.admin.iotmaintenancebom.vo.IotTobeMaintenanceBomRespVO;
import cn.iocoder.yudao.module.pms.controller.admin.maintenance.vo.IotMaintenancePlanPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.maintenance.IotMaintenancePlanDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 保养计划 Mapper
 *
 * @author ruiqi
 */
@Mapper
public interface IotMaintenancePlanMapper extends BaseMapperX<IotMaintenancePlanDO> {

    default PageResult<IotMaintenancePlanDO> selectPage(IotMaintenancePlanPageReqVO reqVO,
                                                        Collection<Long> ids, Collection<Long> planIds) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotMaintenancePlanDO>()
                .eqIfPresent(IotMaintenancePlanDO::getSerialNumber, reqVO.getSerialNumber())
                // .likeIfPresent(IotMaintenancePlanDO::getName, reqVO.getName())
                .eqIfPresent(IotMaintenancePlanDO::getResponsiblePerson, reqVO.getResponsiblePerson())
                .likeIfPresent(IotMaintenancePlanDO::getResponsiblePersonName, reqVO.getResponsiblePersonName())
                .eqIfPresent(IotMaintenancePlanDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotMaintenancePlanDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(IotMaintenancePlanDO::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(IotMaintenancePlanDO::getDeptId, ids)
                .inIfPresent(IotMaintenancePlanDO::getId, planIds)
                .orderByDesc(IotMaintenancePlanDO::getId));
    }

    default List<IotMaintenancePlanDO> selectList(IotMaintenancePlanPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<IotMaintenancePlanDO>()
                .eqIfPresent(IotMaintenancePlanDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(IotMaintenancePlanDO::getSerialNumber, reqVO.getSerialNumber())
                .likeIfPresent(IotMaintenancePlanDO::getName, reqVO.getName())
                .eqIfPresent(IotMaintenancePlanDO::getResponsiblePerson, reqVO.getResponsiblePerson())
                .likeIfPresent(IotMaintenancePlanDO::getResponsiblePersonName, reqVO.getResponsiblePersonName())
                .eqIfPresent(IotMaintenancePlanDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotMaintenancePlanDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(IotMaintenancePlanDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IotMaintenancePlanDO::getId));
    }

    default IotMaintenancePlanDO selectByNo(String no) {
        return selectOne(IotMaintenancePlanDO::getSerialNumber, no);
    }

    List<IotTobeMaintenanceBomRespVO> toBeMaintenanceDeviceBOMs();
}
