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

import cn.hnthyy.thmz.entity.his.zy.ZyReceipt;
import org.apache.ibatis.annotations.*;

/**
 * 住院发票数据库接口
 */
public interface ZyReceiptMapper {
    /**
     * 删除住院发票
     * @param inpatientNo
     * @param admissTimes
     * @param ledgerSn
     * @return
     */
    @Delete("delete from zy_receipt WHERE inpatient_no =#{inpatientNo} AND admiss_times =#{admissTimes} AND ledger_sn =#{ledgerSn} ")
    int deleteZyReceipt(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes, @Param("ledgerSn") Integer ledgerSn);



    /**
     * 获取最后一个住院发票信息
     *
     * @param inpatientNo
     * @param admissTimes
     * @return
     */
    @Select("select top 1* from zy_receipt where inpatient_no =#{inpatientNo} and admiss_times =#{admissTimes} order by ledger_sn desc ")
    ZyReceipt selectLastZyReceipt(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);

    /**
     * 插入住院收费发票
     * @param zyReceipt
     * @return
     */
    @Insert("INSERT INTO zy_receipt ( inpatient_no , admiss_times , ledger_sn , receipt_sn , receipt_no , account_date , date_1 , date_2 , ward , dept , print_date , " +
            "responce_unit , op_id_code , total_charge , charge1 , charge2 , charge3 , charge4 , charge5 , charge6 , charge7 , charge8 , charge9 , charge10 , charge11 , " +
            "charge12 , charge13 , charge14 , charge15 , charge16 , charge17 , charge18 , charge19 , charge20 , charge21 , charge22 , charge23 , charge24 , charge25 ," +
            " charge26 , charge27 , charge28 , charge29 , charge30 ) VALUES (#{inpatientNo},#{admissTimes},#{ledgerSn},#{receiptSn},#{receiptNo},#{accountDate},#{date1}," +
            "#{date2},#{ward},#{dept},#{printDate},#{responceUnit},#{opIdCode},#{totalCharge},#{charge1}, #{charge2} ,#{charge3} ,#{charge4},#{charge5} , #{charge6}, #{charge7} ," +
            " #{charge8}, #{charge9} , #{charge10} ,#{charge11} , #{charge12}, #{charge13} , #{charge14}, #{charge15} ,#{charge16} , #{charge17},#{charge18}, #{charge19}," +
            " #{charge20} , #{charge21} , #{charge22} , #{charge23} , #{charge24} , #{charge25} , #{charge26} ,#{charge27} ,#{charge28} , #{charge29} , #{charge30})")
    int insertZyReceipt(ZyReceipt zyReceipt);


    /**
     * 修改发票信息
     * @param zyReceipt
     * @return
     */
    @Update({"<script>",
            "update zy_receipt ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where inpatient_no =#{inpatientNo} AND admiss_times =#{admissTimes} AND ledger_sn =#{ledgerSn}' >",
            "<when test='ledgerSn!=null'>",
            "receipt_no =#{receiptNo}",
            "</when>",
            "</trim>",
            "</script>"})
    int updateZyReceiptCommon(ZyReceipt zyReceipt);
}
