package cn.iocoder.yudao.module.product.dal.mysql.harvestbatch;

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.product.controller.admin.harvestbatch.vo.GoodsHarvestBatchIdsRespVO;
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.harvestbatch.vo.HarvestBatchRespVO;
import cn.iocoder.yudao.module.product.dal.dataobject.harvestbatch.HarvestBatchDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 采收批次 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface HarvestBatchMapper extends BaseMapperX<HarvestBatchDO> {

    default PageResult<HarvestBatchDO> selectPage(HarvestBatchPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<HarvestBatchDO>()
                .eqIfPresent(HarvestBatchDO::getHarvestBatchId, reqVO.getHarvestBatchId())
                .eqIfPresent(HarvestBatchDO::getHarvestId, reqVO.getHarvestId())
                .betweenIfPresent(HarvestBatchDO::getHarvestDate, reqVO.getHarvestDate())
                .likeIfPresent(HarvestBatchDO::getGoodsName, reqVO.getGoodsName())
                .likeIfPresent(HarvestBatchDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                // .ne(HarvestBatchDO::getBlockState, BlockStateEnum.NOT_ON_CHAIN.getBlockState())
                .orderByDesc(HarvestBatchDO::getId));
    }

    /**
     * 该方法会对批次进行分组
     */
    HarvestBatchRespVO getHarvestBatchDetail(@Param("id") Long id, @Param("harvestBatchId") String harvestBatchId, @Param("languageTypeId") Long languageTypeId);

    List<GoodsHarvestBatchIdsRespVO> getBatchIdsByGoodsId(@Param("goodsIds") List<String> goodsIds, @Param("businessId") Long businessId, @Param("blockState") Integer blockState);
}
