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

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

import java.util.List;

/**
 * @Author
 * @Description：
 * @Date:
 * @Modified By:
 */
public interface RecheckInspectReceiveDetailDao extends BaseDao<RecheckInspectReceiveDetail, Integer> {
    /**
     * 根据单晶编号查询
     *
     * @param crystalNo
     * @return
     */
    RecheckInspectReceiveDetail findByCrystalNo(String crystalNo);

    /**
     * 根据单晶编号、状态查询
     *
     * @param crystalNo
     * @return
     */
    List<RecheckInspectReceiveDetail> findByCrystalNoAndStateOrderByConfirmTimeDesc(String crystalNo,Integer state);

    // 通过方棒编号获取退库次数
    @Query(value = "SELECT COUNT(*) FROM `fb_recheck_inspect_receive_detail` d LEFT JOIN fb_recheck_inspect_receive r  ON d.tray_no = r.tray_no  WHERE crystal_no = ?1 and  d.quit_type = '退库复检' and  r.state = 1", nativeQuery = true)
    Integer findFbFjTkCount(String crystalFbNo);

    @Query(value = "SELECT count(1) FROM( SELECT 1 FROM fb_recheck_inspect_receive_detail WHERE ?1 LIKE CONCAT(crystal_no,'%') ORDER BY ID LIMIT 1 )t", nativeQuery = true)
    Integer isSprework(String sectionNo);

    @Query(value = "SELECT * from fb_recheck_inspect_receive_detail where recheck_receive_id = ?1 ", nativeQuery = true)
    List<RecheckInspectReceiveDetail> findByRecheckReceiveId(Integer id);
}
