package com.jasamedika.medifirst2000.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


	

import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PerhitunganAbkService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;
import com.jasamedika.medifirst2000.entities.PerhitunganAbk;
import com.jasamedika.medifirst2000.vo.PerhitunganAbkVO;
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.PerhitunganAbkDao;

/**
 * Implement class for PerhitunganAbkService
 * 
 * @author Generator
 * @param <T>
 */
@Service("perhitunganAbkService")
public class PerhitunganAbkServiceImpl extends BaseVoServiceImpl implements PerhitunganAbkService 
{	
	@Autowired
	private BaseConverterImpl<PerhitunganAbkVO,PerhitunganAbk>perhitunganAbkConverter;
	
	@Autowired
	private PerhitunganAbkDao perhitunganAbkDao;	
	
	@Override
	public Map<String, Object> savePerhitunganAbk(List<PerhitunganAbkVO> vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		for (PerhitunganAbkVO perhitunganAbkVO : vo) {
			PerhitunganAbk model = new PerhitunganAbk();
			model = perhitunganAbkConverter.transferVOToModel(perhitunganAbkVO,model);			
			PerhitunganAbk resultDomain = perhitunganAbkDao.save(model);
			if (CommonUtil.isNotNullOrEmpty(resultDomain)) {
				result.put("noRec", resultDomain.getNoRec());
			}
		}
				

		return result;
	}

	@Override
	public Map<String, Object> findByTahun(Integer tahun) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			result.put("noRec", JsonUtil.ToMaps(perhitunganAbkDao.findByTahun(tahun)));
		} catch (IllegalArgumentException | IllegalAccessException e) {
			e.printStackTrace();
		}
		return result;
	}
}