package cn.iocoder.yudao.module.mes.dal.mysql.machine;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.controller.admin.machine.vo.MachineComponentListReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.machine.MachineComponentDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 机台 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface MachineComponentMapper extends BaseMapperX<MachineComponentDO> {

    default List<MachineComponentDO> selectList(MachineComponentListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MachineComponentDO>()
                .likeIfPresent(MachineComponentDO::getName, reqVO.getName())
                .eqIfPresent(MachineComponentDO::getParentId, reqVO.getParentId())
                .eqIfPresent(MachineComponentDO::getSort, reqVO.getSort())
                .eqIfPresent(MachineComponentDO::getOrgId, reqVO.getOrgId())
                .eqIfPresent(MachineComponentDO::getSerialCode, reqVO.getSerialCode())
                .betweenIfPresent(MachineComponentDO::getOutgoingTime, reqVO.getOutgoingTime())
                .eqIfPresent(MachineComponentDO::getOutgoingReport, reqVO.getOutgoingReport())
                .eqIfPresent(MachineComponentDO::getPosition, reqVO.getPosition())
                .eqIfPresent(MachineComponentDO::getStandard, reqVO.getStandard())
                .eqIfPresent(MachineComponentDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(MachineComponentDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(MachineComponentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MachineComponentDO::getComponentType, reqVO.getComponentType())
                .inIfPresent(MachineComponentDO::getComponentType, reqVO.getComponentTypes())
                .eqIfPresent(MachineComponentDO::getMachineType, reqVO.getMachineType())
                .betweenIfPresent(MachineComponentDO::getMaintainTime, reqVO.getMaintainTime())
                .eqIfPresent(MachineComponentDO::getMaintainType, reqVO.getMaintainType())
                .eqIfPresent(MachineComponentDO::getMaintainTimeUnit, reqVO.getMaintainTimeUnit())
                .betweenIfPresent(MachineComponentDO::getTrueMaintainTime, reqVO.getTrueMaintainTime())
                .eqIfPresent(MachineComponentDO::getTrueMaintainTimeUnit, reqVO.getTrueMaintainTimeUnit())
                .eqIfPresent(MachineComponentDO::getTrueMaintainTimeType, reqVO.getTrueMaintainTimeType())
                .betweenIfPresent(MachineComponentDO::getLastMaitainTime, reqVO.getLastMaitainTime())
                .eqIfPresent(MachineComponentDO::getMoldId, reqVO.getMoldId())
                .orderByDesc(MachineComponentDO::getSort)
                .orderByDesc(MachineComponentDO::getId));
    }

    default MachineComponentDO selectByParentIdAndName(Long parentId, String name) {
        return selectOne(MachineComponentDO::getParentId, parentId, MachineComponentDO::getName, name);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(MachineComponentDO::getParentId, parentId);
    }
    default MachineComponentDO selectByNo(String no) {
        return selectOne(MachineComponentDO::getCode, no);
    }
}