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

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

import java.util.List;

public interface ProductionFurnaceMaterialSplitDao extends BaseDao<ProductionFurnaceMaterialSplit, Long>{

    /**
     * 根据任务id、复投次数删除
     * @param taskId
     * @param againNum
     */
    void deleteByTaskIdAndAgainNum(Long taskId, Integer againNum);

    void deleteByTaskIdAndRawType(Long taskId, Integer rowType);

    /**
     * 根据任务id、复投次数、桶号查询
     * @param taskId
     * @param againNum
     * @param bucketIndex
     * @return
     */
    List<ProductionFurnaceMaterialSplit> findByTaskIdAndAgainNumAndBucketIndex(Long taskId, Integer againNum, Integer bucketIndex);

    /**
     * 根据炉次号和复投次数查
     * @param lotNo 炉次号
     * @param againNum 复投次数
     * @return
     */
    List<ProductionFurnaceMaterialSplit> findByLotNoAndAgainNum(String lotNo, Integer againNum);

    @Query(value = "SELECT * FROM production_furnace_material_split WHERE raw_type = ?1 and task_id = ?2 and bucket_index = ?3 order by id desc", nativeQuery = true)
    List<ProductionFurnaceMaterialSplit> findByRawTypeAndTaskIdAndBucketIndex(Integer rawType, Long taskId, Integer bucketIndex);
}