package com.sw.mes.crucible.dao;

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

/**
 * @author lf
 * @description
 * @date 2024/1/8 9:08
 */
public interface CrucibleFixedCastingDao extends BaseDao<CrucibleFixedCasting,Integer> {

    @Query(value = "select * from crucible_fixed_casting where equipment_id = ?1 and fixed_casting_type = ?2 limit 1",nativeQuery = true)
    CrucibleFixedCasting findByEquipmentIdAndfixedCastingType (Integer equipmentId, String fixedCastingType);

    @Query(value = "select * from crucible_fixed_casting where equipment_id = ?1 and fixed_casting_type = ?2 and id <> ?3 limit 1",nativeQuery = true)
    CrucibleFixedCasting findByEquipmentIdAndfixedCastingTypeAndIdNot(Integer equipmentId, String fixedCastingType, Integer id);


    CrucibleFixedCasting findTopByEquipmentCodeOrderByIdDesc(String code);

    @Query(value = "select * from crucible_fixed_casting where equipment_code = ?1 and fixed_casting_type = ?2 order by id desc limit 1",nativeQuery = true)
    CrucibleFixedCasting findByEquipmentCodeAndFixedCastingType(String code, String fixedCastingType);

}
