package com.sw.mes.yb.pad.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.pad.entity.PieceDetail;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

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

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface PieceDetailDao extends BaseDao<PieceDetail, Long>{

    @Query(value = "select * from production_piece_detail where  piece_no IN(?1)",nativeQuery = true)
    List<PieceDetail> findByPieceNo(List<String> pieceNos);

    @Query(value = "select * from production_piece_detail where  piece_no = ?1",nativeQuery = true)
    List<PieceDetail> findByPieceNo(String pieceNo);

    @Modifying
    void deleteByPieceNoIn(List<String> pieNos);
    @Query(value = "SELECT a.crystal_no, a.piece_no, a.create_date,a.back_cut FROM production_piece_detail a LEFT JOIN zhxx_operate_piece_check b on a.piece_no = b.piece_no " +
            " WHERE b.piece_no IS NULL  AND (?1 IS NULL OR a.piece_no  = ?1) AND (?2 IS NULL OR a.create_date >= ?2) AND (?3 IS NULL OR a.create_date < ?3) ",nativeQuery = true)
    List<Map<String,Object>> queryProductionPieceDetail(String pieceNo,String startDate,String endDate);

}
