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

import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.outpatient.triage.FloorScreenSetting;
import thyyxxk.webserver.entity.outpatient.triage.MzfzZdDeptRoom;
import thyyxxk.webserver.entity.outpatient.triage.RoomIp;

import java.util.List;

@Mapper
public interface TriageSettingsDao {
    // 获取所有门诊科室
    @Select("select rtrim(code) code, rtrim(name) name, rtrim(py_code) pyCode from zd_unit_code with(nolock) where mz_flag=1")
    List<CodeName> getAllMzDept();

    // 获取员工已选择的科室
    @Select("select chosen_dept from t_triage_user_depts with(nolock) where code=#{code}")
    String getChosenDept(String code);

    @Update("update t_triage_user_depts set chosen_dept=#{chosenDept} where code=#{code}")
    int saveChosenDept(String code, String chosenDept);

    @Insert("insert into t_triage_user_depts (code, code_rs, name, chosen_dept) values " +
            "(#{code}, #{codeRs}, #{name},#{depts})")
    void insertChosenDept(String code, String codeRs, String name, String depts);

    @Select("select rtrim(code_rs) as code, rtrim(name) as name from a_employee_mi where code=#{code}")
    CodeName selectEmployeeCodeRsName(String code);

    @Select("<script>" +
            "select *, " +
            "doctor_name=(select rtrim(name) from a_employee_mi with(nolock) where code=a.doctor_code), " +
            "req_name=(select rtrim(name) from mzy_zd_charge_type with(nolock) where code=a.req_type), " +
            "dept_name=(select rtrim(name) from zd_unit_code with(nolock) where code=a.dept_code) " +
            "from mzfz_zd_dept_room a with(nolock) " +
            "where a.dept_code in " +
            "<foreach collection='deptCodes' item='deptCode' open='(' separator=',' close=')'>" +
            "#{deptCode}" +
            "</foreach>" +
            "</script>")
    List<MzfzZdDeptRoom> getChosenRoom(String[] deptCodes);

    @Select("select rtrim(code) code, rtrim(name) name from a_employee_mi with(nolock) where py_code like #{content} and isnull(del_flag,0)!=1")
    List<CodeName> searchDoctor(String content);

    @Select("select rtrim(code) code, rtrim(name) name, rtrim(py_code) pyCode from mzy_zd_charge_type with(nolock) where isnull(del_flag,0)!=1")
    List<CodeName> getReqs();

    @Update("update mzfz_zd_dept_room set doctor_code=#{doctorCode}, " +
            "req_type=#{reqType}, status_flag=#{statusFlag} " +
            "where room_code=#{roomCode}")
    void updateRoomSettings(MzfzZdDeptRoom room);

    @Select("select * from zd_triage_room_ip with(nolock)")
    List<RoomIp> getAllRoomIp();

    @Update("update zd_triage_room_ip set ip=#{ip} where [key]=#{key}")
    void updateRoomIp(RoomIp param);

    @Select("select * from t_floor_screen_settings where user_code=#{userCode}")
    FloorScreenSetting getFloorScreenSetting(String userCode);

    @Select("select rolling_message from t_floor_screen_settings where user_code='system'")
    String getRollingMessage();
}
