package thyyxxk.webserver.dao.his.outpatient.triage;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.outpatient.mangedoctorinfo.DoctorInfo;
import thyyxxk.webserver.entity.outpatient.triage.MessageForPush;

import java.util.List;

@Mapper
public interface RoomScreenDao {
    @Select("select url from triage_room_page_url where id=1")
    String getPageUrl();

    @Select("select path from triage_room_video order by [key]")
    List<String> getVideoList();

    @Select("select rtrim(doctor_code) from mzfz_zd_dept_room where room_code=#{code}")
    String getRoomDoctorCode(String code);

    @Select("select name=rtrim(a.name), " +
            "sex=rtrim(a.sex_code)," +
            "rtrim(a.emp_tit_code) titleCode," +
            "titleName=(select rtrim(name) from zd_emp_title where code=a.emp_tit_code), " +
            "code=rtrim(a.code), " +
            "rtrim(a.dept_code) deptCode," +
            "deptName=(select rtrim(name) from zd_unit_code where code=a.dept_code), " +
            "a.portrait," +
            "a.specialty," +
            "a.introduction " +
            "from a_employee_mi a where a.code=#{code}")
    DoctorInfo getDoctorInfo(@Param("code") String code);

    @Select("select rtrim(a.room_no) as code, rtrim(b.name) as name from " +
            "mzfz_zd_dept_room a, zd_unit_code b where a.room_code=#{roomCode} " +
            "and b.code=a.dept_code")
    CodeName getRoomNoAndDept(@Param("roomCode") String roomCode);

    @Select("select top 1 fz_no,rtrim(name) as name from mzfz_patient_order with(nolock) where room_code=#{roomCode} " +
            "and datediff(day , visit_date,getdate())=0 and fz_no>#{fzNo} order by fz_no")
    MessageForPush getNextJz(MessageForPush param);

    @Select("select fz_no, rtrim(name) as name from mzfz_patient_order with(nolock) " +
            "where room_code=#{roomCode} and datediff(day , visit_date,getdate())=0 " +
            "and status_flag in ('1','2','3') order by fz_no")
    List<MessageForPush> getNextJzList(MessageForPush param);

    @Select("select top 1 room_code from zd_triage_room_ip where ip=#{ip}")
    String getRoomCodeByIp(@Param("ip") String ip);

    @Update("update t_triage_notify_relation set notify_datetime=getdate() where serial_no=#{serialNo}")
    void updateNotifyDatetime(@Param("serialNo") int serialNo);
}
