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


import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.pc.entity.TrayBindingRecord;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

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

    @Query(value = "SELECT * FROM zhxx_fb_operate_tray_binding_record WHERE code = ?1 AND status = ?2 ", nativeQuery = true)
    List<TrayBindingRecord> findByCodeAndStatus(String code, Integer status);

    @Query(value = "SELECT * FROM zhxx_fb_operate_tray_binding_record WHERE section_no = ?1 AND status = ?2 ", nativeQuery = true)
    List<TrayBindingRecord> findBySectionNoAndStatus(String sectionNo, Integer status);

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_fb_operate_tray_binding_record SET status = ?4,unbundling_user_name = ?3, unbundling_time=NOW() WHERE code = ?1 AND  section_no IN (?2) ", nativeQuery = true)
    Integer updateByCodeAndSectionNoList(String code,List<String> sectionNoList,String unbundlingUserName,Integer status);
}
