package com.yihu.jw.base.dao.course;

import com.yihu.jw.entity.care.course.DoctorPatientTmpDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by Bing on 2021/6/7.
 */
public interface DoctorPatientTmpDao extends PagingAndSortingRepository<DoctorPatientTmpDO,String>,
        JpaSpecificationExecutor<DoctorPatientTmpDO> {

    DoctorPatientTmpDO findByRelationCode(String relationCode);

    @Query(value = "select count(1) from DoctorPatientTmpDO t where t.patient=?1 and t.doctorCode = ?2 and t.type=?3")
    Integer findByPatientAndDoctorCodeAndType(String patient,String doctorCode,Integer type);

    @Query(value = "select count(1) from DoctorPatientTmpDO t where t.patient=?1 and t.orgCode = ?2 and t.type=?3 and t.status=?4 and t.del=1")
    Integer findByPatientAndOrgCodeAndTypeAndStatus(String patient,String orgCode,Integer type,Integer status);

    List<DoctorPatientTmpDO> queryByPatientAndTypeIn(String patient,Integer[] type);

    @Modifying
    @Query(value = "update DoctorPatientTmpDO t set t.del=0 where 1=1")
    void deleteAll();
}
