package cn.iocoder.yudao.module.order.dal.mysql.merge;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper;
import cn.iocoder.yudao.module.order.dal.dataobject.merge.MergeDO;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.order.vo.merge.*;
import org.apache.ibatis.annotations.Param;

/**
 * 订单合单申请 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface MergeMapper extends AbstractMapper<MergeDO> {
    @Override
    default PageResult<MergeDO> selectPage(PageVO page, Object object) {
        if (object instanceof MergeQueryVO) {
            MergeQueryVO vo = (MergeQueryVO) object;
            return selectPage(page, new LambdaQuery<MergeDO>()
                    .betweenIfPresent(MergeDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .eqIfPresent(MergeDO::getApplyOrderNo, vo.getApplyOrderNo())
                    .eqIfPresent(MergeDO::getOrderNos, vo.getOrderNos())
                    .eqIfPresent(MergeDO::getMergedOrderNo, vo.getMergedOrderNo())
                    .betweenIfPresent(MergeDO::getAddTime, vo.getBeginAddTime(), vo.getEndAddTime())
                    .eqIfPresent(MergeDO::getRemarks, vo.getRemarks())
                    .eqIfPresent(MergeDO::getReason, vo.getReason())
                    .eqIfPresent(MergeDO::getStatus, vo.getStatus())
                    .eqIfPresent(MergeDO::getBpmProcessId, vo.getBpmProcessId())
                    .orderByDesc(MergeDO::getId));
        }

        return null;
    }

    @Override
    default List<MergeDO> selectList(Object object) {
        if (object instanceof MergeQueryVO) {
            MergeQueryVO vo = (MergeQueryVO) object;
            return selectList(new LambdaQuery<MergeDO>()
                    .betweenIfPresent(MergeDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .eqIfPresent(MergeDO::getApplyOrderNo, vo.getApplyOrderNo())
                    .eqIfPresent(MergeDO::getOrderNos, vo.getOrderNos())
                    .eqIfPresent(MergeDO::getMergedOrderNo, vo.getMergedOrderNo())
                    .betweenIfPresent(MergeDO::getAddTime, vo.getBeginAddTime(), vo.getEndAddTime())
                    .eqIfPresent(MergeDO::getRemarks, vo.getRemarks())
                    .eqIfPresent(MergeDO::getReason, vo.getReason())
                    .eqIfPresent(MergeDO::getStatus, vo.getStatus())
                    .eqIfPresent(MergeDO::getBpmProcessId, vo.getBpmProcessId())
                    .orderByDesc(MergeDO::getId));
        }

        return null;
    }

    IPage<OrderDO> getUnMergedOrder(@Param("mpPage") IPage<OrderDO> mpPage, @Param("orderDO") OrderDO orderDO);
}
