package com.eactive.eai.rms.onl.statistics.company.annually;

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

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eactive.apim.portal.monitoringcode.entity.MonitoringCodeId;
import com.eactive.eai.rms.data.entity.man.monitoringCode.service.MonitoringCodeService;


/**
 * <pre>
 * 1. 기능 : 
 * 2. 처리 개요 : 
 *     - 
 * 3. 주의사항 : 
 * </pre>
 * @author  : yk
 * @version : $Revision: 1.1 $
 */
@Service("companyAnnuallyService")
public class CompanyAnnuallyService {

	private CompanyAnnuallyDAO dao = null;
	private MonitoringCodeService monitoringCodeService;

	@Autowired
	public CompanyAnnuallyService(@Qualifier("companyAnnuallyDAO") final CompanyAnnuallyDAO dao,
								  MonitoringCodeService monitoringCodeService) {
		this.dao = dao;
		this.monitoringCodeService = monitoringCodeService;
	}

	public HashMap selectList(int startNum,int endNum,HashMap paramMap) throws Exception {

		// 전체 목록수 얻기
		int totalCount = dao.selectListCount(paramMap);

		paramMap.put("startNum" , startNum);// 시작 record
		paramMap.put("endNum"   , endNum);// 끝 record

		List list = dao.selectList(paramMap);

		//모니터링 기관코드 받아오기		
		List listSet = new ArrayList<HashMap<String, Object>>();
		for(int i=0;i<list.size();i++) {
			HashMap<String, Object> tmp = (HashMap<String, Object>) list.get(i);
			String adapterInstiCode = (String)tmp.get("ADPTRINSTICODE");

			if(StringUtils.isNotBlank(adapterInstiCode)) {
				String codeName = monitoringCodeService.findCodenameById(new MonitoringCodeId("ADPTR_DESC",adapterInstiCode));
				tmp.put("ADPTRINSTINAME", codeName);
			}
			listSet.add(tmp);
		}
		HashMap map = new HashMap();

		map.put("totalCount", totalCount);

		map.put("list", listSet);

		return map;
	}
	public HashMap selectListToExcel(HashMap<String, Object> paramMap ) throws Exception {

		List list = dao.selectListToExcel(paramMap);
		List listSet = new ArrayList<HashMap<String, Object>>();
		for(int i=0;i<list.size();i++) {
			HashMap<String, Object> tmp = (HashMap<String, Object>) list.get(i);
			String adapterInstiCode = (String)tmp.get("ADPTRINSTICODE");

			if(StringUtils.isNotBlank(adapterInstiCode)) {
				String codeName = monitoringCodeService.findCodenameById(new MonitoringCodeId("ADPTR_DESC",adapterInstiCode));
				tmp.put("ADPTRINSTINAME", codeName);
			}
			listSet.add(tmp);
		}

		HashMap map = new HashMap();

		map.put("list", list);

		return map;
	}
	public HashMap<String, Object> selectDetail(HashMap paramMap) throws Exception {
		return dao.selectDetail( paramMap);
	}

}
