package com.sw.mes.fb.turnstore.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.fb.turnstore.entity.FbTurnstoreTray;
import com.sw.mes.fb.turnstore.entity.FbTurnstoreTrayItem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Author
 * @Description：
 * @Date:
 * @Modified By:
 */
public interface FbTurnstoreTrayDao extends BaseDao<FbTurnstoreTray, Integer> {

    @Query(value = "SELECT max(order_num) from fb_turnstore_tray where has_gone = '综计WMS' AND time >= CURRENT_DATE", nativeQuery = true)
    Integer findOrderNumByWMS();

    @Query(value = "SELECT max(order_num) from fb_turnstore_tray where has_gone != '综计WMS' AND time >= CURRENT_DATE", nativeQuery = true)
    Integer findOrderNumBy();

    @Query(value = "SELECT 1 FROM fb_turnstore_tray WHERE tray_no=?1 LIMIT 1", nativeQuery = true)
    Integer checkTrayNo(String trayNo);

    @Query(value = "SELECT 1 FROM fb_turnstore_tray WHERE class_no=?1 LIMIT 1", nativeQuery = true)
    Integer checkClassNo(String classNo);


    @Query(value = "SELECT * FROM fb_turnstore_tray WHERE tray_no=?1 LIMIT 1", nativeQuery = true)
    FbTurnstoreTray findByTrayNo(String trayNo);


    @Query(value = "SELECT * FROM fb_turnstore_tray WHERE tray_no in ?1 ", nativeQuery = true)
    List<FbTurnstoreTray> findByTrayNoList(List<String> trayNoList);

    @Query(value = "SELECT * FROM fb_turnstore_tray WHERE `time` >= ?1 AND `time` < ?2 ", nativeQuery = true)
    List<FbTurnstoreTray> findByTime(String startTime, String endTime);

    @Query(value = "SELECT * FROM fb_turnstore_tray WHERE warehouse_entry_number=?1 LIMIT 1", nativeQuery = true)
    FbTurnstoreTray findByWarehouseEntryNumber(String zinbd);

    @Query(value = "SELECT * FROM fb_turnstore_tray_item WHERE section_no=?1 order by id limit 1", nativeQuery = true)
    FbTurnstoreTrayItem findBySectionNo(String sectionNo);
}
