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

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

import java.util.List;

public interface TreatmentOrderViewRepository extends JpaRepository<TreatmentOrderView, Integer> {

    /**
     * 查看某个患者当前有没有正在进行的订单（订单状态，10-待付款,20-已付款），询诊
     * @param doctorId
     * @param patientId
     * @return
     */
    @Query(value = "SELECT  COUNT(1) FROM treatment_order_view o WHERE  o.doctor_id = ? AND o.patient_id = ? and o.order_type = 1 AND o.is_deleted = 0 AND o.order_status in (10,20) limit 5",nativeQuery = true)
    int checkPresentTreatmentOrder(int doctorId, int patientId);

    /**
     * 一个用户里面有50条远程会诊已经可以满足相当长一段时间之内的需求
     *
     * @param userId
     * @return
     */
    @Query(value = "SELECT  * FROM treatment_order_view o WHERE  o.user_id = ? limit 50",nativeQuery = true)
    List<TreatmentOrderView> getTreatmentOrderViewListByUserId(int userId);



}

