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

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

/**
 * 入仓单审核 Mapper
 * @author yanghao
 */
@Mapper
public interface OrderWarehouseApprovalMapper extends AbstractMapper<OrderWarehouseApprovalDO> {
    @Override
    default PageResult<OrderWarehouseApprovalDO> selectPage(PageVO page, Object object) {
        if (object instanceof OrderWarehouseApprovalQueryVO) {
            OrderWarehouseApprovalQueryVO vo = (OrderWarehouseApprovalQueryVO)object;
            return selectPage(page, new LambdaQuery<OrderWarehouseApprovalDO>()
                .eqIfPresent(OrderWarehouseApprovalDO::getOrderIds, vo.getOrderId())
                .eqIfPresent(OrderWarehouseApprovalDO::getOrderNo, vo.getOrderNo())
                .eqIfPresent(OrderWarehouseApprovalDO::getOrderItemId, vo.getOrderItemId())
                .eqIfPresent(OrderWarehouseApprovalDO::getWarehouseInId, vo.getWarehouseInId())
                .eqIfPresent(OrderWarehouseApprovalDO::getFormId, vo.getFormId())
                .eqIfPresent(OrderWarehouseApprovalDO::getType, vo.getType())
                .eqIfPresent(OrderWarehouseApprovalDO::getFollowUpAdminId, vo.getFollowUpAdminId())
                .eqIfPresent(OrderWarehouseApprovalDO::getStatus, vo.getStatus())
                .eqIfPresent(OrderWarehouseApprovalDO::getProcessingResults, vo.getProcessingResults())
                .eqIfPresent(OrderWarehouseApprovalDO::getFinishBy, vo.getFinishBy())
                .eqIfPresent(OrderWarehouseApprovalDO::getIsBatch, vo.getIsBatch())
                .eqIfPresent(OrderWarehouseApprovalDO::getIsFromUserClient, vo.getIsFromUserClient())
                .betweenIfPresent(OrderWarehouseApprovalDO::getFinishTime, vo.getBeginFinishTime(), vo.getEndFinishTime())
                .betweenIfPresent(OrderWarehouseApprovalDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .orderByDesc(OrderWarehouseApprovalDO::getId));
        }

        return null;
    }

    @Override
    default List<OrderWarehouseApprovalDO> selectList(Object object) {
        if (object instanceof OrderWarehouseApprovalQueryVO) {
            OrderWarehouseApprovalQueryVO vo = (OrderWarehouseApprovalQueryVO)object;
            return selectList(new LambdaQuery<OrderWarehouseApprovalDO>()
                .eqIfPresent(OrderWarehouseApprovalDO::getOrderIds, vo.getOrderId())
                .eqIfPresent(OrderWarehouseApprovalDO::getOrderNo, vo.getOrderNo())
                .eqIfPresent(OrderWarehouseApprovalDO::getOrderItemId, vo.getOrderItemId())
                .eqIfPresent(OrderWarehouseApprovalDO::getWarehouseInId, vo.getWarehouseInId())
                .eqIfPresent(OrderWarehouseApprovalDO::getFormId, vo.getFormId())
                .eqIfPresent(OrderWarehouseApprovalDO::getType, vo.getType())
                .eqIfPresent(OrderWarehouseApprovalDO::getFollowUpAdminId, vo.getFollowUpAdminId())
                .eqIfPresent(OrderWarehouseApprovalDO::getStatus, vo.getStatus())
                .eqIfPresent(OrderWarehouseApprovalDO::getProcessingResults, vo.getProcessingResults())
                .eqIfPresent(OrderWarehouseApprovalDO::getFinishBy, vo.getFinishBy())
                .eqIfPresent(OrderWarehouseApprovalDO::getIsBatch, vo.getIsBatch())
                .eqIfPresent(OrderWarehouseApprovalDO::getIsFromUserClient, vo.getIsFromUserClient())
                .betweenIfPresent(OrderWarehouseApprovalDO::getFinishTime, vo.getBeginFinishTime(), vo.getEndFinishTime())
                .betweenIfPresent(OrderWarehouseApprovalDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .orderByDesc(OrderWarehouseApprovalDO::getId));
        }

        return null;
    }

    @Select("select * from ecw_order_warehouse_approval where deleted = 0 and type = #{type} and order_ids = #{orderId} order by id desc limit 1")
    OrderWarehouseApprovalDO selectOne(@Param("type") Integer type, @Param("orderId") Long orderId);
}
