package com.jasamedika.medifirst2000.dao;

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

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.NilaiIndexKinerjaIndividu;

@Repository("NilaiIndexKinerjaIndividuDao")
public interface NilaiIndexKinerjaIndividuDao extends PagingAndSortingRepository<NilaiIndexKinerjaIndividu, String>{
	
	@Query(" select new map(nilaiIndexKinerjaIndividu.totalIKI as totalIKI,"+
			" nilaiIndexKinerjaIndividu.totalInovasi as inovasi, "+
			" nilaiIndexKinerjaIndividu.totalKualitas as kualitas,"+
			" nilaiIndexKinerjaIndividu.totalKuantitas as kuantitas,"+
			" jabatanInternal.namaJabatan as jabatan,"+
			" unitKerja.name as unitKerja,"+
			" nilaiIndexKinerjaIndividu.totalPerilaku as perilaku,"+
			" pegawai.namaLengkap as namaLengkap, pegawai.nipPns as nip)"+  
			" from NilaiIndexKinerjaIndividu nilaiIndexKinerjaIndividu, MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join nilaiIndexKinerjaIndividu.pegawai pegawai "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai  unitKerja "
			+ "left join mapPegawai.jabatan jabatanInternal "
			+ "where mapPegawai.pegawaiId = pegawai.id "
			+ "and mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true "
			+ "and unitKerja.id = :ruanganId "
			+ "and nilaiIndexKinerjaIndividu.periode=:periode")
	public List<Map<String,Object>> findRekapitulasiIKI(@Param("ruanganId") Integer ruanganId,@Param("periode") String periode );
	
	@Query(" select new map(nilaiIndexKinerjaIndividu.totalIKI as totalIKI,"+
			" nilaiIndexKinerjaIndividu.totalInovasi as inovasi, "+
			" nilaiIndexKinerjaIndividu.totalKualitas as kualitas,"+
			" nilaiIndexKinerjaIndividu.totalKuantitas as kuantitas,"+
			" jabatanInternal.namaJabatan as jabatan,"+
			" unitKerja.name as unitKerja,"+
			" nilaiIndexKinerjaIndividu.totalPerilaku as perilaku,"+
			" pegawai.namaLengkap as namaLengkap, pegawai.nipPns as nip)"+  
			" from NilaiIndexKinerjaIndividu nilaiIndexKinerjaIndividu, MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join nilaiIndexKinerjaIndividu.pegawai pegawai "
			+ "left join mapPegawai.subUnitKerjaPegawai subUnitKerja "
			+ "left join mapPegawai.unitKerjaPegawai unitKerja "
			+ "left join mapPegawai.jabatan jabatanInternal "
			+ "where mapPegawai.pegawai = pegawai.id "
			+ "and mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true "
			+ "and nilaiIndexKinerjaIndividu.periode=:periode")
	public List<Map<String,Object>> findAllRekapitulasiIKI(@Param("periode") String periode );
	
	@Query(" select new map(nilaiIndexKinerjaIndividu.totalIKI as totalIKI,"+
			" nilaiIndexKinerjaIndividu.totalInovasi as inovasi, "+
			" nilaiIndexKinerjaIndividu.totalKualitas as kualitas,"+
			" nilaiIndexKinerjaIndividu.totalKuantitas as kuantitas,"+
			" jabatanInternal.namaJabatan as jabatan, "+
			" nilaiIndexKinerjaIndividu.periode as periode, "+
			" ruanganKerja.namaRuangan as unitKerja,"+
			" nilaiIndexKinerjaIndividu.totalPerilaku as perilaku,"+
			" pegawai.namaLengkap as namaLengkap, pegawai.nipPns as nip)"+  
			" from NilaiIndexKinerjaIndividu nilaiIndexKinerjaIndividu, MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join nilaiIndexKinerjaIndividu.pegawai pegawai "
			+ "left join pegawai.ruangan ruanganKerja "
			+ "left join mapPegawai.jabatan jabatanInternal "
			+ "where mapPegawai.pegawaiId = pegawai.id "
			+ "and mapPegawai.isPrimary is true "
			+ "and mapPegawai.statusEnabled is true "
			+ "and nilaiIndexKinerjaIndividu.periode=:periode "
			+ "order by nilaiIndexKinerjaIndividu.totalPerilaku desc")
	public List<Map<String,Object>> findRekapitulasiIndeksKehadiran(@Param("periode") String periode );


}
