package cn.hnthyy.thmz.mapper.his.mz;

import cn.hnthyy.thmz.entity.his.mz.MzDrugWin;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


public interface MzDrugWinMapper {
    /**
     * 加锁
     * @param winNo
     * @return
     */
    @Update("update mz_drug_win set patient_num=patient_num where win_no = #{winNo,jdbcType=CHAR}")
    int updateForBlock(String winNo);


    /**
     * 根据药房类型查询开放中的且排队人数最少的药房窗口
     * @param groupNo
     * @return
     */
    @Select("select top 1 rtrim(win_no) win_no,rtrim(win_name) win_name,rtrim(win_cate) win_cate,rtrim(group_no) group_no,patient_num from " +
            " mz_drug_win where group_no =#{groupNo,jdbcType=CHAR} and win_cate = '0'  order by patient_num asc ")
    MzDrugWin selectMinMzDrugWin(@Param("groupNo") String groupNo);

    /**
     * 更新药房的排队人数
     * @param mzDrugWin
     * @return
     */
    @Update({"<script>",
            "update mz_drug_win ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where win_no = #{winNo,jdbcType=CHAR}' >",
            "<when test='patientNum!=null'>",
            "patient_num =#{patientNum,jdbcType=INTEGER}",
            "</when>",
            "</trim>"
            ,"</script>"})
    int updateMzDrugWin(MzDrugWin mzDrugWin);

    /**
     * 按照组号与窗口号查询窗口名称
     * @param groupNo
     * @param winNo
     * @return
     */
    @Select("select rtrim(win_no) win_no,rtrim(win_name) win_name,rtrim(win_cate) win_cate,rtrim(group_no) group_no,patient_num from " +
            " mz_drug_win where group_no =#{groupNo,jdbcType=CHAR} and win_no = #{winNo,jdbcType=CHAR}")
    MzDrugWin selectMzDrugWinByGroupNoAndWinNo(@Param("groupNo") String groupNo,@Param("winNo") String winNo);
}
