package com.jasamedika.medifirst2000.dao.custom.impl;

import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.dao.custom.RencanaKinerjaTahunanDaoCustom;
import com.jasamedika.medifirst2000.dao.custom.base.impl.CoreDaoImpl;
import com.jasamedika.medifirst2000.entities.RencanaKinerjaTahunan;

@Repository
public class RencanaKinerjaTahunanDaoCustomImpl extends CoreDaoImpl<RencanaKinerjaTahunan> implements RencanaKinerjaTahunanDaoCustom{

	public RencanaKinerjaTahunanDaoCustomImpl() {
		super(RencanaKinerjaTahunan.class);
	}

	@Override
	public	List<Map<String, Object>> findList(String noRec){
		StringBuffer buffer = new StringBuffer();
		buffer
		.append("  select NEW map (")
		.append(" 					r.noRec as noRec, ")
		.append("  					NEW map( ")
		.append(" 							sasaranStrategis.id as id, ")
		.append(" 							sasaranStrategis.sasaranStrategis as sasaranStrategis")
		.append(" 					) as sasaranStrategis, ")
		.append(" 					NEW map( ")
		.append(" 							programKerjaStrategis.id as id, ")
		.append(" 							programKerjaStrategis.programKerjaStrategis as programKerjaStrategis ")
		.append(" 					) as programKerjaStrategis,")
		.append(" 					r.uraian as uraian,")
		.append(" 					r.indikatorKinerja as indikatorKinerja,")
		.append(" 					NEW map( ")
		.append(" 							satuanIndikator.id as id, ")
		.append(" 							satuanIndikator.satuanIndikator as satuanIndikator ")
		.append(" 					) as satuanIndikator,")
		.append(" 					r.rencanaKinerjaTahunan as rencanaKinerjaTahunan ")
		.append(" 				  ) ")
		.append("  from RencanaKinerjaTahunan r ")
		.append("  left join r.sasaranStrategis sasaranStrategis ")
		.append("  left join r.programKerjaStrategis programKerjaStrategis ")
		.append("  left join r.satuanIndikator satuanIndikator ")
		.append("  where r.noRec = :noRec ");
		
		Query query = em.createQuery(buffer.toString());
		query.setParameter("noRec",noRec);
		List<Map<String,Object>> list = query.getResultList();
		
		return list;
	}

}
