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

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.seed.entity.SeedIQCInspection;
import com.sw.mes.yb.seed.entity.SeedSelfInspection;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SeedIQCInspectionDao extends BaseDao<SeedIQCInspection,Long> {
    @Query(value = "select * from seed_iqc_inspection where seed_code = ?1",nativeQuery = true)
    SeedIQCInspection getBySeedCode(String seedCode);
    @Query(value = "select * from seed_iqc_inspection where seed_batch_no = ?1",nativeQuery = true)
    SeedIQCInspection getBySeedBatchNo(String seedBatchNo);
    @Query(value = "select * from seed_iqc_inspection where plan_code = ?1",nativeQuery = true)
    List<SeedIQCInspection> getByPlanCode(String planCode);
    @Query(value = "select sii.* from seed_iqc_inspection sii left join seed_data sd on sii.seed_code = sd.seed_code " +
            "left join seed_self_inspection ssi on sii.seed_code = ssi.seed_code where sii.batch_no = ?1 " +
            "and sii.is_qualified = ?2 and ssi.is_qualified = ?2 and sd.group_bracket = 0",nativeQuery = true)
    List<SeedIQCInspection> getByBatchNo(String batchNo,Boolean isQualified);
    @Query(value = "select * from seed_iqc_inspection where is_qualified = ?1",nativeQuery = true)
    List<SeedIQCInspection> getQualified(Boolean isQualified);
    @Query(value = "select * from seed_iqc_inspection where seed_code in ?1",nativeQuery = true)
    List<SeedIQCInspection> getIQCInspectionBySeedCodes(List<String> seedCodes);
}
