package com.eactive.eai.rms.bat.manage.rule.layoutsync;

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

import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.common.base.SqlMapClientTemplateDao;
import com.eactive.eai.rms.common.util.StringUtils;

/**
 * The Class LayoutDao.
 * <ul>
 * <li>1. Function :</li>
 * <li>2. Summary :</li>
 * <li>3. Notification :</li>
 * </ul>
 */
@Repository("batLayoutSyncDao")
@SuppressWarnings("unchecked")
public class BatLayoutSyncDao extends SqlMapClientTemplateDao {
	
	@SuppressWarnings("deprecation")
	public void addLayoutSyncLog(HashMap<String, String> param) {
		String[] recvData = StringUtils.cuttings(param.get("RecvData"), 4000);
		if(recvData != null) { //취약점소스 수정 2020.08.27
			for( int i=0; i < recvData.length; i++) {
				param.put("RecvData", recvData[i]);
				param.put("Seqno", String.valueOf(i +1));
		        template.insert("BatLayoutSync.addLayoutSyncLog", param);
			}
		}
	}

	public HashMap<String, String> getAdapterForlayoutKey(HashMap<String, String> param) throws Exception {
		int existFlag=0;
		String command="";
		@SuppressWarnings("deprecation")
		List<HashMap<String, String>> list = template.queryForList("BatLayoutSync.findadapterForLayoutKey", param);
		@SuppressWarnings("deprecation")
		List<HashMap<String, String>> list2 = template.queryForList("BatLayoutSync.findadapterDbForLayoutKey", param);
		if( list == null || list.size() != 1 ) {
		}else {
			existFlag=1;			
		}		
		if( list2 == null || list2.size() != 1 ) {			
		}else {
			existFlag=2;
		}		
		if(existFlag==0){

			command = param.get("Command");
			if(!"delete".equals(command))
			{
				throw new Exception("전문 레이아웃 코드 값이 EAI배치 어댑터 정보에 선등록 되어 있지 않습니다!");
			}
			// throw new DAOException("아답터 Sub정보 참조 오류!![" + (list == null ? null : list.size()) + "]");
		}
		HashMap<String, String> mapInfo=null;
		if(existFlag==1)
		{
			mapInfo=list.get(0);
		}
		if(existFlag==2)
		{
			mapInfo=list2.get(0);
		}
		return mapInfo;
	}

	@SuppressWarnings("deprecation")
	public void subFtpLayDelete(HashMap<String, String> param) {
        template.delete("BatLayoutSync.subFtpLayDelete", param);
	}

	@SuppressWarnings("deprecation")
	public void subFtpLayInsert(HashMap<String, String> param) {
        template.insert("BatLayoutSync.subFtpLayInsert", param);
	}
    
	
}
