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

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * 住院日结 99999的
 */
public interface ZyDayclosingRecordMapper {
    /**
     * 查询最后一次日结的结束时间
     * @return
     */
    @Select("select top 1 date_end from zy_dayclosing_record where op_id ='99999' order by closing_date desc ")
    Date selectLastCloseDate();

    /**
     * 保存住院日结记录
     * @param closeDate
     * @param lastCloseDate
     * @return
     */
    @Insert("insert into zy_dayclosing_record ( op_id , closing_date , date_start , date_end , yjj_flag , bt_flag , account_patient_flag , account_ward_flag , ward_income_flag , account_deposit_flag , flag , input_id ) values " +
            "( '99999' , #{closeDate} , #{lastCloseDate} , #{closeDate} , '1' , '1' , '1' , '1' , '1' , '1' , '1' , '99999' ) ")
    int insertZyDayclosingRecord(@Param("closeDate") Date closeDate, @Param("lastCloseDate") Date lastCloseDate);

    /**
     * 更新日结记录
     * @param closeDate
     * @param lastCloseDate
     * @return
     */
    @Update("update zy_ledger_file set dcount_no ='1' , dcount_date =#{closeDate} where cash_date > #{lastCloseDate} and cash_date <= #{closeDate} and cash_id like '99999' ")
    int updateZyLedgerFile(@Param("closeDate") Date closeDate, @Param("lastCloseDate") Date lastCloseDate);
}
