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

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.orderTime.OrderTimeDO;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.order.vo.orderTime.*;
import org.apache.ibatis.annotations.Param;

/**
 * 下单时间轴事件 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface OrderTimeMapper extends AbstractMapper<OrderTimeDO> {
    @Override
    default PageResult<OrderTimeDO> selectPage(PageVO page, Object object) {
        if (object instanceof OrderTimeQueryVO) {
            OrderTimeQueryVO vo = (OrderTimeQueryVO) object;
            return selectPage(page, new LambdaQuery<OrderTimeDO>()
                    .eqIfPresent(OrderTimeDO::getOrderId, vo.getOrderId())
                    .eqIfPresent(OrderTimeDO::getTitleZh, vo.getTitleZh())
                    .eqIfPresent(OrderTimeDO::getTitleEn, vo.getTitleEn())
                    .eqIfPresent(OrderTimeDO::getType, vo.getType())
                    .betweenIfPresent(OrderTimeDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .orderByDesc(OrderTimeDO::getId));
        }

        return null;
    }

    @Override
    default List<OrderTimeDO> selectList(Object object) {
        if (object instanceof OrderTimeQueryVO) {
            OrderTimeQueryVO vo = (OrderTimeQueryVO) object;
            return selectList(new LambdaQuery<OrderTimeDO>()
                    .eqIfPresent(OrderTimeDO::getOrderId, vo.getOrderId())
                    .eqIfPresent(OrderTimeDO::getTitleZh, vo.getTitleZh())
                    .eqIfPresent(OrderTimeDO::getTitleEn, vo.getTitleEn())
                    .eqIfPresent(OrderTimeDO::getType, vo.getType())
                    .betweenIfPresent(OrderTimeDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .orderByDesc(OrderTimeDO::getId));
        }

        return null;
    }

    /**
     * 根据自编号获取指定类型最新的一条数据
     *
     * @param containerNumber 自编号
     * @param status 值
     * @return
     */
    List<OrderTimeDO> newOrderTimeByContainerNumberAndStatus(@Param("containerNumber") String containerNumber, @Param("status") Integer status);
    List<OrderTimeDO> newOrderTimeByOrderIdAndStatus(@Param("orderId") Long orderId, @Param("status") Integer status);
}
