package thyyxxk.webserver.dao.his.zygl;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMi;

/**
 * @Description:
 * @Author:lihong
 * @Date: 2025/5/8
 */
public interface ZyBedMiDao {
    /**
     * 更新床位
     *
     * @param zyBedMi
     * @return
     */
    @Update(" update zy_bed_mi SET bed_status =#{bedStatus} , inpatient_no =#{inpatientNo} , admiss_times =#{admissTimes} WHERE ward_code =#{wardCode} AND dept_code =#{deptCode} AND bed_no =#{bedNo} ")
    int updateZyBedMi(ZyBedMi zyBedMi);

    /**
     * 出院重置病床
     *
     * @param inpatientNo
     * @param admissTimes
     * @return
     */
    @Update("update zy_bed_mi SET bed_status ='1' , admiss_times =NULL , inpatient_no =NULL WHERE inpatient_no =#{inpatientNo} AND admiss_times =#{admissTimes} ")
    int clearZyBedMi(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);

    /**
     * 查询给定病床信息
     *
     * @param deptCode 科室
     * @param wardCode 病区
     * @param bedNo
     * @return
     */
    @Select("SELECT bed_status,bed_no FROM zy_bed_mi WHERE  dept_code =#{deptCode} AND ward_code =#{wardCode} AND bed_no =#{bedNo}")
    ZyBedMi selectZyBedMi(@Param("deptCode") String deptCode, @Param("wardCode") String wardCode, @Param("bedNo") String bedNo);

    /**
     * 查询科室里最大的空闲的病床号码
     *
     * @param deptCode 科室
     * @param wardCode 病区
     * @return
     */
    @Select("select max(bed_no) from zy_bed_mi  WHERE dept_code =#{deptCode} AND ward_code =#{wardCode}  and bed_status ='1' ")
    String selectMaxFreeBedNo(@Param("deptCode") String deptCode, @Param("wardCode") String wardCode);
}
