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

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

import java.util.List;

/**
 * @Author：wanjia
 * @Date：2024/1/9 16:40
 */
public interface SeedDataDao extends BaseDao<SeedData, Long> {
    @Query(value = "select * from seed_data where seed_code = ?1",nativeQuery = true)
    SeedData findByCode(String code);
    @Query(value = "select * from seed_data where seed_batch_no = ?1",nativeQuery = true)
    SeedData findByBatchNo(String seedBatchNo);
    @Query(value = "select * from seed_data where batch_no = ?1 order by id desc limit 1",nativeQuery = true)
    SeedData findMaxByBatchNo(String batchNo);
    @Query(value = "select * from seed_data where batch_no = ?1 limit 1",nativeQuery = true)
    SeedData findByBatch(String batchNo);
    @Query(value = "select * from seed_data where batch_no = ?1",nativeQuery = true)
    List<SeedData> findByBatchs(String batchNo);

    @Query(value = "select sd.* from seed_data sd left join seed_iqc_inspection sii on sd.seed_code = sii.seed_code where sd.batch_no = ?1 and sii.is_qualified = 1 ",nativeQuery = true)
    List<SeedData> findByBatchAndQualified(String batchNo);
}
