package cn.estsh.i3plus.pojo.wms.repository;

import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository;
import cn.estsh.i3plus.pojo.wms.bean.WmsStockSn;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @Description : 库存条码dao层
* @Reference :
* @Author : dragon.xu
* @CreateDate : 2018-11-17 15:53
* @Modify:
**/
public interface WmsStockSnRepository extends BaseRepository<WmsStockSn, Long> {
    /**
     * 按照条码查询实体
     * @param sn 条码
     * @return 库存条码实体
     */
    WmsStockSn findFirstBySn(String sn);

    /**
     * Rock.Yu at 2019-06-22 11:05
     * 按照存储区代码查询最早批次的物料条码
     * 按照 特殊批次、生产日期、收货日期 优先级从高到低依次排序
     * @return 最早批次的条码
     */
    @Query(value = "from WmsStockSn " +
            "where organizeCode=?1 " +
            "and zoneNo=?2 and partNo=?3 and isValid=?4 and isDeleted=?5 and snStatus=40 " +
            "order by fixLotNo, dateCode, lotNo")
    List<WmsStockSn> findByFifoSNByZoneNo(String organizeCode, String zoneNo, String partNo, int isValid, int isDeleted);
}
