
package com.eactive.eai.rms.bat.loader.controller;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.eactive.eai.rms.bat.loader.service.BatSearchService;
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
import com.eactive.eai.rms.common.interceptor.InterceptorSkipController;
import com.eactive.eai.rms.common.util.CommonConstants;

@Controller
public class BatSearchController implements InterceptorSkipController {

    private static final Logger logger = Logger.getLogger(BatSearchController.class);

    @Autowired
    @Qualifier("batSearchService")
    private BatSearchService searchService;
    
    /**
     * 형상관리에서 자원정보를 조회한다.
     * *
     * @param request
     * @param response
     * @param schema
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/searchBAT.json",params="cmd=LIST")
    public ModelAndView search(HttpServletRequest request, HttpServletResponse response 
    		, String serviceType , @RequestParam HashMap<String,Object> paramMap  ) throws Exception {
        
        if (!serviceType.equals("EBT")){
        	HashMap<String,String> result = new HashMap<String,String>();
	    	result.put("status", "error");
	    	result.put("message", "정의 되지 않은 서비스 타입입니다. 받은 서비스 타입="+ serviceType);
        	return new ModelAndView("jsonView",result);
        }
    	//serviceType 설정
        serviceType = DataSourceTypeManager.BAT;
    	if (serviceType != null) {
    		request.getSession().setAttribute(CommonConstants.SERVICE_TYPE_KEY, serviceType);
    		DataSourceType dt = DataSourceTypeManager.getDataSourceType(serviceType);
    		if(dt != null){
    			DataSourceContextHolder.setDataSourceType(dt);
    		}
    	}  	
    	
		HashMap map = searchService.selectList( request,0, 0, paramMap);
		
		
		Map resultMap = new HashMap();
		//resultMap.put("records", pageVo.getTotalCount());//전체 레코드건수	
		resultMap.put("rows"   , map.get("list"));
    	
        

		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;
	    
    }
    
    

  

 
}
