package com.sw.mes.production.dao;

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

import java.util.List;

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

    List<FormulaProductSchemeDetail> findByFormulaProductSchemeIdOrderByAgainNumAsc(Long fpsId);

    @Query(value = "SELECT * FROM production_formula_product_scheme_detail WHERE formula_product_scheme_id = ?1 AND weight_scheme_id = ?2 ORDER BY again_num ASC ",nativeQuery = true)
    List<FormulaProductSchemeDetail> findByFpsIdAndWsId(Long fpsId, Long wsId);

    void deleteAllByFormulaProductSchemeId(Long fpsId);

    @Query(value = "SELECT * FROM production_formula_product_scheme_detail WHERE formula_product_scheme_id = ?1 AND again_num = ?2 ORDER BY id DESC LIMIT 1 ",nativeQuery = true)
    FormulaProductSchemeDetail findByFpsIdAndAgainNum(Long fpsId, Integer againNum);

    @Query(value = "SELECT * FROM production_formula_product_scheme_detail WHERE formula_product_scheme_id = ?1 AND weight_scheme_id = ?2 AND again_num = ?3 ORDER BY id DESC LIMIT 1 ",nativeQuery = true)
    FormulaProductSchemeDetail findByFpsIdAndWsIdAndAgainNum(Long fpsId, Long wsId, Integer againNum);

}