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 AdditionalRegistrationRepository extends JpaRepository<AdditionalRegistration, Integer> {

    /**
     * 判断是否有引用(已付款且未就诊的)
     * @param scheduleId
     * @return
     */
    @Query(value = "select count(1) from additional_registration where schedule_id = ? and deleted = 0  and status = 1",nativeQuery = true)
    int checkNumByScheduleId(int scheduleId);

    /**
     * 根据schedule_id得到所有对应的加号预约对象
     * @param scheduleId
     * @return
     */
    @Query(value = "select * from additional_registration where schedule_id = ?  and deleted = 0  ",nativeQuery = true)
    List<AdditionalRegistration> findByScheduleId(int scheduleId);

    /**
     * 判断是否重复预约
     * @param patientName
     * @param mobile
     * @param scheduleId
     * @return
     */
    @Query(value = "select count(1) from additional_registration where name = ? and mobile = ? and  schedule_id = ?  and deleted = 0  ",nativeQuery = true)
    int  checkRepetition(String patientName, String mobile, int scheduleId);



}
