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

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

import java.util.List;
import java.util.Map;

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

    @Query(value = "SELECT * FROM `production_back_cutting_record` WHERE segment_no = ?1 ORDER BY id DESC LIMIT 1", nativeQuery = true)
    ProductionBackCuttingRecord findBySectionNo(String segmentNo);

    ProductionBackCuttingRecord findTopBySegmentNoOrderByIdDesc(String segmentNo);



    @Query(value = "SELECT\n" +
            "b.totalActualLength,\n" +
            "b.crystal_workshop as crystalWorkshop,\n" +
            "b.product_type_second as productTypeSecond,\n" +
            "c.closure_identification as closureIdentification\n" +
            "FROM\n" +
            "(select \n" +
            "crystal_no,\n" +
            "crystal_workshop,\n" +
            "product_type_second,\n" +
            "grade_type,\n" +
            "sum(actual_length)as totalActualLength\n" +
            "from \n" +
            "yb_inspect_data \n" +
            "where grade_type='正常'\n" +
            "group by crystal_no) b  \n" +
            "left join production_long_crystal c on b.crystal_no = c.crystal_no\n" +
            "where  b.crystal_no = ?1  ",nativeQuery = true)
    List<Map<String,Object>> findInformationBySegmentNo(String subSegmentNo);


    /**
     * 根据晶段编号查询返切画线信息
     *
     * @param crystalNo
     * @return
     */
    List<ProductionBackCuttingRecord> findBySegmentNoAndStatusOrderByIdDesc(String crystalNo, boolean status);
    List<ProductionBackCuttingRecord> findBySegmentNo(String crystalNo);

    List<ProductionBackCuttingRecord> findByUuid(String uuid);
}
