package com.ruoyi.logistics.service;

import java.io.UnsupportedEncodingException;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.logistics.domain.BizWaybillCostDetails;
import com.ruoyi.logistics.domain.BizWaybillOrder;
import com.ruoyi.logistics.domain.dto.OrderStatisticsDto;
import com.ruoyi.logistics.domain.dto.DailyOrderStatisticsDto;
import com.ruoyi.logistics.domain.dto.JDOrderDTO;
import com.ruoyi.logistics.domain.dto.SfOrderImportDTO;

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

/**
 * 运单管理Service接口
 * 
 * @author RuiJing
 * @date 2026-01-29
 */
public interface IBizWaybillOrderService 
{
    /**
     * 查询运单管理
     * 
     * @param waybillId 运单管理主键
     * @return 运单管理
     */
    public BizWaybillOrder selectBizWaybillOrderByWaybillId(Long waybillId);

    /**
     * 查询运单管理列表
     * 
     * @param bizWaybillOrder 运单管理
     * @return 运单管理集合
     */
    public List<BizWaybillOrder> selectBizWaybillOrderList(BizWaybillOrder bizWaybillOrder);

    /**
     * 新增运单管理
     * 
     * @param bizWaybillOrder 运单管理
     * @return 结果
     */
    public int insertBizWaybillOrder(BizWaybillOrder bizWaybillOrder) throws UnsupportedEncodingException, JsonProcessingException;

    /**
     * 修改运单管理
     * 
     * @param bizWaybillOrder 运单管理
     * @return 结果
     */
    public int updateBizWaybillOrder(BizWaybillOrder bizWaybillOrder) ;

    /**
     * 批量删除运单管理
     * 
     * @param waybillIds 需要删除的运单管理主键集合
     * @return 结果
     */
    public int deleteBizWaybillOrderByWaybillIds(Long[] waybillIds);

    /**
     * 删除运单管理信息
     * 
     * @param waybillId 运单管理主键
     * @return 结果
     */
    public int deleteBizWaybillOrderByWaybillId(Long waybillId);

    /**
     * 根据订单信息查询运单详情
     * @param query
     * @return
     */
    public BizWaybillOrder selectBizWaybillOrderByQuery(BizWaybillOrder query);

    void updateBizWaybillOrderState(BizWaybillOrder bizWaybillOrder);

    int canceleBizWaybillOrder(BizWaybillOrder bizWaybillOrder) throws UnsupportedEncodingException;

    /**
     * 获取订单数量汇总
     *
     * @return 订单统计结果
     */
    OrderStatisticsDto getTotalOrdersByOrderType(BizWaybillOrder bizWaybillOrder, BizWaybillCostDetails bizWaybillCostDetails);

    /**
     * 获取近七日每日订单统计
     *
     * @return 近七日每日订单统计列表
     */
    List<DailyOrderStatisticsDto> getLast7DaysOrderStatistics(BizWaybillOrder bizWaybillOrder);

    JSONObject queryOrderFeeInfo(Integer orderType, String waybillCode);

    JSONObject queryWaybillPdf(BizWaybillOrder bizWaybillOrder);

    /**
     * 批量下单
     * 
     * @param orderList 订单列表
     * @param orderType 订单类型 1-京东，2-顺丰
     * @return 结果数组，每个元素表示对应订单的结果 [0:成功数，1:失败数]
     */
    public int batchInsertJDBizWaybillOrder(List<JDOrderDTO> orderList, Integer orderType);

    void asyncBatchInsert(List<BizWaybillOrder> orderList, Integer orderType);

    Map<String,Object> validateAndGetError(List<SfOrderImportDTO> orderList);

    Map<String, Object> validateAndGetErrorJd(List<JDOrderDTO> orderList);

    void asyncBatchInsertJd(List<BizWaybillOrder> orderList, Integer orderType);
}
