package com.ywt.outpatient.domain.entity.center;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ChecklistOrdersRepository extends JpaRepository<ChecklistOrders, Integer>, JpaSpecificationExecutor<ChecklistOrders> {
    ChecklistOrders findFirstByIdAndDeleted(int id, int deleted);
    ChecklistOrders findFirstByWearId(long wearId);

    /**
     * 查询所有已领取超时未归还设备、未提醒过的订单
     */
    @Query(value = "select * from ywt_center.checklist_orders where status = 3 and deleted  = 0 and (to_days(now()) - to_days(send_time) >= 1) and (ext_status is null or ext_status & 1 != 1)", nativeQuery = true)
    List<ChecklistOrders> findAllOvertimeAllocatedOrders();
}