package thyyxxk.webserver.dao.his.dictionary;

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

import java.util.List;

@Mapper
public interface ClinicRoomDictDao {
    @Select("select " +
            "a.dept_code,deptName=b.name,a.room_code,a.room_name, " +
            "statusFlag=isnull(a.status_flag,0),a.room_no " +
            "from mzfz_zd_dept_room a,zd_unit_code b " +
            "where a.dept_code=b.code order by dept_code,room_no")
    List<MzfzZdDeptRoom> getAllRooms();

    @Select("select code,name from zd_unit_code where mz_flag='1' and ghjz_flag='1' order by code")
    List<CodeName> getDeptList();

    @Update("update mzfz_zd_dept_room set dept_code=#{deptCode}, " +
            "room_name=#{roomName},room_no=#{roomNo},status_flag=#{statusFlag} " +
            "where room_code=#{roomCode}")
    void updateRoomInfo(MzfzZdDeptRoom room);

    @Select("select isnull(max(room_code),0)+1 from mzfz_zd_dept_room")
    String getMaxRoomCode();

    @Insert("insert into mzfz_zd_dept_room (dept_code,room_code,room_name,room_no,status_flag) " +
            "values (#{deptCode},#{roomCode},#{roomName},#{roomNo},#{statusFlag})")
    void insertRoomInfo(MzfzZdDeptRoom room);
}
