package com.sw.mes.issue.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.issue.entity.YbIssueRecord;

/**
 * @author wangjingyu
 * @datetime 2023年9月6日 下午4:45:33
 * @description
 */
public interface YbIssueRecordDao extends BaseDao<YbIssueRecord, Long> {

    @Query(value = "SELECT * FROM yb_issue_record WHERE section_no=?1 AND is_deleted = 0 AND status = 0", nativeQuery = true)
    List<YbIssueRecord> findBySectionNo(String sectionNo);

    @Query(value = "SELECT * FROM yb_issue_record WHERE tray_no=?1 AND is_deleted = 0", nativeQuery = true)
    List<YbIssueRecord> findByTrayNo(String trayNo);

    @Query(value = "SELECT * FROM yb_issue_record WHERE branch_code=?1 AND send_status = 0 AND is_deleted = 0", nativeQuery = true)
    List<YbIssueRecord> queryByBranchCode(String branchCode);

    @Modifying
    @Query(value = "UPDATE yb_issue_record SET send_status = ?2 WHERE branch_code = ?1", nativeQuery = true)
    void updateSendStatus(String branchCode, Integer sendStatus);

    @Query(value = "SELECT * FROM yb_issue_record WHERE branch_code=?1 AND send_status = 0 AND is_deleted = 0 ORDER BY id DESC, gmt_create DESC LIMIT 4", nativeQuery = true)
    List<YbIssueRecord> queryByBranchCodeLastFour(String branchCode);
}