package com.jasamedika.medifirst2000.dao;

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

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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.PenilaianKinerjaSatpam;

@Repository("PenilaianKinerjaSatpamDao")
public interface PenilaianKinerjaSatpamDao extends PagingAndSortingRepository<PenilaianKinerjaSatpam, String>,
		JpaSpecificationExecutor<PenilaianKinerjaSatpam> {

	// penilaian kinerja satpam by nama pegawai - sarpras Rumah Tangga
	@Query("select distinct NEW Map(pks.noRec as noRecPenilaian,pks.tglPenilaian as tglPenilaian,pks.tglPeriodeAwal as tglPeriodeAwal,"
			+ "pks.tglPeriodeAkhir as tglPeriodeAkhir,pks.namaSatpam as namaPegawai,pn.namaLengkap as namaPemberiNilai,"
			+ "pks.totalNilaiUraianTugas as totalNilaiUraianTugas,pks.totalNilaiKualitas as totalNilaiKualitas,pks.totalNilaiSikapPerilaku as "
			+ "totalNilaiSikapPerilaku,pks.grandTotal as grandTotal) from PenilaianKinerjaSatpam pks left join pks.pemberiNilai pn "
			+ "where lower(pks.namaSatpam) like %:namaPegawai% "
			+ "order by pks.namaSatpam")
	List<Map<String, Object>> findPenilaianKinerjaSatpamByNamaSatpam(@Param("namaPegawai") String namaPegawai);

	// get all penilaian kinerja satpam - sarpras Rumah Tangga
	@Query("select distinct NEW Map(pks.noRec as noRecPenilaian,pks.tglPenilaian as tglPenilaian,pks.tglPeriodeAwal as tglPeriodeAwal,"
			+ "pks.tglPeriodeAkhir as tglPeriodeAkhir,pks.namaSatpam as namaPegawai,pn.namaLengkap as namaPemberiNilai,"
			+ "pks.totalNilaiUraianTugas as totalNilaiUraianTugas,pks.totalNilaiKualitas as totalNilaiKualitas,pks.totalNilaiSikapPerilaku as "
			+ "totalNilaiSikapPerilaku,pks.grandTotal as grandTotal) "
			+ "from PenilaianKinerjaSatpam pks left join pks.pemberiNilai pn order by pks.namaSatpam")
	List<Map<String, Object>> getPenilaianKinerjaSatpam();

	// penilaian kinerja satpam by no rec - sarpras Rumah Tangga
	@Query("select distinct NEW Map(pks.noRec as noRecPenilaian,pks.tglPenilaian as tglPenilaian,pks.tglPeriodeAwal as tglPeriodeAwal,"
			+ "pks.tglPeriodeAkhir as tglPeriodeAkhir,pks.namaSatpam as namaPegawai,pn.namaLengkap as namaPemberiNilai,pks.totalNilaiUraianTugas as "
			+ "totalNilaiUraianTugas,pks.totalNilaiKualitas as totalNilaiKualitas,pks.totalNilaiSikapPerilaku as totalNilaiSikapPerilaku,"
			+ "pks.grandTotal as grandTotal) from PenilaianKinerjaSatpam pks left join pks.pemberiNilai pn "
			+ "where pks.noRec=:noRec order by pks.namaSatpam")
	List<Map<String, Object>> findPenilaianKinerjaSatpamByNoRec(@Param("noRec") String noRec);

	// get mapping uraian tugas - sarpras Rumah Tangga
	@Query("select NEW Map(mut.uraianTugas as uraianTugas,mut.nilaiUraianTugas as nilaiUraianTugas) "
			+ "from MappingUraianTugas mut where mut.penilaianKinerjaSatpamId=:noRecPenilaian")
	List<Map<String, Object>> findMappingUraianTugas(@Param("noRecPenilaian") String noRec);

	// get mapping kualitas - sarpras Rumah Tangga
	@Query("select NEW Map(mk.kualitas as kualitas,mk.nilaiKualitas as nilaiKualitas) "
			+ "from MappingKualitas mk where mk.penilaianKinerjaSatpamId=:noRecPenilaian")
	List<Map<String, Object>> findMappingKualitas(@Param("noRecPenilaian") String noRec);

	// get mapping sikap perilaku - sarpras Rumah Tangga
	@Query("select NEW Map(msp.sikapPerilaku as sikapPerilaku,msp.nilaiSikapPerilaku as nilaiSikapPerilaku) "
			+ "from MappingSikapPerilaku msp where msp.penilaianKinerjaSatpamId=:noRecPenilaian")
	List<Map<String, Object>> findMappingSikapPerilaku(@Param("noRecPenilaian") String noRec);
}
