package sikd.sikd5.sikd5ejb.mapper;
/**
 * @author  : agus
 * @tanggal : Dec 17, 2018
 */

import java.util.List;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import sikd.sikd5.sikd5bean.tabel.Pemda;
import sikd.sikd5.sikd5bean.tabel.TahunAnggaran;

public interface SettingsMapper {

	@Select("select * from ttahunanggaran order by tahunanggaran desc")
	@Results({
			@Result(property = "tahun", column = "tahunanggaran"),
			@Result(property = "jumlahPemda", column = "jumlahpemda")
	})
	public List<TahunAnggaran> getTahuns();

	@Select("select * from tpemda where kdprov <>'00' and tahunanggaran=#{tahun}"
			+ " order by kdprov, kdpemda ")
	@Results({
			@Result(property = "id", column = "pemdaindex"),
			@Result(property = "kodeProvinsi", column = "kdprov"),
			@Result(property = "kodePemda", column = "kdpemda"),
			@Result(property = "kodeSatker", column = "kdsatker"),
			@Result(property = "namaPemda", column = "urpemda")
	})
	public List<Pemda> getPemdaByTahuns(short tahun);
	
	@Select("with jum as (select kdprov,count(*) jumlahpemda from tpemda a \n" + 
			"where tahunanggaran=#{tahun} and kdprov<>'00'\n" + 
			"group by kdprov )\n" + 
			"select a.*,b.jumlahpemda from tpemda a left join jum b on a.kdprov=b.kdprov\n" + 
			"where a.kdprov <>'00' and a.kdpemda='00' and a.tahunanggaran=#{tahun}")
	@Results({
			@Result(property = "id", column = "pemdaindex"),
			@Result(property = "kodeProvinsi", column = "kdprov"),
			@Result(property = "kodePemda", column = "kdpemda"),
			@Result(property = "kodeSatker", column = "kdsatker"),
			@Result(property = "namaPemda", column = "urpemda"),
			@Result(property = "jumlahPemda", column = "jumlahpemda")
	})
	public List<Pemda> getProvByTahuns(short tahun);
}
