package com.bankaudit.dao;

import org.hibernate.Query;
import org.hibernate.Session;
import org.jboss.logging.Logger;
import org.springframework.stereotype.Repository;

import com.bankaudit.model.MaintReportDerivedStmt;

@Repository("maintReportDerivedStmtDao")
public class MaintReportDerivedStmtDaoImpl extends AbstractDao implements MaintReportDerivedStmtDao {
	
	static final Logger logger = Logger.getLogger(MaintReportDerivedStmtDaoImpl.class);
	
	@Override
	public MaintReportDerivedStmt getMaintReportDerivedStmtById(Integer legalEntityCode, String statementId) {
		logger.info("Inside getMaintReportDerivedStmtById of legalEntityCode :: " + legalEntityCode+" ::"+statementId);
		Session session = getSession();
		return (MaintReportDerivedStmt) (session.createQuery("from MaintReportDerivedStmt d where "
				+ " d.statementId=:statementId ")).setParameter("statementId", statementId).uniqueResult();
	}
	
	@SuppressWarnings({ "unchecked", "serial", "deprecation" })
	@Override
	public void updateMaintReportDrvStmntRupeeSymbl(int legalEntityCode,String statementId){
		logger.info(" updateAuditReportStmntRupeeSymbl .... "+ legalEntityCode + "::" + statementId );
		
		try {
			String hql ="";		
			hql+="CALL update_maint_derive_stmnt_rupee(:legalEntityCode,:auditTypeCcode,:statementId)";
			Session session=getSession();
			Query query = session.createSQLQuery(hql)
					//.addScalar("v_temp", StandardBasicTypes.STRING)
					.setParameter("legalEntityCode", legalEntityCode).setParameter("auditTypeCcode", "RRBI")
				    .setParameter("statementId", statementId);
			
			query.list(); 
			logger.info("Procedure update_audit_report_stmnt executed.");
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
		
	}

}
