package com.sh.djpk.econsole.rest.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sh.djpk.econsole.rest.dao.DataKonsolidasiDao;
import com.sh.djpk.econsole.rest.dao.PeriodeDao;
import com.sh.djpk.econsole.rest.service.DataKonsolidasiSvc;


@Service("konsolSvc")
@Transactional(readOnly = false)
public class DataKonsolidasiSvcImpl implements DataKonsolidasiSvc{

	public static final Logger LOGGER = LoggerFactory
			.getLogger(DataKonsolidasiSvcImpl.class);
	
	@Autowired DataKonsolidasiDao dataKonsolDao;

	@Override
	@Transactional(readOnly = true)
	public List<HashMap> getAll() {
		LOGGER.info(
				"try get data konsolidasi header");
		List<HashMap> l = dataKonsolDao.getAll();
		LOGGER.trace("data from db={}", l);
		return l;
	}

	@Override
	public int insert(Map<String, Object> params) {
		
	
	LOGGER.info("try update params={}", params);
	List<Map<String, Object>> listcomp5 = new ArrayList<Map<String,Object>>();
	Map<String, Object> header = new HashMap<String, Object>();
	
	int header_id = (int) params.get("id");
	String user_id = (String) params.get("user_id");
	
	header.put("id", header_id);
	header.put("tahun", params.get("tahun"));
	header.put("bulan", params.get("period_id"));
	header.put("laporan_id", params.get("laporan_id"));
	header.put("lvl_data", params.get("level"));
	header.put("tgl_kirim_baru", params.get("tgl_kirim"));
	header.put("aktif","Y");
	header.put("status", 2);
	header.put("user_id", user_id);

	listcomp5 = (List<Map<String, Object>>) params.get("content");
	
	
	
	int i = dataKonsolDao.insertcompheader(header);
	LOGGER.info("listcomp5={}", listcomp5);
//	for (int s = 0; s<listcomp5.size(); s++){
//		Map<String, Object> isi = new HashMap<String, Object>();
//		isi = (HashMap<String, Object>) listcomp5.get(s);
//		LOGGER.info("isi={}", isi);
//		int i1 = dataKonsolDao.insertcomp5(isi, header_id, user_id);
//		
//	}
	
	LOGGER.info("result update user>>data from db={}", i);
	LOGGER.info("params={}", params);
	
	return i;
	}
//
//	@Override
//	public int update(Map<String, Object> params) {
//		LOGGER.info("try update params={}", params);
//		int i = periodeDao.updateperiode(params);
//		LOGGER.info("result update periode>>data from db={}", i);
//		LOGGER.info("params={}", params);
//		
//		return i;
//	}
//
//	@Override
//	public int delete(Map<String, Object> params) {
//		LOGGER.info("try update params={}", params);
//		int i = periodeDao.deleteperiode(params);
//		LOGGER.info("result delete periode>>data from db={}", i);
//		LOGGER.info("params={}", params);
//		
//		return i;
//	}
	
	

}
