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

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.fb.instoreapply.entity.InstoreApplyItem;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface InstoreApplyItemDao extends BaseDao<InstoreApplyItem, Integer> {
       //查看是否已填过入库申请
       @Query(value = "SELECT * FROM zhxx_fb_instore_apply_item WHERE section_no_fb in (?1) AND time>=?2",nativeQuery = true)
       List<InstoreApplyItem> getItemsBySectionNos(List<String> list, String queryDate);

       //查看是否已填过入库申请
       @Query(value = "SELECT * FROM zhxx_fb_instore_apply_item WHERE section_no_fb in (?1) AND time>=?2 AND apply_id <> ?3",nativeQuery = true)
       List<InstoreApplyItem> getItemsBySectionNosAndTrayId(List<String> list, String queryDate, Integer trayId);

       @Modifying
       @Query(value = "DELETE FROM zhxx_fb_instore_apply_item WHERE apply_id=?1",nativeQuery = true)
       void deleteByApplyId(Integer id);

       //查看是否已填过入库申请
       @Query(value = "SELECT * FROM zhxx_fb_instore_apply_item WHERE apply_id=?1",nativeQuery = true)
       List<InstoreApplyItem> getItemsByApplyId(Integer applyId);

       @Modifying
       @Query(value="UPDATE zhxx_fb_instore_apply_item SET state='已打印' WHERE apply_id=?1",nativeQuery = true)
       void updateStateById(Integer id);

       @Query(value = "SELECT * FROM zhxx_fb_instore_apply_item WHERE section_no_fb in (?1)",nativeQuery = true)
       List<InstoreApplyItem> checkCreate(List<String> list);

}
