package com.sw.mes.production.dao;

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

import java.math.BigDecimal;
import java.util.List;

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

    void deleteAllByFormulaProductSchemeId(Long fpsId);

    List<FormulaProductSchemeWeightDetail> findByFormulaProductSchemeId(Long fpsId);

    @Query(value = "SELECT * FROM production_formula_product_scheme_weight_detail WHERE formula_product_scheme_id = ?1 AND scope_upper >= ?2 AND scope_lower <= ?2 ORDER BY scope_lower ASC LIMIT 1 ",nativeQuery = true)
    FormulaProductSchemeWeightDetail findByFpsIdAndScope(Long fpsId, BigDecimal weight);

}