package com.eactive.eai.rms.bap.manage.message.messageMeta;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eactive.eai.rms.bap.common.base.BapBaseService;

@Service("bapMessageMetaService")
public class BapMessageMetaService extends BapBaseService {

	@Autowired
	@Qualifier("bapMessageMetaDao")
	private BapMessageMetaDao dao;

	public HashMap<String, Object> selectList(int startNum,int endNum, HashMap<String, Object> paramMap) throws Exception {
 
		// 전체 목록 수 얻기
		int totalCount = dao.selectListCount(paramMap);

		paramMap.put("startNum" , startNum);//  record
		paramMap.put("endNum"   , endNum);//  record

		List<Map<String, Object>> list = dao.selectList(paramMap);
		HashMap<String, Object> map = new HashMap<String, Object>();

		map.put("totalCount", totalCount);
		map.put("list", list);
		
		return map;
	}	

	public HashMap<String, Object> selectDetail(String msgMetaDstcd) throws Exception {

		HashMap<String, Object>   detail = dao.selectDetail(msgMetaDstcd);
		List<Map<String, Object>> list   = dao.msgList(msgMetaDstcd);		

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("detail", detail);
		map.put("list", list);
		
		return map;

	}	

	public void update(HashMap<String, Object> paramMap, HashMap<String, Object>[] list )throws Exception {
		dao.update(paramMap);
		dao.deleteList(paramMap);
		HashMap<String, Object> data ;
		for(HashMap<String, Object> map : list){
			data = new HashMap<String, Object>();
			data.putAll(paramMap);
			data.put("msgClmnSeq",map.get("MSGCLMNSEQ"));
			data.put("msgItemDsticName",map.get("MSGITEMDSTICNAME"));
			dao.insertList(data);
		}		
	}

	public void insert(HashMap<String, Object> paramMap, HashMap<String, Object>[] list) throws Exception {
		
		dao.insert(paramMap);
		HashMap<String, Object> data ;
		
		for(HashMap<String, Object> map : list){
			data = new HashMap<String, Object>();
			data.putAll(paramMap);
			data.put("msgClmnSeq",map.get("MSGCLMNSEQ"));
			data.put("msgItemDsticName",map.get("MSGITEMDSTICNAME"));
			dao.insertList(data);
		}		
	}

	public void delete(HashMap<String, Object> paramMap) throws Exception {
		dao.delete(paramMap);
		dao.deleteList(paramMap);
	}	
	
}
