package com.sunda.spmsoversea.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsoversea.dto.OverseaWhsDumpDTO;
import com.sunda.spmsoversea.dto.OverseaWhsDumpQueryDTO;
import com.sunda.spmsoversea.entity.OverseaWhsDump;
import com.sunda.spmsoversea.entity.OverseaWhsDumpDtl;
import com.sunda.spmsuser.entity.SpmsUser;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 海外仓转储任务表 服务类
 * </p>
 *
 * @author Wayne
 * @since 2021-11-02
 */
public interface IOverseaWhsDumpService extends IService<OverseaWhsDump> {

    /**
     海外SPMS转储单据状态:
     0删除；
     1草稿；
     2待审批；
     3SPMS审批通过(提交OA);
     4OA驳回(操作同1);
     5OA审批通过(出库中);
     6出库完成;
     7提交SAP获取PO失败;
     8提交SAP获取PO;
     9提交SAP获取DN失败;
     10提交SAP获取DN成功(扣转出方库存);
     11转出已撤销(撤到状态5出库中，SAP撤回成功则加回库存);
     */

    /** 获取转储任务列表分页 */
    ResponseResult getWhsDumpPage(OverseaWhsDumpQueryDTO overseaWhsDumpQueryDTO);

    /** 获取一个转储任务全部明细数据 */
    List<Map<String, Object>> getWhsDumpDtls(String whsDumpUuid);

    /** 创建一个转储任务申请 spmsStatus = 1 或 3 */
    ResponseResult createWhsDump(OverseaWhsDumpDTO overseaWhsDumpDTO, String userId, SpmsUser spmsUser,boolean newOa)throws Exception ;

    /** 转储任务关闭，状态变化为：1-0，4-0，5-0 */
    ResponseResult closeWhsDump(String whsDumpUuid, Integer dataVersion, String userId);

    /** 转储任务新增行项目 */
    ResponseResult addOverseaWhsDumpDtls(List<OverseaWhsDumpDtl> dumpDtls, String userId);

    /** 转储任务删除行项目 */
    ResponseResult deleteOverseaWhsDumpDtls(List<OverseaWhsDumpDtl> dumpDtls, String userId);

    /** OA 审批通过接口 */
    ResponseResult oaApproveWhsDump(String oaBianhao, String oaStatus, String userId)  throws Exception ;

    /** 转储任务更新状态变化控制：1-1(保存), 1-3(提交OA), 4-4(驳回保存), 4-3(驳回重提), 5-6(出库完成) */
    ResponseResult updateWhsDump(OverseaWhsDumpDTO overseaWhsDumpDTO, String userId, SpmsUser spmsUser,boolean newOa)throws Exception ;

    /** 提交SAP状态变化控制：6/7-8/7(获取PO), 8/9-10/9(获取DN)，获取到DN扣库存 */
    ResponseResult whsDumpToSap(String whsDumpUuid, String postingDate, Integer dataVersion, String userId)throws Exception ;

    /**
     海外SPMS转储单据状态:
         0删除；1草稿；2待审批；3SPMS审批通过(提交OA);4OA驳回(操作同1);5OA审批通过(出库中);6出库完成;7提交SAP获取PO失败;
         8提交SAP获取PO;9提交SAP获取DN失败;10提交SAP获取DN成功(扣转出方库存);11转出已撤销(撤到状态5出库中，SAP撤回成功则加回库存);
     转储任务撤回状态变化及处理：
         2-1 更新状态; 5-1 更新状态;
         6-5 更新状态; 7-5 更新状态;
         8-5 从SAP撤回PO; 9-5 从SAP撤回PO;
         10-8,8-5 从SAP撤回DN、加回库存、从SAP撤回PO;
     */
    ResponseResult cancelWhsDump(String whsDumpUuid, String cancelPostingDate, Integer dataVersion, String userId)throws Exception ;
    
    /** 创建转储申请单时excel批量导入 
     * @param whsDumpUuid **/
	ResponseResult batchCreateDumpDtl(List<OverseaWhsDumpDtl> safetyList, String userId, String whsDumpUuid);
	
	/** 根据SPMS单据号查询单据信息 **/
	ResponseResult getOverseaWhsDumpHead(String spmsId);

    List<Map<String, Object>> getWhsDumpDtlListExcel(String whsDumpUuid);

    //转储任务详情推送工厂与物料到MDM
    ResponseResult whsDumpToMdM(String whsDumpUuid,String userId) throws Exception;
    
    /**
     * 根据转储单号删除SAP的STO&DN单
     * @param whsDumpNo
     * @param userId
     * @return
     */
	ResponseResult deleteWhsDumpToSap(String whsDumpNo, String userId) throws Exception;
}
