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

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.mes.controller.admin.bom.vo.BomPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 产品BOM Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface BomMapper extends BaseMapperX<BomDO> {

    default PageResult<BomDO> selectPage(BomPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BomDO>()
                .eqIfPresent(BomDO::getCode, reqVO.getCode())
                .eqIfPresent(BomDO::getVersion, reqVO.getVersion())
                .eqIfPresent(BomDO::getProductId, reqVO.getProductId())
                .eqIfPresent(BomDO::getUnitId, reqVO.getUnitId())
                .eqIfPresent(BomDO::getYieldRate, reqVO.getYieldRate())
                .eqIfPresent(BomDO::getRemark, reqVO.getRemark())
                .eqIfPresent(BomDO::getIsEnable, reqVO.getIsEnable())
                .betweenIfPresent(BomDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BomDO::getId));
    }

    default PageResult<BomDO> selectBomExist(BomPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BomDO>()
                .eqIfPresent(BomDO::getCode, reqVO.getCode())
                .orderByDesc(BomDO::getId));
    }

    default BomDO selectByNo(String no) {
        return selectOne(BomDO::getCode, no);
    }

    default BomDO selectByProductId(Long productId) {
        return selectOne(BomDO::getProductId, productId,
                BomDO::getIsEnable, true);
    }
}