package thyyxxk.webserver.dao.his.inpatient.charge;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.inpatient.charge.MzsfBillnoRec;

/**
 * @Description:
 * @Author:lihong
 * @Date: 2024/9/9
 */
@Mapper
public interface MzsfBillnoRecDao extends BaseMapper<MzsfBillnoRec> {

    /**
     * @description: 更新状态为失效
     * @author: lihong
     * @date: 2024/9/9 10:28
     * @param: mzsfBillnoRec
     * @return: int
     **/
    @Update("update mzsf_billno_rec set status_flag ='2' where cash_id =#{cashId} and status_flag =#{statusFlag} and receipt_type =#{receiptType}")
    int updateStatusFlag(MzsfBillnoRec mzsfBillnoRec);

    /**
     * @description: 查询用户当前有效的发票
     * @author: lihong
     * @date: 2024/9/9 14:28
     * @return: thyyxxk.webserver.entity.zysf.MzsfBillnoRec
     **/
    @Select(" select *" +
            "from mzsf_billno_rec " +
            "where cash_id = #{userCode} " +
            "  and status_flag = '1' " +
            "  and receipt_type = '2' ")
    MzsfBillnoRec selectCurMzsfBillnoRec(String userCode);

    @Update(" update mzsf_billno_rec set current_no =current_no + 1 where status_flag ='1' and receipt_type ='2' and cash_id =#{userCode} ")
    int updateCurrentNo(String userCode);
    /**
     * @description: 查询预交金当前收据号
     * @author: lihong
     * @date: 2025/6/11 8:29
     * @param: userCode
     * @return: thyyxxk.webserver.entity.inpatient.charge.MzsfBillnoRec
     **/
    @Select(" select cash_id,current_no from mzsf_billno_rec where cash_id = #{userCode} and receipt_type = '9'")
    MzsfBillnoRec selectCurYjjSjh(String userCode);

    @Update(" update mzsf_billno_rec set current_no =#{currentNo}   where  cash_id =#{cashId}  and receipt_type = '9' ")
    int updateYjjSj(MzsfBillnoRec mzsfBillnoRec);

    @Update(" update mzsf_billno_rec set current_no =current_no + 1  where  cash_id =#{userCode} and receipt_type='9' ")
    int addYjjSj(String userCode);
}
