package com.eactive.eai.rms.bap.manage.jspforselectlist;

import java.util.ArrayList;
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;
import com.eactive.eai.rms.common.context.MonitoringContext;
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;

@Service("jspForSelectListFileService")
public class JspForSelectListFileService extends BapBaseService {
    @Autowired
    @Qualifier("monitoringContext")
    private MonitoringContext monitoringContext;	
    
    @Autowired
    @Qualifier("jspForSelectListFileDao")
    private JspForSelectListFileDao dao;
    
	public List<Map<String, Object>> selectLogListFile(String date) throws Exception {
		String use = monitoringContext.getStringProperty(MonitoringContext.RMS_JSP_SELECT_USE);
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if("Y".equals(use)){
			DataSourceType dataSourceType = DataSourceTypeManager.getDataSourceType("BAP");
			DataSourceContextHolder.setDataSourceType(dataSourceType);	
			
			String schemaId = "";
			
			if(dataSourceType != null && (dataSourceType.getSchema() != null)){  //취약점소스 수정 2020.08.25
				schemaId = dataSourceType.getSchema();
			}
			
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("schemaId",schemaId);
            paramMap.put("date", date);
            return dao.selectLogList(paramMap);
		}else{
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("errMsg", "현재 설정값='사용안함'으로 사용할 수 없습니다.");
			list.add(map);
		}
		return list;
	}	
}