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

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

import java.util.Date;

public interface MzSerialNoMapper {


    /**
     * 加锁
     * @param updateTime
     * @return
     */
    @Update("update mz_serial_no set update_time=#{updateTime,jdbcType=TIMESTAMP} where id = 1")
    int updateForBlock(@Param("updateTime") Date updateTime);

    /**
     * 查询序列号记录
     * @return
     */
    @Select("select serial_no,rtrim(outpatient_no) outpatient_no,inject_no,serial_out,prior_no,serial_new,hzyl_no from mz_serial_no where id = 1")
    MzSerialNo selectMzSerialNo();

    /**
     * 更新序列号
     * @param mzSerialNo
     * @return
     */
    @Update({"<script>",
            "update mz_serial_no ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where id =1 ' >",
               "<when test='newOutpatientNo!=null'>",
                  "outpatient_no =#{newOutpatientNo,jdbcType=VARCHAR}",
               "</when>",
               "<when test='newSerialOut!=null'>",
                  ",serial_out =#{newSerialOut,jdbcType=INTEGER}",
               "</when>",
               "<when test='newSerialNew!=null'>",
                  ",serial_new =#{newSerialNew,jdbcType=INTEGER}",
               "</when>",
            "</trim>"
            ,"</script>"})
    int updateMzSerialNo(MzSerialNo mzSerialNo);
}
