package com.sw.mes.fb.checkout.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.fb.checkout.entity.FbCheckOutRecord;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.math.BigDecimal;
import java.util.List;

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface FbCheckOutRecordDao extends BaseDao<FbCheckOutRecord, Integer>{

    @Query(value = "SELECT * FROM `zhxx_operate_check_out` WHERE fb_section_no = ?1 order by id desc",nativeQuery = true)
    List<FbCheckOutRecord> findFbSecitonNo(String sectionNoFb);

    @Query(value = "SELECT * FROM `zhxx_operate_check_out` WHERE fb_section_no like ?1 order by id desc",nativeQuery = true)
    List<FbCheckOutRecord> findAllFbCheckOutRecord(String sectionNoFb);

    @Query(value = "SELECT * FROM `zhxx_operate_check_out` WHERE id = ?1",nativeQuery = true)
    FbCheckOutRecord findFbCheckOutRecordById(Long id);


    /**
     * 根据方棒编号查询方棒反切划完线单晶画线记录
     *
     * @param sectionNoFb 方棒编号
     * @return
     */
    @Query(value = "select length from production_painting_line_detail where  no = ?1 and is_cut = 0 and crystal_type = 1 and type = 0 order by id desc limit 1", nativeQuery = true)
    String getProductionPaintingLineDetail(String sectionNoFb);

    /**
     * 修改检验数据库是否反切字段
     *
     * @param isCutBack 是否反切
     * @param sectionNo 晶段
     */
    @Modifying
    @Query(value = "UPDATE zhxx_operate_check_out_data SET tangent_flag = ?1 WHERE fb_section_no = ?2 ", nativeQuery = true)
    void updateIsCutBack(int isCutBack, String sectionNo);
    @Modifying
    @Query(value = "UPDATE zhxx_operate_check_out SET  weight = ?2 WHERE id = ?1  ", nativeQuery = true)
    void updateWeight(Integer id, BigDecimal weight);

    @Query(value = "SELECT * FROM `zhxx_operate_check_out` WHERE yb_section_no IN(?1)  ORDER BY id desc",nativeQuery = true)
    List<FbCheckOutRecord> findYbSecitonNoList(List<String> sectionNoYbList);

    @Query(value = "SELECT * FROM zhxx_operate_check_out WHERE fb_section_no in ?1",nativeQuery = true)
    List<FbCheckOutRecord> findBySectionNoList(List<String> sectionNoList);}
