package com.yc.ship.module.trade.dal.mysql.orderjzdispatch;

import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.trade.controller.admin.orderjzdetail.vo.OrderJzDispatchRecordRespVO;
import com.yc.ship.module.trade.controller.admin.orderjzdetail.vo.OrderJzDispatchPageReqVO;
import com.yc.ship.module.trade.dal.dataobject.orderjzdispatch.OrderJzDispatchDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 订单分车 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface OrderJzDispatchMapper extends BaseMapperX<OrderJzDispatchDO> {

  default PageResult<OrderJzDispatchDO> selectPage(OrderJzDispatchPageReqVO pageReqVO) {
    return selectPage(pageReqVO, new LambdaQueryWrapperX<OrderJzDispatchDO>()
      .eqIfPresent(OrderJzDispatchDO::getVoyageId, pageReqVO.getVoyageId())
      .likeIfPresent(OrderJzDispatchDO::getDispatchNo, pageReqVO.getDispatchNo())
      .likeIfPresent(OrderJzDispatchDO::getBusNumber, pageReqVO.getBusNumber())
      .likeIfPresent(OrderJzDispatchDO::getDriverName, pageReqVO.getDriverName())
      .eqIfPresent(OrderJzDispatchDO::getSourceType, pageReqVO.getSourceType())
      .betweenIfPresent(OrderJzDispatchDO::getDispatchTime, pageReqVO.getDispatchTime())
      .betweenIfPresent(OrderJzDispatchDO::getCreateTime, pageReqVO.getCreateTime())
      .orderByDesc(OrderJzDispatchDO::getDispatchTime));
  }

    /**
     * 物理删除分车记录
     * @param id 记录ID
     * @return 影响行数
     */
    @Delete("DELETE FROM trade_order_jz_dispatch WHERE id = #{id}")
    int physicalDeleteById(@Param("id") Long id);

    /**
     * 分页查询分车记录（按分车号分组）
     */
    List<OrderJzDispatchRecordRespVO> selectDispatchRecordPage(
            @Param("reqVO") OrderJzDispatchPageReqVO reqVO,
            @Param("offset") int offset,
            @Param("limit") int limit);

    /**
     * 查询分车记录总数（按分车号分组）
     */
    Long selectDispatchRecordCount(@Param("reqVO") OrderJzDispatchPageReqVO reqVO);

}
