package com.dashitech.hsms.dao;

import com.dashitech.hsms.entity.HsmsCallLogEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;

public interface IHsmsCallLogDAO extends JpaRepository<HsmsCallLogEntity, String> {

    @SuppressWarnings("unchecked")
    HsmsCallLogEntity save(HsmsCallLogEntity callLogEntity);

    @Query(value = " select a from HsmsCallLogEntity a where a.dTMFA=:callerIdNumber and a.dTMFB=:destinationNumber and a.responseTime=:createdTime ")
    HsmsCallLogEntity selectByParams(@Param("callerIdNumber") String callerIdNumber, @Param("destinationNumber") String destinationNumber, @Param("createdTime") Date createdTime);

    @Query(value = "select hos_id from itsm_system_hospital_config where _key = ?1 and _value =?2 limit 1 ",nativeQuery = true)
    String selectSernelNo(String key,String value);

    @Query(value = " select a.id from HsmsCallLogEntity a where a.callAccept=:uuid ")
    Long selectIdByUuid(@Param("uuid") String uuid);

    @Query(value = "SELECT dept FROM itsm_uc_dept g WHERE g.many_phone like CONCAT('%',:phone,'%') AND g.delete_flag = 0 limit 1", nativeQuery = true)
    String getDeptNameByPhone(@Param("phone")String phone);
}
