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

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.pc.entity.QualityPrint;
import org.springframework.data.jpa.repository.Query;

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

public interface QualityPrintDAO extends BaseDao<QualityPrint, Integer> {
    @Query(value="SELECT * FROM zhxx_quality_print WHERE FIND_IN_SET(section_no,?1) AND inspect_time>=?2",nativeQuery = true)
    List<QualityPrint> getInfoBatch(String sectionNos, Date date);

    @Query(value="SELECT * FROM zhxx_quality_print WHERE section_no IN (?1)",nativeQuery = true)
    List<QualityPrint> getInfoBatchNew(List<String> sectionNos);

    @Query(value="SELECT * FROM zhxx_quality_print WHERE FIND_IN_SET(section_no,?1)",nativeQuery = true)
    List<QualityPrint> getInfoBatchFB(String sectionNos);

    @Query(value="SELECT * FROM zhxx_quality_print WHERE section_no IN (?1)",nativeQuery = true)
    List<QualityPrint> getInfoBatchFBNew(List<String> sectionNos);

    @Query(value="SELECT product_level_second AS productLevelSecond,product_level_experiment AS productLevelExperiment,product_type_second AS productTypeSecond,\n" +
                 "count(1) AS printCount FROM zhxx_quality_print\n" +
                 "WHERE FIND_IN_SET(section_no,?1) AND inspect_time>=?2\n" +
                 "GROUP BY product_level_second,product_level_experiment,product_type_second",nativeQuery = true)
    List<Map<String,Object>> getInfoBatchStatic(String sectionNos, Date date);

    @Query(value="SELECT product_level_second AS productLevelSecond,product_level_experiment AS productLevelExperiment,product_type_second AS productTypeSecond,\n" +
            "count(1) AS printCount FROM zhxx_quality_print\n" +
            "WHERE section_no IN (?1) " +
            "GROUP BY product_level_second,product_level_experiment,product_type_second",nativeQuery = true)
    List<Map<String,Object>> getInfoBatchStaticNew(List<String> sectionNos);

    @Query(value="SELECT * FROM zhxx_quality_print WHERE section_no=?1 ",nativeQuery = true)
    List<QualityPrint> findBySectionNo(String sectionNo);
}
