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


import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.pc.entity.StoreMixInfoItem;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @Author liru
* @Description：
* @Date:
* @Modified By:
*/
public interface StoreMixInfoItemDao extends BaseDao<StoreMixInfoItem , Integer> {

    /**
     * 根据配料id
     * @param storeMixInfoId
     * @return
     */
    List<StoreMixInfoItem> findByStoreMixInfo_Id(Integer storeMixInfoId);

    @Modifying
    @Transactional
    @Query(value = "DELETE FROM store_mix_info_item WHERE store_mix_info_id=?1 ", nativeQuery = true)
    void deleteByStoreMixInfo_Id(Integer storeMixInfoId);

    @Query(value = "select * from store_mix_info_item where id IN (?1) ", nativeQuery = true)
    List<StoreMixInfoItem> findByIds(List<Integer> ids);

    @Query(value = "SELECT i.* FROM store_mix_info_item i LEFT JOIN store_mix_info m ON i.store_mix_info_id=m.id \n" +
            "  WHERE m.lot_no = ?1 AND i.is_gi=0", nativeQuery = true)
    List<StoreMixInfoItem> getByLotNo(String lotNo);
}
