package com.yihu.jw.doctor.dao;

import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
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 org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * 医生基础信息 数据库访问层
 *
 * @version
 * <pre>
 * Author	Version		Date		Changes
 * litaohong 	1.0  		2018年08月31日 	Created
 *
 * </pre>
 * @since 1.
 */
@Transactional
public interface BaseDoctorDao extends PagingAndSortingRepository<BaseDoctorDO, String>, JpaSpecificationExecutor<BaseDoctorDO>  {

    @Query("from BaseDoctorDO d where d.id = ?1 AND d.del ='1'")
    BaseDoctorDO findById(String id);

    @Query("from BaseDoctorDO d where  d.del ='1'")
    List<BaseDoctorDO> findByDel();

    @Modifying
    @Query("update BaseDoctorDO p set p.introduce = ?2,p.expertise = ?3,p.photo = ?4,p.outpatientType = ?5 where p.id = ?1")
    void update(String doctorId,String introduce,String expertise,String photo,String outpatientType);

    @Modifying
    @Query("update BaseDoctorDO p set p.del = ?2 where p.id = ?1")
    void updateStatus(String doctorId,String status);

    List<BaseDoctorDO> findByIdcard(String idcard);

    @Query("from BaseDoctorDO d where d.name = ?1 AND d.del ='1'")
    BaseDoctorDO findByNameAndDel(String name);

    @Query("from BaseDoctorDO d where d.idcard = ?1 AND d.del ='1'")
    BaseDoctorDO findByIdcardAndDel(String id);
    @Query("from BaseDoctorDO d where d.mobile = ?1")
    List<BaseDoctorDO> findByMobile(String id);

    @Query("from BaseDoctorDO d where d.yktDoctorId = ?1 AND d.del ='1'")
    BaseDoctorDO findByYktDoctorId(String yktDoctorId);

    @Query("from BaseDoctorDO d where d.idcard = ?1 AND d.del ='1'")
    BaseDoctorDO findByIdcardAndId(String idcard);

    @Query("SELECT d from BaseDoctorDO d,BaseTeamMemberDO te where d.id = te.doctorCode and te.del='1' AND d.del ='1' and te.teamCode in (?1) ")
    List<BaseDoctorDO> findDoctorsByTeam(List<String> teams);
}
