package sikd.sikd5.sikd5ejb.mapper.transaksi;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import sikd.sikd5.sikd5bean.tabel.transaksi.Headerdth;
import sikd.sikd5.sikd5bean.ws.transaksi.Headerdth_WS;

/**
 * @oleh : soraturaes
 * @tanggal : May 13, 2019
 */
@SuppressWarnings("el-syntax")
public interface HeaderDthMapper {

	@Delete({
			"delete from transaksi.headerdth",
			"where headerdthid = #{headerdthid,jdbcType=BIGINT}"
	})
	int deleteHeaderDthByPrimaryKey(Long headerdthid);

	@Delete({
			"delete from transaksi.headerdth",
			"where tahunanggaran = #{record.tahunanggaran} and kodesatker=#{record.kodesatker} and ",
			"nomorsp2d=#{record.nomorsp2d} and tanggalsp2d=#{record.tanggalsp2d}"
	})

	int deleteHeaderDthBySp2d(@Param("record") Headerdth_WS record);

	@Select({
			"insert into transaksi.headerdth (headerlogidinsert, headerlogidiupdate, ",
			"tahunanggaran, kodesatker, kodepemda, namapemda, jeniscoa,",
			"nomorsp2d, tanggalsp2d, ",
			"namaaplikasi, pengembangaplikasi, versisinergi, nmfile, sha256)",
			"values (#{headerlogidinsert,jdbcType=BIGINT}, ",
			"#{headerlogidupdate,jdbcType=BIGINT}, ",
			"#{record.tahunanggaran,jdbcType=INTEGER}, #{record.kodesatker,jdbcType=VARCHAR},#{record.kodepemda,jdbcType=VARCHAR},",
			"#{record.namapemda,jdbcType=VARCHAR},#{record.jeniscoa,jdbcType=INTEGER}, ",
			"#{record.nomorsp2d,jdbcType=VARCHAR}, #{record.tanggalsp2d,jdbcType=TIMESTAMP}, ",
			"#{record.namaaplikasi,jdbcType=VARCHAR}, #{record.pengembangaplikasi,jdbcType=VARCHAR}, ",
			"#{record.versisinergi,jdbcType=VARCHAR}, #{record.nmfile,jdbcType=VARCHAR}, ",
			"#{record.sha256,jdbcType=CHAR})",
			"returning headerdthid"
	})
	long insertHeaderDth(@Param("record") Headerdth_WS record, @Param("headerlogidinsert") long headerlogidinsert,
			@Param("headerlogidupdate") long headerlogidupdate);

	@Update({
			"update transaksi.headerdth",
			"set ",
			"headerlogidiupdate = #{headerlogidiupdate,jdbcType=BIGINT},",
			"where headerdthid = #{headerdthid,jdbcType=BIGINT}"
	})
	int updateLogUpdateHeaderDth(@Param("headerdthid") long headerdthid, @Param("headerlogidiupdate") long headerlogidiupdate);

	@Select({
			"select",
			"headerdthid, headerlogidinsert, headerlogidupdate, tahunanggaran,kodesatker, ",
			"kodepemda, namapemda, jeniscoa, nomorsp2d, tanggalsp2d, ",
			"namaaplikasi, pengembangaplikasi, versisinergi, nmfile, sha256",
			"from transaksi.headerdth",
			"where ",
			"tahunanggaran=#{tahunanggaran,jdbcType=INTEGER}",
			"and kodesatker=#{kodesatker,jdbcType=VARCHAR}",
			"and extract(month from tanggalsp2d)=#{bulan,jdbcType=INTEGER}"
	})
	@Results({
			@Result(column = "headerdthid", property = "headerdthid", jdbcType = JdbcType.BIGINT, id = true),
			@Result(column = "headerlogidinsert", property = "headerlogidinsert", jdbcType = JdbcType.BIGINT),
			@Result(column = "headerlogidiupdate", property = "headerlogidiupdate", jdbcType = JdbcType.BIGINT),
			@Result(column = "tahunanggaran", property = "tahunanggaran", jdbcType = JdbcType.SMALLINT),
			@Result(column = "kodesatker", property = "kodesatker", jdbcType = JdbcType.VARCHAR),
			@Result(column = "kodepemda", property = "kodepemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "namapemda", property = "namapemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "jeniscoa", property = "jeniscoa", jdbcType = JdbcType.SMALLINT),
			@Result(column = "nomorsp2d", property = "nomorsp2d", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tanggalsp2d", property = "tanggalsp2d", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "namaaplikasi", property = "namaaplikasi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "pengembangaplikasi", property = "pengembangaplikasi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "versisinergi", property = "versisinergi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "nmfile", property = "nmfile", jdbcType = JdbcType.VARCHAR),
			@Result(column = "sha256", property = "sha256")
	})
	List<Headerdth> selectHeaderdthByMonth(@Param("tahunanggaran") int tahunanggaran,
			@Param("kodesatker") String kodesatker, @Param("bulan") int bulan);

	@Update({
			"update transaksi.headerdth",
			"set ",
			"headerlogidiupdate = #{headerlogidiupdate,jdbcType=BIGINT},",
			"tahunanggaran = #{record.tahunanggaran,jdbcType=SMALLINT},",
			"kodesatker = #{record.kodesatker,jdbcType=CHAR},",
			"kodepemda = #{record.kodepemda,jdbcType=CHAR},",
			"namapemda = #{record.namapemda,jdbcType=VARCHAR},",
			"jeniscoa = #{record.jeniscoa,jdbcType=SMALLINT},",
			"nomorsp2d = #{record.nomorsp2d,jdbcType=VARCHAR},",
			"tanggalsp2d = #{record.tanggalsp2d,jdbcType=TIMESTAMP},",
			"nmfile = #{record.nmfile,jdbcType=VARCHAR},",
			"sha256 = #{record.sha256,jdbcType=CHAR}",
			"where headerdthid = #{headerdthid,jdbcType=BIGINT}"
	})
	int updateHeaderdthByPrimaryKey(@Param("record") Headerdth_WS record, @Param("headerdthid") long headerdthid,
			@Param("headerlogidiupdate") long headerlogidiupdate);

	@Select({
			"select",
			"headerdthid, headerlogidinsert, headerlogidiupdate, tahunanggaran,kodesatker, ",
			"kodepemda, namapemda, jeniscoa, nomorsp2d, tanggalsp2d, ",
			"namaaplikasi, pengembangaplikasi, versisinergi, nmfile, sha256",
			"from transaksi.headerdth",
			"where ",
			"tahunanggaran=#{tahunanggaran,jdbcType=INTEGER}",
			"and kodesatker=#{kodesatker,jdbcType=VARCHAR}",
			"and nomorsp2d=ANY(#{inSp2ds})"
	})
	@Results({
//			@Result(column = "headerdthid", property = "headerdthid", jdbcType = JdbcType.BIGINT, id = true),
//			@Result(column = "headerlogidinsert", property = "headerlogidinsert", jdbcType = JdbcType.BIGINT),
//			@Result(column = "headerlogidiupdate", property = "headerlogidiupdate", jdbcType = JdbcType.BIGINT),
			@Result(column = "tahunanggaran", property = "tahunanggaran", jdbcType = JdbcType.SMALLINT),
			@Result(column = "kodesatker", property = "kodesatker", jdbcType = JdbcType.VARCHAR),
			@Result(column = "kodepemda", property = "kodepemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "namapemda", property = "namapemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "jeniscoa", property = "jeniscoa", jdbcType = JdbcType.SMALLINT),
			@Result(column = "nomorsp2d", property = "nomorsp2d", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tanggalsp2d", property = "tanggalsp2d", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "namaaplikasi", property = "namaaplikasi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "pengembangaplikasi", property = "pengembangaplikasi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "versisinergi", property = "versisinergi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "nmfile", property = "nmfile", jdbcType = JdbcType.VARCHAR),
			@Result(column = "sha256", property = "sha256")
	})
	List<Headerdth_WS> selectHeaderdthByNomorSp2ds(@Param("tahunanggaran") int tahunanggaran,
			@Param("kodesatker") String kodesatker, @Param("inSp2ds") String[] inSp2ds);

	@Select({
			"select",
			"headerdthid, headerlogidinsert, headerlogidupdate, tahunanggaran,kodesatker, ",
			"kodepemda, namapemda, jeniscoa, nomorsp2d, tanggalsp2d, ",
			"namaaplikasi, pengembangaplikasi, versisinergi, nmfile, sha256",
			"from transaksi.headerdth",
			"where ",
			"tahunanggaran=#{tahunanggaran,jdbcType=INTEGER}",
			"and kodesatker=#{kodesatker,jdbcType=VARCHAR}",
			"and nomorsp2d=#{inSp2d}"
	})
	@Results({
			@Result(column = "headerdthid", property = "headerdthid", jdbcType = JdbcType.BIGINT, id = true),
			@Result(column = "headerlogidinsert", property = "headerlogidinsert", jdbcType = JdbcType.BIGINT),
			@Result(column = "headerlogidiupdate", property = "headerlogidiupdate", jdbcType = JdbcType.BIGINT),
			@Result(column = "tahunanggaran", property = "tahunanggaran", jdbcType = JdbcType.SMALLINT),
			@Result(column = "kodesatker", property = "kodesatker", jdbcType = JdbcType.VARCHAR),
			@Result(column = "kodepemda", property = "kodepemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "namapemda", property = "namapemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "jeniscoa", property = "jeniscoa", jdbcType = JdbcType.SMALLINT),
			@Result(column = "nomorsp2d", property = "nomorsp2d", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tanggalsp2d", property = "tanggalsp2d", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "namaaplikasi", property = "namaaplikasi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "pengembangaplikasi", property = "pengembangaplikasi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "versisinergi", property = "versisinergi", jdbcType = JdbcType.VARCHAR),
			@Result(column = "nmfile", property = "nmfile", jdbcType = JdbcType.VARCHAR),
			@Result(column = "sha256", property = "sha256")
	})
	Headerdth selectHeaderdthByNomorSp2d(@Param("tahunanggaran") int tahunanggaran,
			@Param("kodesatker") String kodesatker, @Param("inSp2d") String inSp2d);

}
