package com.sunda.spmswms.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmswms.dto.WhsSearchDTO;
import com.sunda.spmswms.entity.InventoryCheckAction;
import com.sunda.spmswms.entity.WhsStorageInventory;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * <p>
 * 储位库存信息表 服务类
 * </p>
 *
 * @author Wayne
 * @since 2021-03-18
 */
public interface IWhsStorageInventoryService extends IService<WhsStorageInventory> {

    /**分页 */
    ResponseResult getWhsList(
            List<String> werks, List<String> whsLocationCode, List<String> storageArea, List<String> shelfNo, List<String> shelfLayer,
            List<String> shelfCell, List<String>storageNo,List<String>materialNo,String storageCategory,List<String>
                    boxNote, int pageNo, int pageSize);
     /**不分页 
     * @param searchInfo 
     * @param packageNote */
     ResponseResult getWhsStorageInventory(
            List<String> werks, List<String> whsLocationCode, List<String> storageArea, List<String> shelfNo, List<String> shelfLayer,
            List<String> shelfCell, List<String>storageNo,List<String>materialNo,String storageCategory,List<String>
                    boxNote, String searchInfo, String packageNote);
    // 更新储位库存  备件货上架
    ResponseResult updateStorageInventoryX(String uuid,String boxNote,String deliveryNoteSap,String userId);
    ResponseResult insertStorageInventoryX(String uuid,String boxNote,String deliveryNoteSap,String userId);

    // 更新储位库存  贸易货上架
    ResponseResult updateStorageInventoryM(String uuid,String materialNo,Double qty,String deliveryNoteSap,String userId);

    // 更新储位库存  备件货下架
    ResponseResult updateDeductTaskDtlX(String uuid,String boxNote,String deliveryNoteSap,String userId);

    // 更新储位库存  贸易货下架
    ResponseResult updateDeductTaskDtlM(String uuid, String materialNo, Double qty, String deliveryNoteSap, String userId);

    // 查箱码所在储位
    WhsStorageInventory getBoxNoteStorage(String boxNote);

    // 查找Material在储位的库存
    WhsStorageInventory getMaterialOnStorage(String materialNo, String storageNo);

    /** 根据储位 uuid 和 箱码查询箱码可用数量 */
    String getAvailableQtyByUuidBoxNote(String storageUuid, String boxNote);

    /** 根据储位 uuid 和 箱码查询储位库存数据 */
    WhsStorageInventory getStorageBoxNote(String storageUuid, String boxNote);

    //根据箱号list查找对应的储位UUID List
    List<WhsStorageInventory> getStorageListByBoxNoteList (List<String> searchCriteria);

    //逐行更新最新备件箱码信息
    ResponseResult updateStorageInventoryX(String uuid,String operateTime,String boxNote);

    //在箱码不存在的时候插入箱的信息
    void insertStorageInventory(String uuid, String operateTime, String boxNote);

    //根据箱号查阅储位信息,并判断是否存在
    Optional<WhsStorageInventory> getStorageInventoryByBoxNo(String boxNote);

    /** 根据箱码删除储位库存 */
    int deleteStorageBoxNote(String boxNote);
    /** 根据箱码，储位编号删除储位库存 */
    int deleteStorageByBoxNoteStorageId(String uuid,String boxNote);

    /** 贸易货根据储位 uuid 和 物料编号查询库存数量 */
    WhsStorageInventory getStorageMaterialNo(String storageUuid, String materialNo);

    /** 贸易货根据储位uuid，物料号，数量扣减更新储位库存 */
    int updateWhsStorage(String storageUuid, String materialNo, double qty);

    /** 根据箱码，储位编号更新储位库存*/
    ResponseResult updateWhsStorageX(JSONObject updateDoc,String userId);

    /* 根据日期获取最近有出入库的贸易货储位库存*/
    ResponseResult getStorageMByDate(String werks,String whsLocationCode,String startDate,String endDate);
    /* 根据日期获取最近有出入库的储位库存(海外仓适用)*/
    ResponseResult getStorageByDate(String werks,String whsLocationCode,String startDate,String endDate,String documentType);
    /* 根据日期获取最近有出入库的备件货储位库存*/
    ResponseResult getStorageXByDate(String werks,String whsLocationCode,String startDate,String endDate);

    /** 盘盈盘亏储位库存操作调用方法: qty 为操作数的绝对值；inventoryActionType 701盘盈，702盘亏； 
     * @param taskRowId */
    int updateWhsStorageInventory(InventoryCheckAction inventoryCheckAction, String materialNo,
                                  String boxNote, double discrepancy, String storageUuid, String userId, String taskRowId);

//    /** 贸易货根据储位uuid，物料号，数量增加更新储位库存。返回结果 > 0 表示成功。 */
//    int updateWhsStorageInventoryM(String storageUuid, String materialNo, double qty);

    /**检查是否有足够库存*/
    ResponseResult checkStorageInventory(JSONArray storageList,String materialNo);

    int updateWhsStorageInventoryMOld(String storageUuid, String materialNo, double qty);



    /** 线程安全控制————贸易货储位库存操作，包括库存校验，operateType = add 加库存；operateType = sub 减库存； 加减库存时 qty 都取正数；此法不带操作日志； */
    ResponseResult updateStorageInventoryM(String storageUuid, String materialNo, double qty, String operateType);

    /** 线程安全控制————备件货储位库存操作，包括库存校验，operateType = add 加库存；operateType = sub 减库存； 加减库存时 qty 都取1；此法不带操作日志； */
    ResponseResult updateStorageInvX(String storageUuid, String boxNote, double qty, String operateType);

//    Page<Map<String,Object>> getPageMap(JSONObject doc);
    Map<String,Object> getPageMap(List<String> werks, List<String> whsLocationCode, List<String> storageArea, List<String> shelfNo, List<String> shelfLayer, List<String> shelfCell, List<String> storageNo, List<String> materialNo, String storageCategory, List<String> boxNote, int pageNo, int pageSize);

    /**获取多个物料,箱码所在的储位信息*/
    ResponseResult getWSInventory(String werks,String whsLocationCode,List<String> materialNo,  List<String> boxNote);
    
    /**
     * 国内仓获取库存明细报表
     * @param dto
     * @return
     */
	ResponseResult getWhsStockList(WhsSearchDTO dto);

    int updateWhsStorageNotUpdate(String storageUuid, String materialNo, double qty);
    /**
     * 批量获取箱码库存信息接口
     * @param boxNote
     * @return
     */
	ResponseResult getWSInventoryByBoxNote(List<String> boxNote);
}
