package cn.iocoder.yudao.module.identity.dal.mysql.diversionrecord;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.identity.dal.dataobject.diversionrecord.DiversionRecordDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.identity.controller.admin.diversionrecord.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 疑似窜货记录 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface DiversionRecordMapper extends BaseMapperX<DiversionRecordDO> {

    default PageResult<DiversionRecordDO> selectPage(DiversionRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DiversionRecordDO>()
                .eqIfPresent(DiversionRecordDO::getDealerId, reqVO.getDealerId())
                .likeIfPresent(DiversionRecordDO::getDealerName, reqVO.getDealerName())
                .eqIfPresent(DiversionRecordDO::getBatchId, reqVO.getBatchId())
                .eqIfPresent(DiversionRecordDO::getGoodsId, reqVO.getGoodsId())
                .likeIfPresent(DiversionRecordDO::getGoodsName, reqVO.getGoodsName())
                .eqIfPresent(DiversionRecordDO::getScanLocation, reqVO.getScanLocation())
                .betweenIfPresent(DiversionRecordDO::getScanTime, reqVO.getScanTime())
                .eqIfPresent(DiversionRecordDO::getDiversionState, reqVO.getDiversionState())
                .eqIfPresent(DiversionRecordDO::getDiversionLevel, reqVO.getDiversionLevel())
                .eqIfPresent(DiversionRecordDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DiversionRecordDO::getRemarks, reqVO.getRemarks())
                .eqIfPresent(DiversionRecordDO::getBelongBusinessId, reqVO.getBelongBusinessId())
                .likeIfPresent(DiversionRecordDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                .betweenIfPresent(DiversionRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DiversionRecordDO::getId));
    }

    default List<DiversionRecordDO> selectList(DiversionRecordExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DiversionRecordDO>()
                .eqIfPresent(DiversionRecordDO::getDealerId, reqVO.getDealerId())
                .likeIfPresent(DiversionRecordDO::getDealerName, reqVO.getDealerName())
                .eqIfPresent(DiversionRecordDO::getBatchId, reqVO.getBatchId())
                .eqIfPresent(DiversionRecordDO::getGoodsId, reqVO.getGoodsId())
                .likeIfPresent(DiversionRecordDO::getGoodsName, reqVO.getGoodsName())
                .eqIfPresent(DiversionRecordDO::getScanLocation, reqVO.getScanLocation())
                .betweenIfPresent(DiversionRecordDO::getScanTime, reqVO.getScanTime())
                .eqIfPresent(DiversionRecordDO::getDiversionState, reqVO.getDiversionState())
                .eqIfPresent(DiversionRecordDO::getDiversionLevel, reqVO.getDiversionLevel())
                .eqIfPresent(DiversionRecordDO::getStatus, reqVO.getStatus())
                .eqIfPresent(DiversionRecordDO::getRemarks, reqVO.getRemarks())
                .eqIfPresent(DiversionRecordDO::getBelongBusinessId, reqVO.getBelongBusinessId())
                .likeIfPresent(DiversionRecordDO::getBelongBusinessName, reqVO.getBelongBusinessName())
                .betweenIfPresent(DiversionRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DiversionRecordDO::getId));
    }

    List<DiversionRecordDO> selectByGoodsId(@Param("goodsId") String goodsId);

    List<DiversionRecordDO> selectByGoodsIdAndBatchIdAndScanLocation(@Param("goodsId") String goodsId,
                                                                     @Param("batchId") String batchId,
                                                                     @Param("scanLocation") String scanLocation);
}
