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;

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

    /**
     * 保存住院日结记录
     * @param lastCloseDate
     * @param dateEnd
     * @param closeDate
     * @param opId
     * @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 " +
            "( #{opId} , #{closeDate} , #{lastCloseDate} , #{dateEnd} , '1' , '1' , '1' , '1' , '1' , '1' , '1' , #{opId} ) ")
    int insertZyDayclosingRecord(@Param("closeDate") Date closeDate,@Param("lastCloseDate") Date lastCloseDate, @Param("dateEnd") Date dateEnd,  @Param("opId") String opId);

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