package com.sw.mes.production.dao;

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

import java.util.Map;

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

    @Modifying
    @Query(value = "DELETE FROM production_truncation_reccut_details WHERE reccut_id=?1", nativeQuery = true)
    void delete(Long reccutId);

    @Query(value = "select ptr.crystal_no from production_truncation_reccut ptr join (select reccut_id from production_truncation_reccut_details where section_no = ?1 order by id desc LIMIT 1) ptrd on   ptrd.reccut_id = ptr.id", nativeQuery = true)
    String findCrystalNoBySectionNo(String sectionNo);

    @Query(value = "select ptr.segment_no,ptr.reason from zhxx_operate_re_cut ptr join (select operate_reversecut_draw_id from production_painting_line_detail where no = ?1 order by id desc LIMIT 1) ptrd on ptrd.operate_reversecut_draw_id = ptr.id", nativeQuery = true)
    Map<String, Object> findBySectionNo(String no);
}
