package com.sw.mes.production.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.production.entity.FormulaSchemeDetail;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

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

    List<FormulaSchemeDetail> findByFormulaSchemeId(Long id);

    List<FormulaSchemeDetail> findByFormulaSchemeIdAndMaterialClassName(Long formulaSchemeId, String materialClassName);

    @Query(value = "SELECT fsd.* FROM production_formula_scheme_detail AS fsd " +
            "INNER JOIN production_formula_scheme AS pfs ON fsd.formula_scheme_id = pfs.id " +
            "INNER JOIN production_furnace_material_split AS fms ON fms.scheme_id = pfs.id " +
            "WHERE fms.task_id = ?1 AND fms.again_num = ?2 AND fsd.material_code = ?3 LIMIT 1 ", nativeQuery = true)
    FormulaSchemeDetail findByTaskAndMaterialCode(Long taskId, Integer againNum, String materialCode);
}