package com.sw.mes.fls.dao;


import com.sw.mes.core.base.BaseDao;
import com.sw.mes.fls.entity.TempTurnstoreTrayItem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

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

    @Query(value = "SELECT * FROM temp_turnstore_tray_item ti WHERE ti.tray_id = ?1 ORDER BY ti.current_position DESC, create_time DESC LIMIT 1", nativeQuery = true)
    TempTurnstoreTrayItem findMaxCurrentPositionByTrayId(Integer id);

    @Query(value = "SELECT * FROM temp_turnstore_tray_item ti WHERE ti.tray_id = ?1", nativeQuery = true)
    List<TempTurnstoreTrayItem> findByTrayId(Integer id);

    @Query(value = "SELECT " +
            " tt.* " +
            " FROM temp_turnstore_tray tt " +
            " INNER JOIN temp_turnstore_tray_item ti ON ti.tray_id = tt.id " +
            " WHERE tt.grouped = 0 AND ti.section_no = ?1 " +
            " ORDER BY ti.id DESC LIMIT 1", nativeQuery = true)
    Map<String, Object> findBySectionNoWithoutGrouped(String sectionNo);
}
