package com.sckw.transport.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sckw.transport.api.model.dto.AddressResDTO;
import com.sckw.transport.api.model.dto.LogisticsOrderDTO;
import com.sckw.transport.api.model.vo.LogisticsOrderVO;
import com.sckw.transport.model.KwtLogisticsOrder;
import com.sckw.transport.model.param.DriverParam;
import com.sckw.transport.model.param.LogisticsOrderParam;
import com.sckw.transport.model.vo.DriverListVo;
import com.sckw.transport.model.vo.OrderFinishVO;
import com.sckw.transport.model.vo.SubcontractConsignmentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface KwtLogisticsOrderMapper extends BaseMapper<KwtLogisticsOrder> {

    int insert(KwtLogisticsOrder record);


    /**
     * 查询物流订单数据
     *
     * @param logisticsOrderParam 查询参数
     * @param dictId              字典id
     * @return
     */
    List<LogisticsOrderDTO> selectLogisticOrderData(@Param("logisticsOrderParam") LogisticsOrderParam logisticsOrderParam, @Param("dictId") Long dictId);


    /**
     * 销售订单-采购订单-托运详情
     * @param id
     * @param page
     * @param pageSize
     * @param type
     * @return
     */
    List<com.sckw.transport.model.dto.LogisticsOrderDTO> selectOrderList(@Param("id") String id, @Param("page") int page,
                                                                         @Param("pageSize") int pageSize,@Param("type") String type);

    /**
     * 销售订单-采购订单-托运详情
     *
     * @param id
     * @param type
     * @return
     */
    List<com.sckw.transport.model.dto.LogisticsOrderDTO> selectOrderListNotPage(@Param("id") String id, @Param("type") String type);

    /**
     * 销售订单-采购订单-托运列表-数据统计
     *
     * @param id
     * @return
     */
    List<com.sckw.transport.model.dto.LogisticsOrderDTO> selectOrderCountByTorderId(@Param("id") String id, @Param("type") String type);

    /**
     * @param id   贸易订单id
     * @param type 采购单1/销售单2
     * @return
     */
    Long selectOrderCount(@Param("id") String id, @Param("type") String type);

    /**
     * @param logisticsOrderParam
     * @param dictId
     * @return
     */
    Long selectLogisticOrderCount(@Param("logisticsOrderParam") LogisticsOrderParam logisticsOrderParam, @Param("dictId") Long dictId);

    Map<String, String> getRejectReason(@Param("id") String id, @Param("status") String status);

    /**
     * 根据承运订单id查看分包数据列表
     *
     * @param lOrderId
     * @param page
     * @param pageSize
     * @return
     */
    List<SubcontractConsignmentVO> getSubcontractConsignment(@Param("lOrderId") String lOrderId, @Param("page") Integer page, @Param("pageSize") Integer pageSize);

    /**
     *
     * @param lOrderId
     * @return
     */
    List<SubcontractConsignmentVO> getSubcontractConsignmentNotPage(@Param("lOrderId") String lOrderId);

    /**
     *
     * @param lOrderId
     * @return
     */
    List<Map> countSubcontractConsignmentById(@Param("lOrderId") String lOrderId);

    /**
     * 通过物流订单查看单据下运力司机数据
     *
     * @param driverParam
     * @return
     */
    List<DriverListVo> selectDriverListById(@Param("driverParam") DriverParam driverParam);

    /**
     * @param ids
     * @return
     */
    List<LogisticsOrderVO> selectLogisticOrderList(@Param("ids") List<String> ids);

    /**
     * 通过物流订单id获取统计数据
     *
     * @param orderId
     * @return
     */
    OrderFinishVO selectOrderFinishData(@Param("orderId") String orderId);

    /**
     * @param params {ownOrderId 物流订单id, upperlOrderId 下级分包物流订单,belowlOrderId 所属上级分包}
     * @desc 查询分包物流订单
     * @author zk
     * @date 2023/7/20
     **/
    List<KwtLogisticsOrder> findLogisticsOrder(Map params);

    /**
     *
     * @param entId
     * @return
     */
    List<Integer> getAddressList(@Param("entId") Long entId);

    /**
     *
     * @param entId
     * @return
     */
    List<AddressResDTO> getAddressDetailListByEntId(@Param("entId") Long entId);

    /**
     *
     * @param id
     * @return
     */
    int selectMaxLevel(@Param("id") String id);

    /**
     * 根据贸易订单id统计委派量-实际装货量-实际卸货量
     * @param tOrderId
     * @return
     */
    Map<String, BigDecimal> countAmountByTradeOrderId(@Param("tOrderId") Long tOrderId);
}