package com.sunda.spmswms.service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmswms.entity.SapDeliveryNote;
import com.sunda.spmswms.entity.SapDeliveryNoteDtl;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * SAP交货单表头 服务类
 * </p>
 *
 * @author Wayne
 * @since 2021-03-22
 */
public interface ISapDeliveryNoteService extends IService<SapDeliveryNote> {

    /** 页面按钮刷新获取最新交货单、交货单行项目、供应商等信息更新接口 */
    void insertSapDeliveryNote(JSONObject doc)throws Exception ;

    Map<String, Object> getSapDeliveryNote(String userId, JSONObject searchCriteria);

    Map<String, Object> getSapDeliveryNotePda(String userId, JSONObject searchCriteria);

    Map<String, Object> getOrderReceiveDatabySapDN(String deliveryNoteSap);

    /** 贸易货交货单更新接口————更新交货单表头信息 */
    ResponseResult updateSapDeliveryNote(String deliveryNoteSap, String spmsStatus,String remarks,String documentDate,String postingDate,String mobileType,String userId, String operateUser)throws Exception ;

    /** 贸易货交货单更新接口————更新交货单行项目信息，以及贸易货库存信息 */
    ResponseResult updateSapDeliveryNoteDtl(JSONObject doc, String userId)throws Exception ;

    /** 更新备件货实收箱数信息 */
//    ResponseResult updateSapBoxNote(JSONObject doc);

    /** 获取指定条件下所有备件货收货任务列表 */
    Map<String, Object> getSpDeliveryNoteTask(String userId, JSONObject doc);

    /** 根据交货单号查询交货单表头及行项目提交SAP */
    Map<String, Object> getDnDataToSap(String deliveryNoteSap, String postingDate, String userId, String remarks, String operateUser);

    /** 来货验收结果更新接口，备件货箱数验收结果更新。更新交货单表头、行项目、箱码信息表，生成上架任务 */
    ResponseResult checkSapDeliveryNote(String userId, JSONObject doc)throws Exception ;

    /** 根据交货单号更新单据状态，先校验原有状态是否正确，再更新到新的状态 */
    int updateSapDeliveryNoteStatus(String deliveryNoteSap, String targetStatus, String sapVoucherNumber, String sapVoucherYear);

    /** 根据交货单号获取交货单表头信息 */
    SapDeliveryNote getSapDnByDn(String deliveryNoteSap);

    /** 贸易货一步收化接口*/
    ResponseResult sapDeliveryNoteRecM (JSONObject jsonObject,String userId)throws Exception ;

    /** 备件货一步收化接口*/
    ResponseResult sapDeliveryNoteRecX (JSONObject jsonObject,String userId)throws Exception ;

    /** 20210623 PDA按交货单和状态更新交货单信息，返回更新之后的交货单信息——仅供PDA */
    ResponseResult updateSapDeliveryNoteTask(JSONObject doc, String userId);

    /** 交货单开始处理之前，先向 SAP 发出交货单锁定 REST 请求 */
    ResponseResult lockSapDeliveryNote(String deliveryNoteSap, String userId);

    /** 备件货交货单从SAP Rest更新数据时，从SAP获取数据成功更新到SPMS之前先删掉该交货单关联的所有数据，包括交货单明细，包装单号，箱码，箱码明细 */
    ResponseResult deleteDnRelateDoc(String deliveryNoteSap);

    /** 从SAP撤销交货单成功之后更新字段到交货单表中 */
    void updateCancelSapDeliveryNote(String deliveryNoteSap, String cancelPostingDate, String cancelSapVoucherNumber, String cancelRemark);

    /** 关闭/开启自管仓交货单，关闭单据 operateType = 0，开启单据 operateType = 1； */
    ResponseResult closeOrOpenSapDeliveryNote(String deliveryNoteSap, String operateType, String userId);
    
    /**
     * 更新装卸货信息接口
     * @param doc
     * @param userId
     * @return
     */
	ResponseResult updateLoadingData(JSONObject doc, String userId);
	
	/**
	 * 获取装卸货信息接口
	 * @param deliveryNoteSap
	 * @return
	 */
	Map<String, Object> getLoadingData(String deliveryNoteSap);
	
	/**
	 * 批量更新行项目的金额字段
	 * @param itemList
	 * @return
	 */
	int updateBatchDtl(List<SapDeliveryNoteDtl> itemList);
	
	/**
	 * 撤销交货单
	 * @param deliveryNoteSap
	 * @param userId
	 * @return
	 */
	ResponseResult revokeSapDeliveryNote(String deliveryNoteSap, String userId);

}
