package com.sunda.spmswms.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmswms.entity.ShelfOnTask;
import com.sunda.spmswms.entity.ShelfOnTaskDtl;
import com.sunda.spmswms.entity.WhsOut;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 出库任务表 服务类
 * </p>
 *
 * @author Wayne
 * @since 2021-04-23
 */
public interface IWhsOutService extends IService<WhsOut> {

    /**极据Uuid获取出库任务*/
    WhsOut getWhsOutByUuid(String uuid);

    /** 根据 装箱单号、工厂、仓库地点代码/可装柜地点代码、货物类型、可装柜日期、柜序号 查询出库任务是否存在 */
    WhsOut getWhsOut(String werks,
                     String whsLocationCode,
                     String packageList,
                     String goodsType,
                     String dateOfLoading,
                     String cabinetSerialNumber);
    /** 装箱单任务拆分——新建一个出库任务 */
    int insertWhsOut(WhsOut whsOut);

    /** 用户获取出库任务列表 */
    IPage<WhsOut> getWhsOutList(JSONObject doc);

    /** 用户获取出库任务列表，带上下架任务单号 */
    Page<Map<String, Object>> getWhsOutListPage(JSONObject doc);

    /** 根据出库任务表头获取出库任务明细信息，贸易货按物料出，备件货按箱码出 */
    List<Map<String, Object>> getWhsOutDtl(String goodsType, String uuid);

    /** 根据出库任务表头获取出库任务明细,下架任务明细信息，备件货按箱码出 */
    ResponseResult getWhsOutDtlX(String uuid);

    /** 根据备件货出库任务明细中的箱码，获取箱码中 物料明细信息 */
    List<Map<String, Object>> getBoxNoteDtl(String boxNote);

    /** 仅备件货根据出库任务uuid生成下架任务表头、下架任务明细；备件按箱下架。*/
    int initShelfOnTask(String userId, String createDate, String uuid);

    /** 备件货出库任务完成————更新下架任务明细、更新下架任务表头状态为 2已完成、计算储位库存、更新出库任务明细、更新出库任务表头、计算仓库库存、下架未出库部分生成上架任务  */
    ResponseResult updateWhsOut(JSONObject doc, String userId)throws Exception;

    /** 贸易货出库任务完成，补单形式 */
    ResponseResult updateWhsOutM(JSONObject doc, String userId)throws Exception;

    /** 获取出库任务执行结果提交SAP，返回信息包含 出库任务结果表头、出库任务结果行项目、备件货还包括箱码 */
    ResponseResult getWhsOutToSap(String uuid, String userId)throws Exception;

    /** 备件货出库保存功能——保存出库任务详情 和 下架任务详情，不计算库存 */
    ResponseResult saveWhsOutX(JSONObject doc, String userId)throws Exception;

    /** 通过装箱单号、柜序号将多个出库任务详情合并显示在一起，包括推荐储位信息 */
    ResponseResult getWhsOutDtlList(String packageList, String cabinetSerialNumber, String werks, String whsLocationCode);


    /** 根据下架任务uuid获取 下架任务类型 创建时间最新的一条下架任务 */
    ShelfOnTask getShelfOnTaskByRelateDocNumber(String whsOutUuid, String taskType);

    /** 根据下架任务uuid，获取下架任务详情 */
    List<ShelfOnTaskDtl> getShelfOnTaskDtlByRelateDocNumber(String whsOutUuid);

    /**根据uuid撤销贸易货出库*/
    ResponseResult withdrawWhsOutM(String whsOutUuid, String currentStatus, String userId)throws Exception;
    /**根据uuid撤销贸备件出库*/
    ResponseResult withDrawWhsOutX(String whsOutUuid, String currentStatus, String userId)throws Exception;

    /** 获取提交SAP数据结构体 */
    ResponseResult whsOutCancel(String packageList, String whsOutUuid, String userId);

    /** 出库任务关闭 */
    ResponseResult whsOutClose(String whsOutUuid, String userId, String remarks)throws Exception;
    
    /**
     * 出库任务打开
     * @param whsOutUuid
     * @param userId
     * @param remarks
     * @return
     */
	ResponseResult whsOutOpen(String whsOutUuid, String userId, String remarks);
	
	/**
	 * 根据装箱单号创建出库任务头信息
	 * @param doc
	 * @param userId
	 * @return
	 * @throws Exception
	 */
	ResponseResult createWhsOutHead(JSONObject doc, String userId) throws Exception;
	
	/**
	 * PDA查询装箱单号下的备件出库任务
	 * @param doc
	 * @return
	 */
	Page<Map<String, Object>> getWhsOutListPagePda(JSONObject doc);
	
	/** 根据出库任务表头获取出库任务明细信息，贸易货按物料出，备件货按箱码出 */
	List<Map<String, Object>> selectWhsOutDtl(String goodsType, String uuid);
}
