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

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.turnstore.entity.ProductionBindingTrayLog;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

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

    ProductionBindingTrayLog findByTrayNoAndCrystalNo(String trayNo, String crystalNo);

    @Modifying
    @Query(value = "update `production_binding_tray_log` set crystal_no = ?2 where crystal_no = ?1", nativeQuery = true)
    void updateByCrystalNo(String crystalNoOld, String crystalNo);

    @Query(value = "SELECT * FROM production_binding_tray_log WHERE tray_no=?1 ORDER BY id desc LIMIT 1", nativeQuery = true)
    ProductionBindingTrayLog getFirstData(String pailNum);

    @Query(value = "SELECT * FROM production_binding_tray_log WHERE crystal_no=?1 ORDER BY id DESC LIMIT 1 ", nativeQuery = true)
    ProductionBindingTrayLog findByCrystalNo(String crystalNo);
}
