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

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

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

import com.eactive.eai.rms.common.base.OnlBaseService;

@Service("batLayoutSyncManService")
public class BatLayoutSyncManService extends OnlBaseService {
    @Autowired
    @Qualifier("batLayoutSyncDao")
    private BatLayoutSyncDao dao;
    
    public String deleteLayout(HashMap<String, String> param) throws Exception {
    	String result = "";
    	try {
    		dao.subFtpLayDelete(param);
    	} catch(Exception e) {
    		result = e.getMessage();
    	} finally {
            param.put("PrcssRslt", result.equals("") ? "S" : "F");
			param.put("PrcssRsltCmnt", result);
	        addLayoutSyncLog(param);
    	}
    	return result;
    }

    public void insertLayout(List<HashMap<String, String>> items, HashMap<String, String> param) 
            throws Exception {
    	String result = "";
    	try {
        	// 초기화
    		dao.subFtpLayDelete(param);
        	
        	for(HashMap<String, String> item : items) {
        		dao.subFtpLayInsert(item);
        	}
    	} catch(Exception e) {
    		result = e.getMessage();
    	} finally {
            param.put("PrcssRslt", result.equals("") ? "S" : "F");
			param.put("PrcssRsltCmnt", result);
	        addLayoutSyncLog(param);
    	}
    }

    public void addLayoutSyncLog(HashMap<String, String> param) throws Exception {
    	dao.addLayoutSyncLog(param);
    }

	public HashMap<String, String> getAdapterForlayoutKey(HashMap<String, String> query) throws Exception {
		return dao.getAdapterForlayoutKey(query);
	}
}