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.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.IpsrsPemakaianMesin;

@Repository("ipsrsPemakaianMesinDao")
public interface IpsrsPemakaianMesinDao extends PagingAndSortingRepository<IpsrsPemakaianMesin, String>{

	@Query("select NEW Map ("
			+ "a.noRec as noRecPemakainMesin, "
			+ "b.noRec as noRec, "
			+ "a.tanggal as tanggal, "
			+ "b.literPemakaianAwal as literPemakaianAwal, "
			+ "b.literPemakaianAhir as literPemakaianAhir, "
			+ "c.namaLengkap as petugas, "
			+ "d.namaProduk as namaMesin, "
			+ "d.id as idMesin, "
			+ "e.typeProduk as jenisMesin, "
			+ "e.id as idJenisProduk, "
			+ "f.kapasitas as kapasitas) "
			+ "from IpsrsPemakaianMesin a "
			+ "left join a.ipsrsMesinBoiler b "
			+ "left join a.pegawai c "
			+ "left join b.mesin d "
			+ "left join d.typeProduk e, "
			+ "Mesin f where f.mesinId=b.mesinId and "
			+ "upper(e.typeProduk) like '%BOILER%' and a.statusEnabled in('true')")
	List<Map<String, Object>> getAllPemakaianBoiler();

	@Query("select NEW Map ("
			+ "a.noRec as noRecPemakainMesin, "
			+ "b.noRec as noRec, "
			+ "a.tanggal as tanggal, "
			+ "b.pemakaianAwal as pemakaianAwal, "
			+ "b.pemakaianAhir as pemakaianAhir, "
			+ "c.namaLengkap as petugas, "
			+ "d.namaProduk as namaMesin, "
			+ "d.id as idMesin, "
			+ "e.typeProduk as jenisMesin, "
			+ "e.id as idJenisProduk, "
			+ "f.kapasitas as kapasitas) "
			+ "from IpsrsPemakaianMesin a "
			+ "left join a.ipsrsMesinGenset b "
			+ "left join a.pegawai c "
			+ "left join b.mesin d "
			+ "left join d.typeProduk e, "
			+ "Mesin f where f.mesinId=b.mesinId and "
			+ "upper(e.typeProduk) like '%GENSET%' and a.statusEnabled in('true')")
	List<Map<String, Object>> getAllPemakaianGenset();
}
