package com.dev.swms.server.service.receiving;

import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.dev.swms.server.model.base.Location;
import com.dev.swms.server.model.base.LotInfo;
import com.dev.swms.server.model.base.PackageUnit;
import com.dev.swms.server.model.fee.Fee;
import com.dev.swms.server.model.receiving.ASN;
import com.dev.swms.server.model.receiving.ASNDetail;
import com.dev.swms.server.model.receiving.ReceivedDoc;
import com.dev.energy.server.service.BaseManager;

@Transactional(readOnly=true)
public interface ASNManager extends BaseManager{
	/**
	 * 保存收货单－新增收货单时自动设置所属仓库和单据状态
	 * @param asn 待保存的收货单
	 */
	@Transactional
	void storeASN(ASN asn);
	
	/**
	 * 激活收货单－只能激活“打开”状态与收货明细不为空的收货单
	 * @param asnIds 待激活的收货单ID清单
	 */
	@Transactional
	void activeAll(List<Long> asnIds);
	
	/**
	 * 取消激活收货单－只能取消激活“生效”状态的收货单
	 * @param asnIds 待取消激活的收货单ID清单
	 */
	@Transactional
	void inactiveAll(List<Long> asnIds);

	/**
	 * 删除收货单－只能删除“打开”状态的收货单
	 * @param asnIds 待删除收货单的ID清单
	 */
	@Transactional
	void deleteAll(List<Long> asnIds);

	/**
	 * 取消收货单－只能取消“打开”状态的收货单
	 * @param asnIds
	 */
	@Transactional
	void cancelAll(List<Long> asnIds);
	
    /**
     * 新增收货单明细－当asnDetail对象已存在时，则直接修改收货单明细对象
     * @param asnId　待保存的收货单ＩＤ
     * @param asnDetail　待增加的收货单明细
     */
    @Transactional
    void addASNDetail(Long asnId, ASNDetail asnDetail);
    
    /**
     * 删除收货单明细
     * @param asnId 待删除明细的收货单ID
     * @param asnDetailIds 待删除的收货单明细ID集合
     */
    @Transactional
    void removeASNDetail(Long asnId, List<Long> asnDetailIds);
    
    /**
     * 整单收货
     * @param asnId 收货单ID;
     * @param receiveDate 收货日期;
     * @param qualityCode 质损代码;
     * @param workerId 作业人员;
     * 
     */
    @Transactional
    void confirmReceiving(Long asnId, Date receiveDate, String qualityCode, Long workerId,Long zoneId);
    
    @Transactional
    void confirmReceivingVIM(Long asnId,String qualityCode, Long workerId,Long zoneId);

    @Transactional
    void yjshConfirmReceiving(List<Long> asnIds, Date receiveDate, Long locationId);

    /**
     * 批量收货
     * @param asnId 收货单ID;
     * @param asnDetailIds 收货单明细ID集合;
     * @param receiveDate 收货日期;
     * @param qualityCode 质损代码;
     * @param workerId 作业人员;
     * 
     */
    @Transactional
    void confirmReceiving(Long asnId, List<Long> asnDetailIds, Date receiveDate, String qualityCode, Long workerId,Long zoneId);
    @Transactional
    void confirmReceivingAllKams(Long asnId,Date receiveDate, String receivingstatus,
			Long zoneId);
    @Transactional
    void confirmReceivingKams(List<Long> asnDetailIds,String myfs,Date receiveDate, String qualityCode,
			Long zoneId,Location loc);
    /**
     * 单一明细收货
     * @param asnId 收货单ID;
     * @param asnDetailId 收货明细ID;
     * @param lotInfo 批次属性
     * @param quantity 收货数量
     * @param receivingPackageUnit 收货包装ID
     * @param receiveDate 收货日期;
     * @param qualityCode 质损代码;
     * @param workerId 作业人员;
     * 
     */
    @Transactional
    void confirmReceiving(Long asnId, Long asnDetailId, LotInfo lotInfo, double quantity, 
    		 Date receiveDate, String qualityCode,Long workerId,Long zoneId,ASNDetail detail);
    
    /**
     * 收货质检（传入的质检数量为基本单位数量）
     * @param asn
     * @param inventories
     */
    @Transactional
    void asnQuality(ASN asn, Map inventories);
    /**
     * 取消收货－－－对指定的收货记录取消收货
     *     直接删除收货记录，并调整收货单及其明细的收货数量
     *     取消收货记录中对应的上架计划（收货单收货调整后重新手工创建上架计划）
     * @param receivedRecordIds
     */
    @Transactional
    void receiveBack(List<Long> receivedRecordIds);
    @Transactional
    void receiveBackKams(List<Long> receivedRecordIds);
    
     /**
     * 获取指定收货单明细的待收数量
     * @param map 前台页面参数map
     */
    String getExpectedQuantityByDetail(Map map);
    
    /**
     * 获取指定收货单明细的收货数量
     * @param map 前台页面参数map
     */
    Double getReceivedQuantityByDetail(Map map);
    
    int getCaseQty(Map map);
    
    int getPuQty(Map map);
    
    String getZoneMap(Map map);
    
    ASN getASNByCode(String code);
    
    /**
     * RF方法－根据指定收货单的货品编码查找对应的收货单明细
     * @param docId
     * @param itemCode
     * @param type 0-返回找到的第一条单据明细
     *             1-返回找到的第一条未完成收货确认的单据明细
     * @return
     */
    ASNDetail getASNDetailByItem(Long asnId, String itemCode,int type);
    
//    asnDetail getasnDetailByItemKey(Long itemKeyId, Long docId);
    
    @Transactional
    PackageUnit getUnit(Long detailId);

	ReceivedDoc getReceivedDocByCode(String code,String receivedDocCode, int type);
	
	/**
	 * 根据收货单自动创建上架计划
	 * @param asnIds
	 */
	@Transactional
	void createMoveDocByASN(List<Long> asnIds);
	
	@Transactional
	void input(Long asnId,String vehicle,Date inputDate,Long workerId);
	
	@Transactional
	void output(Long asnId,Date inputDate,Long workerId);
	
	@Transactional
	void willReceive(List<Long> ids,Long dock_id,Date estimateDate,String vehicle);

	@Transactional
	void receiveBackAll(Long asnId);
	
	@Transactional
	void virInOutputStock(List<Long> ids);	
	
	@Transactional
	void receiveOver(List<Long> ids);	
	
	@Transactional
	void asnMoveTo(List<Long> ids);
	
	@Transactional
	void transitInStock(List<Long> ids);
	
	@Transactional
	void transitOutStock(List<Long> ids);
	
	/**
	 * 收货确认导入
	 * @param file
	 * @param asnId
	 */
	@Transactional
	void importReceiveConfirm(File file,Long asnId);
	
	/**
	 * 判断用户是否存在有收货的单据
	 * @param userId
	 * @return
	 */
	boolean isExistReceiveASN(Long userId);
	
	/**
	 * 根据ASN号或取ASN收货信息
	 * @param code
	 * @param userId
	 * @return
	 */
	
	
	@Transactional
	int rfReceive(Map<Object,Object> values);
	
	/**
	 * 根据ASNDetail和包装获取码托信息
	 * @param asnDetailId
	 * @param unit
	 * @return
	 */
	String getStockInfoByItemUnit(Long asnDetailId, String unit);
	
	/**
	 * 导入收货单
	 * */
	@Transactional
    void importASN(File file);
	
	@Transactional
    void importASN2(File file);
	
	/**
	 * 导入收货上架
	 * */
	@Transactional
    void importASNGrounding(File file);
	@Transactional
	void confirmReceiving(Long asnId, Map locs) ;
	@Transactional
	void saveFee(Fee fee ,Long asnid,String billObjectType);
	@Transactional
	void deleteFee(List<Long> ids);
	
	/**
	 * @author  dev
	 * 删除回单影像
	 */
	@Transactional
	void deleteSignFile(List<Long> ids);
	@Transactional
	void cancelReceivedRecord(Long asnId, Map qtys);
	@Transactional
	void cancelReceivedRecord(Long asnId);
	@Transactional
	void confirmAsnReceivingKams(List<Long> asnIds,String myfs,Date receiveDate, String receivingstatus,Long zoneId) ;
	/**
	 * 发动机批量采集入库
	 * @param detailId
	 * @param pfId
	 * @param location_code
	 * @param barCodes
	 * @param oper
	 */
	@Transactional
	void confirmReceivingKamsAppFdjs(Long detailId,Long pfId,String location_code,String barCodes,String oper) ;
	
	@Transactional
	void confirmReceivingKamsApp(Long detailId,String location_code,Long pfId,double qty,String barCode,Date receiveDate,String oper) ;
	/**
	 * 盘点调整
	 * @param file
	 */
	@Transactional
	void importInvPDTZ(File file);

}