package com.cirle.scientific.dao;/*
 *24901
 *2022/12/21
 *11:11
 */


import com.cirle.scientific.po.QkjPatientApp;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface QkjPatientAppDao extends PagingAndSortingRepository<QkjPatientApp, Long>, JpaSpecificationExecutor<QkjPatientApp> {

    @Query(value = "select * from qkj_patient_app where mem_card = ?1 and id = ?2 and obj_type = ?3 and obj_id = ?4 and status = 0",nativeQuery = true)
    QkjPatientApp findAllByMemCard(String memCard, Integer patientId,  Integer objType, Integer objId);

    @Query(value = "select * from qkj_patient_app where mem_card = ?1 and patient_name = ?2 and status = 0 and is_accomplish_question = 1 order by id desc limit 1 ",nativeQuery = true)
    QkjPatientApp findAllByMemCardAndName(String memCard, String patientName);

    @Query(value = "select * from qkj_patient_app where mem_card = ?1 and obj_type = ?2 and obj_id = ?3 and phone = ?4 and status = 0 order by id desc limit 1 ",nativeQuery = true)
    QkjPatientApp findAllByMemCardAndObjTypeAndObjIdAndPhone(String doctorCodeMemCard, Integer objType, Integer objId, String phone);

    @Query(value = "select * from qkj_patient_app where mem_card = ?1 and create_time > ?2  and create_time < ?3 and is_accomplish_question = 1 and status = 0",nativeQuery = true)
    List<QkjPatientApp> findIsAccomplishQuestion(String doctorCodeMemCard, String firstday, String lastday);

}
