package com.sckw.transport.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sckw.mongo.model.TableTops;
import com.sckw.transport.model.KwtWaybillOrder;
import com.sckw.transport.model.dto.OrderCarDTO;
import com.sckw.transport.model.dto.WayBillDetailDTO;
import com.sckw.transport.model.vo.WaybillCountVo;
import com.sckw.transport.model.vo.WaybillOrderDriverVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

@Mapper
public interface KwtWaybillOrderMapper extends BaseMapper<KwtWaybillOrder> {
    int deleteByPrimaryKey(Long id);

    int insert(KwtWaybillOrder record);

    int insertSelective(KwtWaybillOrder record);

    KwtWaybillOrder selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(KwtWaybillOrder record);

    int updateByPrimaryKey(KwtWaybillOrder record);

    List<OrderCarDTO> selectWaybillOrderCarList(@Param("id") String id, @Param("page") int page, @Param("pageSize") int pageSize);

    List<OrderCarDTO> selectWaybillOrderCarListGroupByTruckNo(@Param("ids") List<String> ids, @Param("page") int page, @Param("pageSize") int pageSize);

    Long selectWaybillOrderCarCount(@Param("id") String id);

    /**
     * 根据司机id+定义状态统计
     *
     * @param id
     * @param status
     * @return
     */
    TableTops statistics(@Param("id") Long id, @Param("status") List<Long> status);

    /**
     * 根据司机id+运单状态获取物流订单id
     *
     * @param id
     * @param status
     * @return
     */
    List<Long> selectDriverOrder(@Param("id") Long id, @Param("status") List<Long> status);

    /**
     * 根基运单ID查询关联数据
     *
     * @param id
     * @return
     */
    WayBillDetailDTO selectWaybillRelate(@Param("id") Long id);

    /**
     * 通过物流订单id+车辆运单状态查询是否存在处理中的数据
     *
     * @param id
     * @param statusList
     * @return
     */
    int selectDataByLorderId(@Param("id") String id, @Param("statusList") List<Integer> statusList);

    /**
     * @param params {lOrderId 物流订单id, upperlOrderId 下级分包物流订单,belowlOrderId 所属上级分包, loadCountStatus 有效装货状态, unloadCountStatus 有效卸货状态}
     * @desc 统计车辆运单
     * @author zk
     * @date 2023/7/31
     **/
    WaybillCountVo findWaybillOrderCount(Map params);

    /**
     * @param driverId 司机ID
     * @desc 统计司机任务数(待接单/出车/执行/完结)
     * @author zk
     * @date 2023/8/1
     **/
    Map<String, Object> findStatisticsCountByDriver(@Param("driverId") Long driverId);

    /**
     * @param params {driverId 司机ID, month月份}
     * @desc 统计司机任务数（任务数/委派量/装货量/卸货量/亏吨量/亏吨扣款）
     * @author zk
     * @date 2023/8/1
     **/
    Map<String, Object> findStatisticsSumByDriver(Map params);

    /**
     * @param params {driverId 司机ID}
     * @desc 查询司机任务列表-待接单
     * @author zk
     * @date 2023/8/1
     **/
    List<WaybillOrderDriverVo> findWaitWaybillOrderByDriver(Map params);

    /**
     * @param params {driverId 司机ID, busStatus 状态 2出车/3执行/4完结, month月份}
     * @desc 查询司机任务列表-出车/执行/完结
     * @author zk
     * @date 2023/8/1
     **/
    List<WaybillOrderDriverVo> findOtherWaybillOrderByDriver(Map params);

    /**
     *
     * @param id
     * @return
     */
    List<OrderCarDTO> selectWaybillOrderCarListNotPage(@Param("id") String id);
}