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

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

/**
 * 入仓项打包纪录 Mapper
 * @author yanghao
 */
@Mapper
public interface OrderItemPackLogMapper extends AbstractMapper<OrderItemPackLogDO> {
    @Override
    default PageResult<OrderItemPackLogDO> selectPage(PageVO page, Object object) {
        if (object instanceof OrderItemPackLogQueryVO) {
            OrderItemPackLogQueryVO vo = (OrderItemPackLogQueryVO)object;
            return selectPage(page, new LambdaQuery<OrderItemPackLogDO>()
                .eqIfPresent(OrderItemPackLogDO::getOrderId, vo.getOrderId())
                .eqIfPresent(OrderItemPackLogDO::getOrderItemId, vo.getOrderItemId())
                .eqIfPresent(OrderItemPackLogDO::getOrderWarehouseInContent, vo.getOrderWarehouseInContent())
                .likeIfPresent(OrderItemPackLogDO::getCreatorName, vo.getCreatorName())
                .betweenIfPresent(OrderItemPackLogDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .orderByDesc(OrderItemPackLogDO::getId));
        }

        return null;
    }

    @Override
    default List<OrderItemPackLogDO> selectList(Object object) {
        if (object instanceof OrderItemPackLogQueryVO) {
            OrderItemPackLogQueryVO vo = (OrderItemPackLogQueryVO)object;
            return selectList(new LambdaQuery<OrderItemPackLogDO>()
                .eqIfPresent(OrderItemPackLogDO::getOrderId, vo.getOrderId())
                .eqIfPresent(OrderItemPackLogDO::getOrderItemId, vo.getOrderItemId())
                .eqIfPresent(OrderItemPackLogDO::getOrderWarehouseInContent, vo.getOrderWarehouseInContent())
                .likeIfPresent(OrderItemPackLogDO::getCreatorName, vo.getCreatorName())
                .betweenIfPresent(OrderItemPackLogDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .orderByDesc(OrderItemPackLogDO::getId));
        }

        return null;
    }


    @Select("select * from ecw_order_item_pack_log where id in (select min(id) as id from ecw_order_item_pack_log t where t.order_id = #{orderId} and t.deleted = 0 group by order_id, order_Item_id)")
    List<OrderItemPackLogDO> getOriginalPackLogList(@Param("orderId") Long orderId);
}
