package com.eactive.eai.rms.bap.statistics.eaibzwkdstcd.listup;

import java.util.ArrayList;
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;

@Service("bjobBzwkDstcdListupService")
public class BjobBzwkDstcdListupService {
	@Autowired
	@Qualifier("bjobBzwkDstcdListupDAO")
    private BjobBzwkDstcdListupDAO dao = null;
    
    public HashMap<String, Object> selectList(HashMap<String,Object> param) throws Exception{

    	HashMap<String, Object> map = new HashMap<String, Object>();		
    	
    	String tableNum = "";
    	if (param.get("searchStartTime") != null) {
    		tableNum = param.get("searchStartTime").toString().substring(6,8);
    	} else {
    		return map;
    	}

    	param.put("tableNum", tableNum);
    	List<HashMap<String, Object>> list = dao.selectList(param);
    	
    	// List에서 상위 N개만 추출 (endNum-startNum)
    	int startNum = param.get("startNum") != null ? Integer.valueOf(param.get("startNum").toString()) : 0;
    	int endNum = param.get("endNum") != null ? Integer.valueOf(param.get("endNum").toString()) : 10;
    	List<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>(); 
    	if ((endNum-startNum-1) < list.size()) {
    		result = list.subList(startNum,endNum);
    	} else {
    		result = list;
    	}

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

}
