package com.siginfo.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.SAXHelper;
import org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.XSSFComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import com.siginfo.common.CommonUtil;
import com.siginfo.common.ExcelUtil;
import com.siginfo.dao.CommonDao;
import com.siginfo.dao.MainDao;
import com.siginfo.vo.PhaseInfoVO;
import com.siginfo.vo.PlanCRHDInfoVO;
import com.siginfo.vo.PlanCROPInfoVO;
import com.siginfo.vo.PlanCRRSInfoVO;
import com.siginfo.vo.PlanCRWDInfoVO;


@Service
@Transactional(rollbackFor = {Exception.class})
public class MainService {
	
	@Autowired
	private CommonDao commonDao;

	@Autowired
	private MainDao mainDao;
	
	public static List<PhaseInfoVO> phaseVoList;
	public static List<PlanCRRSInfoVO> crrsVoList;
	public static List<PlanCRHDInfoVO> crhdVoList;
	public static List<PlanCROPInfoVO> cropVoList;
	public static List<PlanCRWDInfoVO> crwdVoList;
	
	public List<PhaseInfoVO> phaseInfoList(Map<String, Object> paramMap) throws Exception {
		phaseVoList = mainDao.phaseInfoList(paramMap); 
		return phaseVoList; 
	}
	
	public List<PlanCRRSInfoVO> crrsInfoList(Map<String, Object> paramMap) throws Exception {
		crrsVoList = mainDao.crrsInfoList(paramMap); 
		return crrsVoList; 
	}
	
	public List<PlanCRHDInfoVO> crhdInfoList(Map<String, Object> paramMap) throws Exception {
		crhdVoList = mainDao.crhdInfoList(paramMap);
		return crhdVoList;
	}
	
	public List<PlanCROPInfoVO> cropInfoList(Map<String, Object> paramMap) throws Exception {
		cropVoList = mainDao.cropInfoList(paramMap);
		return cropVoList;
	}
	
	public List<PlanCRWDInfoVO> crwdInfoList(Map<String, Object> paramMap) throws Exception {
		crwdVoList = mainDao.crwdInfoList(paramMap);
		return crwdVoList;
	}
	
	public String calcAngle(String flowNum, Object P1_lat, Object P1_lng, Object P2_lat, Object P2_lng) {
		String from_lat = CommonUtil.checkNull(P1_lat.toString());
		String from_lng = CommonUtil.checkNull(P1_lng.toString());
		String to_lat   = CommonUtil.checkNull(P2_lat.toString());
		String to_lng   = CommonUtil.checkNull(P2_lng.toString());
		
		String str_bearing = "";
		if((!"".equals(from_lat) || !"".equals(from_lng) || !"".equals(to_lat) || !"".equals(to_lng)))
		{
			if(!from_lat.equals("0") || !from_lng.equals("0") || !to_lat.equals("0") || !to_lng.equals("0"))
			{
				from_lat = (from_lat.length() > 12) ? from_lat.substring(0,12) : from_lat;
				from_lng = (from_lng.length() > 12) ? from_lng.substring(0,12) : from_lng;
				to_lat   = (to_lat.length() > 12) ? to_lat.substring(0,12) : to_lat;
				to_lng   = (to_lng.length() > 12) ? to_lng.substring(0,12) : to_lng;

				//System.out.println("from_lat : " + from_lat + " , from_lng : " + from_lng + " , to_lat : " + to_lat + " , to_lng : " + to_lng);

				
				// ex)   flat : 37.353329900   flng : 126.94595397  tlat : 37.353153397  tlng :  126.94579719  af :4 bf : 8
				//Cur_Lat_radian : 0.6519384577066711
				//    lng_r      : 2.215624407914001
				//
				//
				//
				// 현재 위치 : 위도나 경도는 지구 중심을 기반으로 하는 각도이기 때문에 라디안 각도로 변환한다.
				double Cur_Lat_radian = Double.parseDouble(from_lat) * (3.141592 / 180);
				double Cur_Lon_radian = Double.parseDouble(from_lng) * (3.141592 / 180);

				// 목표 위치 : 위도나 경도는 지구 중심을 기반으로 하는 각도이기 때문에 라디안 각도로 변환한다.
				double Dest_Lat_radian = Double.parseDouble(to_lat) * (3.141592 / 180);
				double Dest_Lon_radian = Double.parseDouble(to_lng) * (3.141592 / 180);

				double radian_distance = Math.acos(Math.sin(Cur_Lat_radian) * Math.sin(Dest_Lat_radian) + Math.cos(Cur_Lat_radian) * Math.cos(Dest_Lat_radian) * Math.cos(Cur_Lon_radian - Dest_Lon_radian));
				double radian_distance_acos = (Math.sin(Dest_Lat_radian) - Math.sin(Cur_Lat_radian) * Math.cos(radian_distance)) / (Math.cos(Cur_Lat_radian) * Math.sin(radian_distance));

				if(radian_distance_acos < -1) radian_distance_acos = -1;
				else if(radian_distance_acos > 1) radian_distance_acos = 1;

				// 목적지 이동 방향을 구한다.(현재 좌표에서 다음 좌표로 이동하기 위해서는 방향을 설정해야 한다. 라디안값이다.
				double radian_bearing = Math.acos(radian_distance_acos);        // acos의 인수로 주어지는 x는 360분법의 각도가 아닌 radian(호도)값이다.
				double true_bearing = 0;
				
				if (Math.sin(Dest_Lon_radian - Cur_Lon_radian) < 0)
				{
					true_bearing = radian_bearing * (180 / 3.141592);
					true_bearing = 360 - true_bearing;
				}
				else
				{
					true_bearing = radian_bearing * (180 / 3.141592);
				}
				
				double double_bearing = Math.round(true_bearing);
				int int_bearing = (int) double_bearing;
				
				if("17".equals(flowNum) || "18".equals(flowNum))
				{
					if(int_bearing < 90) int_bearing += 360;
					int_bearing = int_bearing - 90;
				}
				str_bearing = Integer.toString(int_bearing);
			}
		}
		else
		{
//			System.out.println("=========================null==========================");
		}
		
		return str_bearing;
	}
	
	public String addRingSide(String flowNum,String strtAngle,String endAngle) {
		String leftFlag = "S";
		String ringPhase = "";
		
		if(!"".equals(strtAngle))
		{
			if("1".equals(flowNum) || "3".equals(flowNum) || "5".equals(flowNum) || "7".equals(flowNum) || "9".equals(flowNum))
			{
				leftFlag = "L";
			}
			else if("17".equals(flowNum) || "18".equals(flowNum))
			{
				leftFlag = "P";
			}
			if(strtAngle.length() < 3) strtAngle = String.format("%03d", Integer.parseInt(strtAngle));
			if(!"".equals(endAngle) && endAngle.length() < 3) endAngle = String.format("%03d", Integer.parseInt(endAngle));
			
			ringPhase = leftFlag + strtAngle + endAngle;
		}
		else
		{
			ringPhase = "";
		}
		
		return ringPhase;
	}
	
	public String goCoordToAngle(String flowNum,String middleY,String middleX,
									String endY,String endX,String strtY,String strtX) throws Exception {
		String ringPStartAngle;
		String ringPEndAngle;
		
		/*if("17".equals(flowNum) || "18".equals(flowNum))
		{
			ringPStartAngle = calcAngle(centerY,centerX,middleY,middleX);
			ringPEndAngle   = "";
		}
		else
		{
			ringPStartAngle = calcAngle(middleY,middleX,endY,endX);
			ringPEndAngle   = calcAngle(middleY,middleX,strtY,strtX);
		}*/
		
		ringPStartAngle = calcAngle(flowNum,middleY,middleX,endY,endX);
		if("17".equals(flowNum) || "18".equals(flowNum)) ringPEndAngle = "";
		else ringPEndAngle = calcAngle(flowNum,middleY,middleX,strtY,strtX);
		
		return addRingSide(flowNum,ringPStartAngle,ringPEndAngle);
	}

	public void transAngle() throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("queryId", "transAngle");


		List<Map<String,Object>> result = commonDao.list(paramMap);
		
		for(Map<String,Object> map : result) 
		{
			
			String regionCd            = CommonUtil.checkNull(map.get("REGION_CD"),"");
			String intNo               = CommonUtil.checkNull(map.get("INT_NO"),"");
			String mapNo               = CommonUtil.checkNull(map.get("MAP_NO"),"");
			String intMainphase        = CommonUtil.checkNull(map.get("INT_MAINPHASE"),"");
			//String centerX             = CommonUtil.checkNull(map.get("CENTER_X"),"");
			//String centerY             = CommonUtil.checkNull(map.get("CENTER_Y"),"");
			String a1FlowNum           = CommonUtil.checkNull(map.get("A1_FLOW_NUM"),"");
			String a2FlowNum           = CommonUtil.checkNull(map.get("A2_FLOW_NUM"),"");
			String a3FlowNum           = CommonUtil.checkNull(map.get("A3_FLOW_NUM"),"");
			String a4FlowNum           = CommonUtil.checkNull(map.get("A4_FLOW_NUM"),"");
			String a5FlowNum           = CommonUtil.checkNull(map.get("A5_FLOW_NUM"),"");
			String a6FlowNum           = CommonUtil.checkNull(map.get("A6_FLOW_NUM"),"");
			String a7FlowNum           = CommonUtil.checkNull(map.get("A7_FLOW_NUM"),"");
			String a8FlowNum           = CommonUtil.checkNull(map.get("A8_FLOW_NUM"),"");
			String b1FlowNum           = CommonUtil.checkNull(map.get("B1_FLOW_NUM"),"");
			String b2FlowNum           = CommonUtil.checkNull(map.get("B2_FLOW_NUM"),"");
			String b3FlowNum           = CommonUtil.checkNull(map.get("B3_FLOW_NUM"),"");
			String b4FlowNum           = CommonUtil.checkNull(map.get("B4_FLOW_NUM"),"");
			String b5FlowNum           = CommonUtil.checkNull(map.get("B5_FLOW_NUM"),"");
			String b6FlowNum           = CommonUtil.checkNull(map.get("B6_FLOW_NUM"),"");
			String b7FlowNum           = CommonUtil.checkNull(map.get("B7_FLOW_NUM"),"");
			String b8FlowNum           = CommonUtil.checkNull(map.get("B8_FLOW_NUM"),"");
			
			String aRing1Phase = goCoordToAngle(a1FlowNum,
					 map.get("A_RING_1_PHASE_MIDDLE_Y").toString(),map.get("A_RING_1_PHASE_MIDDLE_X").toString(),
					 map.get("A_RING_1_PHASE_END_Y").toString(),map.get("A_RING_1_PHASE_END_X").toString(),
					 map.get("A_RING_1_PHASE_STRT_Y").toString(),map.get("A_RING_1_PHASE_STRT_X").toString());
			String aRing2Phase = goCoordToAngle(a2FlowNum,
		             map.get("A_RING_2_PHASE_MIDDLE_Y").toString(),map.get("A_RING_2_PHASE_MIDDLE_X").toString(),
		             map.get("A_RING_2_PHASE_END_Y").toString(),map.get("A_RING_2_PHASE_END_X").toString(),
		             map.get("A_RING_2_PHASE_STRT_Y").toString(),map.get("A_RING_2_PHASE_STRT_X").toString());
			String aRing3Phase = goCoordToAngle(a3FlowNum,
		             map.get("A_RING_3_PHASE_MIDDLE_Y").toString(),map.get("A_RING_3_PHASE_MIDDLE_X").toString(),
		             map.get("A_RING_3_PHASE_END_Y").toString(),map.get("A_RING_3_PHASE_END_X").toString(),
		             map.get("A_RING_3_PHASE_STRT_Y").toString(),map.get("A_RING_3_PHASE_STRT_X").toString());
			String aRing4Phase = goCoordToAngle(a4FlowNum,
		             map.get("A_RING_4_PHASE_MIDDLE_Y").toString(),map.get("A_RING_4_PHASE_MIDDLE_X").toString(),
		             map.get("A_RING_4_PHASE_END_Y").toString(),map.get("A_RING_4_PHASE_END_X").toString(),
		             map.get("A_RING_4_PHASE_STRT_Y").toString(),map.get("A_RING_4_PHASE_STRT_X").toString());
			String aRing5Phase = goCoordToAngle(a5FlowNum,
		             map.get("A_RING_5_PHASE_MIDDLE_Y").toString(),map.get("A_RING_5_PHASE_MIDDLE_X").toString(),
		             map.get("A_RING_5_PHASE_END_Y").toString(),map.get("A_RING_5_PHASE_END_X").toString(),
		             map.get("A_RING_5_PHASE_STRT_Y").toString(),map.get("A_RING_5_PHASE_STRT_X").toString());
			String aRing6Phase = goCoordToAngle(a6FlowNum,
		             map.get("A_RING_6_PHASE_MIDDLE_Y").toString(),map.get("A_RING_6_PHASE_MIDDLE_X").toString(),
		             map.get("A_RING_6_PHASE_END_Y").toString(),map.get("A_RING_6_PHASE_END_X").toString(),
		             map.get("A_RING_6_PHASE_STRT_Y").toString(),map.get("A_RING_6_PHASE_STRT_X").toString());
			String aRing7Phase = goCoordToAngle(a7FlowNum,
		             map.get("A_RING_7_PHASE_MIDDLE_Y").toString(),map.get("A_RING_7_PHASE_MIDDLE_X").toString(),
		             map.get("A_RING_7_PHASE_END_Y").toString(),map.get("A_RING_7_PHASE_END_X").toString(),
		             map.get("A_RING_7_PHASE_STRT_Y").toString(),map.get("A_RING_7_PHASE_STRT_X").toString());
			String aRing8Phase = goCoordToAngle(a8FlowNum,
		             map.get("A_RING_8_PHASE_MIDDLE_Y").toString(),map.get("A_RING_8_PHASE_MIDDLE_X").toString(),
		             map.get("A_RING_8_PHASE_END_Y").toString(),map.get("A_RING_8_PHASE_END_X").toString(),
		             map.get("A_RING_8_PHASE_STRT_Y").toString(),map.get("A_RING_8_PHASE_STRT_X").toString());
			String bRing1Phase = goCoordToAngle(b1FlowNum,
					 map.get("B_RING_1_PHASE_MIDDLE_Y").toString(),map.get("B_RING_1_PHASE_MIDDLE_X").toString(),
					 map.get("B_RING_1_PHASE_END_Y").toString(),map.get("B_RING_1_PHASE_END_X").toString(),
					 map.get("B_RING_1_PHASE_STRT_Y").toString(),map.get("B_RING_1_PHASE_STRT_X").toString());
			String bRing2Phase = goCoordToAngle(b2FlowNum,
		             map.get("B_RING_2_PHASE_MIDDLE_Y").toString(),map.get("B_RING_2_PHASE_MIDDLE_X").toString(),
		             map.get("B_RING_2_PHASE_END_Y").toString(),map.get("B_RING_2_PHASE_END_X").toString(),
		             map.get("B_RING_2_PHASE_STRT_Y").toString(),map.get("B_RING_2_PHASE_STRT_X").toString());
			String bRing3Phase = goCoordToAngle(b3FlowNum,
		             map.get("B_RING_3_PHASE_MIDDLE_Y").toString(),map.get("B_RING_3_PHASE_MIDDLE_X").toString(),
		             map.get("B_RING_3_PHASE_END_Y").toString(),map.get("B_RING_3_PHASE_END_X").toString(),
		             map.get("B_RING_3_PHASE_STRT_Y").toString(),map.get("B_RING_3_PHASE_STRT_X").toString());
			String bRing4Phase = goCoordToAngle(b4FlowNum,
		             map.get("B_RING_4_PHASE_MIDDLE_Y").toString(),map.get("B_RING_4_PHASE_MIDDLE_X").toString(),
		             map.get("B_RING_4_PHASE_END_Y").toString(),map.get("B_RING_4_PHASE_END_X").toString(),
		             map.get("B_RING_4_PHASE_STRT_Y").toString(),map.get("B_RING_4_PHASE_STRT_X").toString());
			String bRing5Phase = goCoordToAngle(b5FlowNum,
		             map.get("B_RING_5_PHASE_MIDDLE_Y").toString(),map.get("B_RING_5_PHASE_MIDDLE_X").toString(),
		             map.get("B_RING_5_PHASE_END_Y").toString(),map.get("B_RING_5_PHASE_END_X").toString(),
		             map.get("B_RING_5_PHASE_STRT_Y").toString(),map.get("B_RING_5_PHASE_STRT_X").toString());
			String bRing6Phase = goCoordToAngle(b6FlowNum,
		             map.get("B_RING_6_PHASE_MIDDLE_Y").toString(),map.get("B_RING_6_PHASE_MIDDLE_X").toString(),
		             map.get("B_RING_6_PHASE_END_Y").toString(),map.get("B_RING_6_PHASE_END_X").toString(),
		             map.get("B_RING_6_PHASE_STRT_Y").toString(),map.get("B_RING_6_PHASE_STRT_X").toString());
			String bRing7Phase = goCoordToAngle(b7FlowNum,
		             map.get("B_RING_7_PHASE_MIDDLE_Y").toString(),map.get("B_RING_7_PHASE_MIDDLE_X").toString(),
		             map.get("B_RING_7_PHASE_END_Y").toString(),map.get("B_RING_7_PHASE_END_X").toString(),
		             map.get("B_RING_7_PHASE_STRT_Y").toString(),map.get("B_RING_7_PHASE_STRT_X").toString());
			String bRing8Phase = goCoordToAngle(b8FlowNum,
		             map.get("B_RING_8_PHASE_MIDDLE_Y").toString(),map.get("B_RING_8_PHASE_MIDDLE_X").toString(),
		             map.get("B_RING_8_PHASE_END_Y").toString(),map.get("B_RING_8_PHASE_END_X").toString(),
		             map.get("B_RING_8_PHASE_STRT_Y").toString(),map.get("B_RING_8_PHASE_STRT_X").toString());
			
			Map<String,Object> ringMap = new HashMap<String,Object>();
			ringMap.put("regionCd", regionCd);
			ringMap.put("intNo", intNo);
			ringMap.put("mapNo", mapNo);
			ringMap.put("intMainphase", intMainphase);
			ringMap.put("aRing1Phase", aRing1Phase);
			ringMap.put("aRing2Phase", aRing2Phase);
			ringMap.put("aRing3Phase", aRing3Phase);
			ringMap.put("aRing4Phase", aRing4Phase);
			ringMap.put("aRing5Phase", aRing5Phase);
			ringMap.put("aRing6Phase", aRing6Phase);
			ringMap.put("aRing7Phase", aRing7Phase);
			ringMap.put("aRing8Phase", aRing8Phase);
			ringMap.put("bRing1Phase", bRing1Phase);
			ringMap.put("bRing2Phase", bRing2Phase);
			ringMap.put("bRing3Phase", bRing3Phase);
			ringMap.put("bRing4Phase", bRing4Phase);
			ringMap.put("bRing5Phase", bRing5Phase);
			ringMap.put("bRing6Phase", bRing6Phase);
			ringMap.put("bRing7Phase", bRing7Phase);
			ringMap.put("bRing8Phase", bRing8Phase);
			ringMap.put("a1FlowNum", a1FlowNum);
			ringMap.put("a2FlowNum", a2FlowNum);
			ringMap.put("a3FlowNum", a3FlowNum);
			ringMap.put("a4FlowNum", a4FlowNum);
			ringMap.put("a5FlowNum", a5FlowNum);
			ringMap.put("a6FlowNum", a6FlowNum);
			ringMap.put("a7FlowNum", a7FlowNum);
			ringMap.put("a8FlowNum", a8FlowNum);
			ringMap.put("b1FlowNum", b1FlowNum);
			ringMap.put("b2FlowNum", b2FlowNum);
			ringMap.put("b3FlowNum", b3FlowNum);
			ringMap.put("b4FlowNum", b4FlowNum);
			ringMap.put("b5FlowNum", b5FlowNum);
			ringMap.put("b6FlowNum", b6FlowNum);
			ringMap.put("b7FlowNum", b7FlowNum);
			ringMap.put("b8FlowNum", b8FlowNum);
			
			ringMap.put("queryId", "insertPhase");
			commonDao.update(ringMap);
		}
	}
	
	public String setNumberFormat(String angle) {
		if(angle.length() == 1) angle = "00" + angle;
		else if(angle.length() == 2) angle = "0" + angle;
		
		return angle;
	}
	
	public String xlsExcelReader(MultipartHttpServletRequest req, String uploadId) throws Exception {
		
		MultipartFile file = null;
		
		String regionCd = req.getParameter("uploadRegionCd");
		String resultMsg = "0";
		
		/*BATCH_JOB_DEL FLAG를 N으로 변경 시켜준다..
		 * 엑설파일 INT정보를 MERGE 하면 BATCH_JOB_DEL FLAG가 Y로 변경된다
		 * */
		Map<String,Object> paramJobMap = new HashMap<String,Object>();
		if("int".equals(uploadId))
		{
			paramJobMap.put("tableId", "TB_INT");
			paramJobMap.put("regionCd", regionCd);
			mainDao.jobDelUpdate(paramJobMap);
			file = req.getFile("intInfoUpload");
		}
		else
		{
			mainDao.deleteCoordToAngle();
			paramJobMap.put("tableId", "TB_INT_PHASE");
			paramJobMap.put("regionCd", regionCd);
			mainDao.jobDelUpdate(paramJobMap);
			file = req.getFile("phaseInfoUpload");
			
			//System.out.println("file : " + file.getOriginalFilename());
		}

		List<Map<String,String>> excelList = new ArrayList<Map<String,String>>();
		SheetHandler sheetHandler = new SheetHandler();
		
		try {
			OPCPackage opc = OPCPackage.open(file.getInputStream());
			XSSFReader xssfReader = new XSSFReader(opc);
			
			ReadOnlySharedStringsTable data = new ReadOnlySharedStringsTable(opc);
			StylesTable styles = xssfReader.getStylesTable();
			
			InputStream sheetStream = xssfReader.getSheetsData().next();
			InputSource sheetSource = new InputSource(sheetStream);
			
			ContentHandler handler = new XSSFSheetXMLHandler(styles, data, sheetHandler, false);
			
			XMLReader sheetParser = SAXHelper.newXMLReader();
			//XMLReader에 재정의하여 구현한 인터페이스 설정
	        sheetParser.setContentHandler(handler);
	        //파싱하여 처리
	        sheetParser.parse(sheetSource);
	        
	        sheetStream.close();
			opc.close();
			
			for(List<String> row : sheetHandler.getRows())
			{
				if("int".equals(uploadId))
				{
					if(row.size() != 10) 
					{
						resultMsg = "1";
						break;
					}
					else
					{
						Map<String,String> map = new HashMap<String,String>();
						map.put("regionCd",regionCd);
						map.put("intNo",row.get(0));
						map.put("intNm",row.get(1));
						map.put("intType",row.get(2));
						map.put("intLcType",row.get(3));
						map.put("intLampType",row.get(4));
						map.put("mainIntNo",row.get(5));
						map.put("groupNo",row.get(6)); 
						map.put("xCoord",row.get(7));
						map.put("yCoord",row.get(8));
						map.put("sigunguCd",row.get(9));
						
						mainDao.xlsExcelReader(uploadId,map);
						excelList.add(map);
					}
				}
				else if("phase".equals(uploadId))
				{
					if(row.size() != 115) 
					{
						resultMsg = "1";
						break;
					}
					else
					{
						Map<String,String> map = new HashMap<String,String>();
						map.put("regionCd",regionCd);
						map.put("intNo",row.get(0));
						map.put("mapNo",row.get(1));  
						map.put("intMainphase",row.get(2));
						map.put("aRing1PhaseStrtX",row.get(3));  	
						map.put("aRing1PhaseStrtY",row.get(4));  	
						map.put("aRing1PhaseMiddleX",row.get(5));  	
						map.put("aRing1PhaseMiddleY",row.get(6));  
						map.put("aRing1PhaseEndX",row.get(7));
						map.put("aRing1PhaseEndY",row.get(8));
						map.put("aRing2PhaseStrtX",row.get(9));
						map.put("aRing2PhaseStrtY",row.get(10));
						map.put("aRing2PhaseMiddleX",row.get(11));
						map.put("aRing2PhaseMiddleY",row.get(12));
						map.put("aRing2PhaseEndX",row.get(13));
						map.put("aRing2PhaseEndY",row.get(14));
						map.put("aRing3PhaseStrtX",row.get(15));
						map.put("aRing3PhaseStrtY",row.get(16));
						map.put("aRing3PhaseMiddleX",row.get(17));
						map.put("aRing3PhaseMiddleY",row.get(18));
						map.put("aRing3PhaseEndX",row.get(19));
						map.put("aRing3PhaseEndY",row.get(20));
						map.put("aRing4PhaseStrtX",row.get(21));
						map.put("aRing4PhaseStrtY",row.get(22));
						map.put("aRing4PhaseMiddleX",row.get(23));
						map.put("aRing4PhaseMiddleY",row.get(24));
						map.put("aRing4PhaseEndX",row.get(25));
						map.put("aRing4PhaseEndY",row.get(26));
						map.put("aRing5PhaseStrtX",row.get(27));
						map.put("aRing5PhaseStrtY",row.get(28));
						map.put("aRing5PhaseMiddleX",row.get(29));
						map.put("aRing5PhaseMiddleY",row.get(30));
						map.put("aRing5PhaseEndX",row.get(31));
						map.put("aRing5PhaseEndY",row.get(32));
						map.put("aRing6PhaseStrtX",row.get(33));
						map.put("aRing6PhaseStrtY",row.get(34));
						map.put("aRing6PhaseMiddleX",row.get(35));
						map.put("aRing6PhaseMiddleY",row.get(36));
						map.put("aRing6PhaseEndX",row.get(37));
						map.put("aRing6PhaseEndY",row.get(38));
						map.put("aRing7PhaseStrtX",row.get(39));
						map.put("aRing7PhaseStrtY",row.get(40));
						map.put("aRing7PhaseMiddleX",row.get(41));
						map.put("aRing7PhaseMiddleY",row.get(42));
						map.put("aRing7PhaseEndX",row.get(43));
						map.put("aRing7PhaseEndY",row.get(44));
						map.put("aRing8PhaseStrtX",row.get(45));
						map.put("aRing8PhaseStrtY",row.get(46));
						map.put("aRing8PhaseMiddleX",row.get(47));
						map.put("aRing8PhaseMiddleY",row.get(48));
						map.put("aRing8PhaseEndX",row.get(49));
						map.put("aRing8PhaseEndY",row.get(50));
						map.put("bRing1PhaseStrtX",row.get(51));
						map.put("bRing1PhaseStrtY",row.get(52));
						map.put("bRing1PhaseMiddleX",row.get(53));
						map.put("bRing1PhaseMiddleY",row.get(54));
						map.put("bRing1PhaseEndX",row.get(55));
						map.put("bRing1PhaseEndY",row.get(56));
						map.put("bRing2PhaseStrtX",row.get(57));
						map.put("bRing2PhaseStrtY",row.get(58));
						map.put("bRing2PhaseMiddleX",row.get(59));
						map.put("bRing2PhaseMiddleY",row.get(60));
						map.put("bRing2PhaseEndX",row.get(61));
						map.put("bRing2PhaseEndY",row.get(62));
						map.put("bRing3PhaseStrtX",row.get(63));
						map.put("bRing3PhaseStrtY",row.get(64));
						map.put("bRing3PhaseMiddleX",row.get(65));
						map.put("bRing3PhaseMiddleY",row.get(66));
						map.put("bRing3PhaseEndX",row.get(67));
						map.put("bRing3PhaseEndY",row.get(68));
						map.put("bRing4PhaseStrtX",row.get(69));
						map.put("bRing4PhaseStrtY",row.get(70));
						map.put("bRing4PhaseMiddleX",row.get(71));
						map.put("bRing4PhaseMiddleY",row.get(72));
						map.put("bRing4PhaseEndX",row.get(73));
						map.put("bRing4PhaseEndY",row.get(74));
						map.put("bRing5PhaseStrtX",row.get(75));
						map.put("bRing5PhaseStrtY",row.get(76));
						map.put("bRing5PhaseMiddleX",row.get(77));
						map.put("bRing5PhaseMiddleY",row.get(78));
						map.put("bRing5PhaseEndX",row.get(79));
						map.put("bRing5PhaseEndY",row.get(80));
						map.put("bRing6PhaseStrtX",row.get(81));
						map.put("bRing6PhaseStrtY",row.get(82));
						map.put("bRing6PhaseMiddleX",row.get(83));
						map.put("bRing6PhaseMiddleY",row.get(84));
						map.put("bRing6PhaseEndX",row.get(85));
						map.put("bRing6PhaseEndY",row.get(86));
						map.put("bRing7PhaseStrtX",row.get(87));
						map.put("bRing7PhaseStrtY",row.get(88));
						map.put("bRing7PhaseMiddleX",row.get(89));
						map.put("bRing7PhaseMiddleY",row.get(90));
						map.put("bRing7PhaseEndX",row.get(91));
						map.put("bRing7PhaseEndY",row.get(92));
						map.put("bRing8PhaseStrtX",row.get(93));
						map.put("bRing8PhaseStrtY",row.get(94));
						map.put("bRing8PhaseMiddleX",row.get(95));
						map.put("bRing8PhaseMiddleY",row.get(96));
						map.put("bRing8PhaseEndX",row.get(97));
						map.put("bRing8PhaseEndY",row.get(98));
						map.put("a1FlowNum",row.get(99)); 
						map.put("a2FlowNum",row.get(100)); 
						map.put("a3FlowNum",row.get(101)); 
						map.put("a4FlowNum",row.get(102));
						map.put("a5FlowNum",row.get(103));
						map.put("a6FlowNum",row.get(104));
						map.put("a7FlowNum",row.get(105));
						map.put("a8FlowNum",row.get(106));
						map.put("b1FlowNum",row.get(107));
						map.put("b2FlowNum",row.get(108));
						map.put("b3FlowNum",row.get(109));
						map.put("b4FlowNum",row.get(110));
						map.put("b5FlowNum",row.get(111));
						map.put("b6FlowNum",row.get(112));
						map.put("b7FlowNum",row.get(113));
						map.put("b8FlowNum",row.get(114));
						
						mainDao.xlsExcelReader(uploadId,map);
						excelList.add(map);
					}
				}
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
		
		if(excelList.size() > 0)
		{
			if("phase".equals(uploadId))
			{
				transAngle();
//				System.out.println("---------------------------------transAngle End---------------------------------------");
			}
			mainDao.intPhaseInfoDelete(paramJobMap);
		}
		
		return resultMsg;
	}
	
	public String xlsxExcelReader(MultipartHttpServletRequest req, String uploadId) throws Exception {
		
		MultipartFile file = null;
		
		String regionCd = req.getParameter("uploadRegionCd");
		String resultMsg = "0";
		
		/*BATCH_JOB_DEL FLAG를 N으로 변경 시켜준다..
		 * 엑설파일 INT정보를 MERGE 하면 BATCH_JOB_DEL FLAG가 Y로 변경된다
		 * */
		Map<String,Object> paramJobMap = new HashMap<String,Object>();
		if("int".equals(uploadId))
		{
			paramJobMap.put("tableId", "TB_INT");
			paramJobMap.put("regionCd", regionCd);
			mainDao.jobDelUpdate(paramJobMap);
			file = req.getFile("intInfoUpload");
		}
		else
		{
			mainDao.deleteCoordToAngle();
			paramJobMap.put("tableId", "TB_INT_PHASE");
			paramJobMap.put("regionCd", regionCd);
			mainDao.jobDelUpdate(paramJobMap);
		}
		
		if("int".equals(uploadId)) file = req.getFile("intInfoUpload");
		else file = req.getFile("phaseInfoUpload");
		
		List<Map<String,String>> excelList = new ArrayList<Map<String,String>>();
		SheetHandler sheetHandler = new SheetHandler();

		try {
			OPCPackage opc = OPCPackage.open(file.getInputStream());
			XSSFReader xssfReader = new XSSFReader(opc);
			
			ReadOnlySharedStringsTable data = new ReadOnlySharedStringsTable(opc);
			StylesTable styles = xssfReader.getStylesTable();
			
			InputStream sheetStream = xssfReader.getSheetsData().next();
			InputSource sheetSource = new InputSource(sheetStream);
			
			ContentHandler handler = new XSSFSheetXMLHandler(styles, data, sheetHandler, false);
			
			XMLReader sheetParser = SAXHelper.newXMLReader();
			//XMLReader에 재정의하여 구현한 인터페이스 설정
	        sheetParser.setContentHandler(handler);
	        //파싱하여 처리
	        sheetParser.parse(sheetSource);
	        
	        sheetStream.close();
			opc.close();

			for(List<String> row : sheetHandler.getRows())
			{
				if("int".equals(uploadId))
				{
					if(row.size() != 10) 
					{
						resultMsg = "1";
						break;
					}
					else
					{
						Map<String,String> map = new HashMap<String,String>();
						map.put("regionCd",regionCd);
						map.put("intNo",row.get(0));
						map.put("intNm",row.get(1));
						map.put("intType",row.get(2));
						map.put("intLcType",row.get(3));
						map.put("intLampType",row.get(4));
						map.put("mainIntNo",row.get(5));
						map.put("groupNo",row.get(6));
						map.put("xCoord",row.get(7));
						map.put("yCoord",row.get(8));
						map.put("sigunguCd",row.get(9));
						
						mainDao.xlsExcelReader(uploadId,map);
						excelList.add(map);
					}
				}
				else if("phase".equals(uploadId))
				{
					if(row.size() != 115) 
					{
						resultMsg = "1";
						break;
					}
					else
					{
						Map<String,String> map = new HashMap<String,String>();
						map.put("regionCd",regionCd);
						map.put("intNo",row.get(0));
						map.put("mapNo",row.get(1));  
						map.put("intMainphase",row.get(2));
						map.put("aRing1PhaseStrtX",row.get(3));  	
						map.put("aRing1PhaseStrtY",row.get(4));  	
						map.put("aRing1PhaseMiddleX",row.get(5));  	
						map.put("aRing1PhaseMiddleY",row.get(6));  
						map.put("aRing1PhaseEndX",row.get(7));
						map.put("aRing1PhaseEndY",row.get(8));
						map.put("aRing2PhaseStrtX",row.get(9));
						map.put("aRing2PhaseStrtY",row.get(10));
						map.put("aRing2PhaseMiddleX",row.get(11));
						map.put("aRing2PhaseMiddleY",row.get(12));
						map.put("aRing2PhaseEndX",row.get(13));
						map.put("aRing2PhaseEndY",row.get(14));
						map.put("aRing3PhaseStrtX",row.get(15));
						map.put("aRing3PhaseStrtY",row.get(16));
						map.put("aRing3PhaseMiddleX",row.get(17));
						map.put("aRing3PhaseMiddleY",row.get(18));
						map.put("aRing3PhaseEndX",row.get(19));
						map.put("aRing3PhaseEndY",row.get(20));
						map.put("aRing4PhaseStrtX",row.get(21));
						map.put("aRing4PhaseStrtY",row.get(22));
						map.put("aRing4PhaseMiddleX",row.get(23));
						map.put("aRing4PhaseMiddleY",row.get(24));
						map.put("aRing4PhaseEndX",row.get(25));
						map.put("aRing4PhaseEndY",row.get(26));
						map.put("aRing5PhaseStrtX",row.get(27));
						map.put("aRing5PhaseStrtY",row.get(28));
						map.put("aRing5PhaseMiddleX",row.get(29));
						map.put("aRing5PhaseMiddleY",row.get(30));
						map.put("aRing5PhaseEndX",row.get(31));
						map.put("aRing5PhaseEndY",row.get(32));
						map.put("aRing6PhaseStrtX",row.get(33));
						map.put("aRing6PhaseStrtY",row.get(34));
						map.put("aRing6PhaseMiddleX",row.get(35));
						map.put("aRing6PhaseMiddleY",row.get(36));
						map.put("aRing6PhaseEndX",row.get(37));
						map.put("aRing6PhaseEndY",row.get(38));
						map.put("aRing7PhaseStrtX",row.get(39));
						map.put("aRing7PhaseStrtY",row.get(40));
						map.put("aRing7PhaseMiddleX",row.get(41));
						map.put("aRing7PhaseMiddleY",row.get(42));
						map.put("aRing7PhaseEndX",row.get(43));
						map.put("aRing7PhaseEndY",row.get(44));
						map.put("aRing8PhaseStrtX",row.get(45));
						map.put("aRing8PhaseStrtY",row.get(46));
						map.put("aRing8PhaseMiddleX",row.get(47));
						map.put("aRing8PhaseMiddleY",row.get(48));
						map.put("aRing8PhaseEndX",row.get(49));
						map.put("aRing8PhaseEndY",row.get(50));
						map.put("bRing1PhaseStrtX",row.get(51));
						map.put("bRing1PhaseStrtY",row.get(52));
						map.put("bRing1PhaseMiddleX",row.get(53));
						map.put("bRing1PhaseMiddleY",row.get(54));
						map.put("bRing1PhaseEndX",row.get(55));
						map.put("bRing1PhaseEndY",row.get(56));
						map.put("bRing2PhaseStrtX",row.get(57));
						map.put("bRing2PhaseStrtY",row.get(58));
						map.put("bRing2PhaseMiddleX",row.get(59));
						map.put("bRing2PhaseMiddleY",row.get(60));
						map.put("bRing2PhaseEndX",row.get(61));
						map.put("bRing2PhaseEndY",row.get(62));
						map.put("bRing3PhaseStrtX",row.get(63));
						map.put("bRing3PhaseStrtY",row.get(64));
						map.put("bRing3PhaseMiddleX",row.get(65));
						map.put("bRing3PhaseMiddleY",row.get(66));
						map.put("bRing3PhaseEndX",row.get(67));
						map.put("bRing3PhaseEndY",row.get(68));
						map.put("bRing4PhaseStrtX",row.get(69));
						map.put("bRing4PhaseStrtY",row.get(70));
						map.put("bRing4PhaseMiddleX",row.get(71));
						map.put("bRing4PhaseMiddleY",row.get(72));
						map.put("bRing4PhaseEndX",row.get(73));
						map.put("bRing4PhaseEndY",row.get(74));
						map.put("bRing5PhaseStrtX",row.get(75));
						map.put("bRing5PhaseStrtY",row.get(76));
						map.put("bRing5PhaseMiddleX",row.get(77));
						map.put("bRing5PhaseMiddleY",row.get(78));
						map.put("bRing5PhaseEndX",row.get(79));
						map.put("bRing5PhaseEndY",row.get(80));
						map.put("bRing6PhaseStrtX",row.get(81));
						map.put("bRing6PhaseStrtY",row.get(82));
						map.put("bRing6PhaseMiddleX",row.get(83));
						map.put("bRing6PhaseMiddleY",row.get(84));
						map.put("bRing6PhaseEndX",row.get(85));
						map.put("bRing6PhaseEndY",row.get(86));
						map.put("bRing7PhaseStrtX",row.get(87));
						map.put("bRing7PhaseStrtY",row.get(88));
						map.put("bRing7PhaseMiddleX",row.get(89));
						map.put("bRing7PhaseMiddleY",row.get(90));
						map.put("bRing7PhaseEndX",row.get(91));
						map.put("bRing7PhaseEndY",row.get(92));
						map.put("bRing8PhaseStrtX",row.get(93));
						map.put("bRing8PhaseStrtY",row.get(94));
						map.put("bRing8PhaseMiddleX",row.get(95));
						map.put("bRing8PhaseMiddleY",row.get(96));
						map.put("bRing8PhaseEndX",row.get(97));
						map.put("bRing8PhaseEndY",row.get(98));
						map.put("a1FlowNum",row.get(99)); 
						map.put("a2FlowNum",row.get(100)); 
						map.put("a3FlowNum",row.get(101)); 
						map.put("a4FlowNum",row.get(102));
						map.put("a5FlowNum",row.get(103));
						map.put("a6FlowNum",row.get(104));
						map.put("a7FlowNum",row.get(105));
						map.put("a8FlowNum",row.get(106));
						map.put("b1FlowNum",row.get(107));
						map.put("b2FlowNum",row.get(108));
						map.put("b3FlowNum",row.get(109));
						map.put("b4FlowNum",row.get(110));
						map.put("b5FlowNum",row.get(111));
						map.put("b6FlowNum",row.get(112));
						map.put("b7FlowNum",row.get(113));
						map.put("b8FlowNum",row.get(114));
						
						mainDao.xlsExcelReader(uploadId,map);
						excelList.add(map);
					}
				}
			}
			
		} catch(Exception e) {
			
//			System.out.println("execel make Exception!!");
			
			e.printStackTrace();
		}
		
		
		if(excelList.size() > 0)
		{
			if("phase".equals(uploadId))
			{
				transAngle();
				
				//126.9419414	37.36666122	 126.941877	37.36645231	126.9418126	37.36624766
				//calcPedeAngle("37.36666122", "126.9419414", "37.36624766", "126.9418126");
				//126.941877	37.36645231	126.9418126	37.36624766
				
				/*String aRing2Phase = goCoordToAngle(a2FlowNum,
			             map.get("A_RING_2_PHASE_MIDDLE_Y").toString(),map.get("A_RING_2_PHASE_MIDDLE_X").toString(),
			             map.get("A_RING_2_PHASE_END_Y").toString(),map.get("A_RING_2_PHASE_END_X").toString(),
			             map.get("A_RING_2_PHASE_STRT_Y").toString(),map.get("A_RING_2_PHASE_STRT_X").toString());*/
				
				/*
				104 2p aring
				126.930263   37.35846639	
				126.9304796  37.35858349	
				126.9307015  37.35869627
				
				104 2p bring
				126.930694	37.35869253	
				126.9304769	37.35857609	
				126.9302545	37.35846398
				*/

				/*
				104 4p aring
				126.9303274	37.35838111	
				126.9305527	37.3585005	
				126.9307727	37.35861989
				
				104 4p bring
				126.9303274	37.35838111	
				126.9305527	37.3585005	
				126.9307727	37.35861989
				*/

				/*String aaa = goCoordToAngle("17","37.35858349","126.9304796","37.35869627","126.9307015","37.35846639","126.930263");
				String bbb = goCoordToAngle("17","37.35857609","126.9304769","37.35846398","126.9302545","37.35869253","126.930694");
				
				String ccc = goCoordToAngle("17","37.3585005","126.9305527","37.35861989","126.9307727","37.35838111","126.9303274");
				String ddd = goCoordToAngle("17","37.3585005","126.9305527","37.35861989","126.9307727","37.35838111","126.9303274");
				
				System.out.println("aRing 2p: " + aaa);
				System.out.println("bRing 2p: " + bbb);
				System.out.println("aRing 4p: " + ccc);
				System.out.println("bRing 4p: " + ddd);*/
				

				//calcAngle("37.36645231", "126.941877", "37.36624766", "126.9418126");
//				System.out.println("---------------------------------transAngle End---------------------------------------");
			}
			mainDao.intPhaseInfoDelete(paramJobMap);
		}
		
		return resultMsg;
		
	}
	
	public void getSiginfoExcelList(HttpServletRequest req, HttpServletResponse res) throws Exception {
		
		String regionCd = CommonUtil.checkNull(req.getParameter("regionCd"));
		String regionNm = CommonUtil.checkNull(req.getParameter("regionNm"));
		String intNo    = CommonUtil.checkNull(req.getParameter("intNo"));

		String filePath = req.getSession().getServletContext().getRealPath("/excelFiles");
		String fileFullPath = filePath + "/" + regionNm + "/";
		File fileDir = new File(fileFullPath);
		
		if(!fileDir.exists())
		{
			fileDir.mkdir();
		}
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", regionCd);
		paramMap.put("intNo", intNo);
		
		phaseVoList= null;
		crrsVoList = null;
		crhdVoList = null;
		cropVoList = null;
		crwdVoList = null;

		phaseInfoList(paramMap);
		crrsInfoList(paramMap);
		crhdInfoList(paramMap);
		cropInfoList(paramMap);
		crwdInfoList(paramMap);
		
		writeSiginfoExcel(req, res, regionNm);
		
		//intPosImg 삭제..
		deletePosImgs(req);
	}
	
	public void deletePosImgs(HttpServletRequest req) throws Exception {
		
		String regionCd = CommonUtil.checkNull(req.getParameter("regionCd"));
		String intNo = CommonUtil.checkNull(req.getParameter("intNo"));
		
		File imgsPath   = new File(req.getSession().getServletContext().getRealPath("/intPosImg/"+ regionCd + "_" + intNo));
		File aPhasePath = new File(req.getSession().getServletContext().getRealPath("/intPosImg/"+ regionCd + "_" + intNo +"/A"));
		File bPhasePath = new File(req.getSession().getServletContext().getRealPath("/intPosImg/"+ regionCd + "_" + intNo +"/B"));
		
		if(imgsPath.exists())
		{
			if(aPhasePath.exists())
			{
				File[] apFiles = aPhasePath.listFiles();
				for(int i = 0; i < apFiles.length; i++)
					apFiles[i].delete();
			}
			if(bPhasePath.exists())
			{
				File[] bpFiles = bPhasePath.listFiles();
				for(int j = 0; j < bpFiles.length; j++)
					bpFiles[j].delete();
			}
			File[] posFiles = imgsPath.listFiles();
			for(int k = 0; k < posFiles.length; k++)
				posFiles[k].delete();
			
			imgsPath.delete();
		}
	}
	
	public void writeSiginfoExcel(HttpServletRequest req, HttpServletResponse res, String regionNm) throws Exception {
		
		String regionCd = "";
		String intNo  = "";
		String intNm  = "";		
		String a1FlowNum = "";
		String a2FlowNum = "";
		String a3FlowNum = "";
		String a4FlowNum = "";
		String a5FlowNum = "";
		String a6FlowNum = "";
		String a7FlowNum = "";
		String a8FlowNum = "";
		String b1FlowNum = "";
		String b2FlowNum = "";
		String b3FlowNum = "";
		String b4FlowNum = "";
		String b5FlowNum = "";
		String b6FlowNum = "";
		String b7FlowNum = "";
		String b8FlowNum = "";
		
		if(phaseVoList.size() > 0)
		{
			for(int pl = 0; pl < phaseVoList.size(); pl++) 
			{
				regionCd = phaseVoList.get(pl).getREGION_CD();
				intNo  = phaseVoList.get(pl).getINT_NO();
				intNm  = phaseVoList.get(pl).getINT_NM();
				a1FlowNum = phaseVoList.get(pl).getA1_FLOW_NUM();
				a2FlowNum = phaseVoList.get(pl).getA2_FLOW_NUM();
				a3FlowNum = phaseVoList.get(pl).getA3_FLOW_NUM();
				a4FlowNum = phaseVoList.get(pl).getA4_FLOW_NUM();
				a5FlowNum = phaseVoList.get(pl).getA5_FLOW_NUM();
				a6FlowNum = phaseVoList.get(pl).getA6_FLOW_NUM();
				a7FlowNum = phaseVoList.get(pl).getA7_FLOW_NUM();
				a8FlowNum = phaseVoList.get(pl).getA8_FLOW_NUM();
				b1FlowNum = phaseVoList.get(pl).getB1_FLOW_NUM();
				b2FlowNum = phaseVoList.get(pl).getB2_FLOW_NUM();
				b3FlowNum = phaseVoList.get(pl).getB3_FLOW_NUM();
				b4FlowNum = phaseVoList.get(pl).getB4_FLOW_NUM();
				b5FlowNum = phaseVoList.get(pl).getB5_FLOW_NUM();
				b6FlowNum = phaseVoList.get(pl).getB6_FLOW_NUM();
				b7FlowNum = phaseVoList.get(pl).getB7_FLOW_NUM();
				b8FlowNum = phaseVoList.get(pl).getB8_FLOW_NUM();
				
				//교차로 이미지
				/*String phaseImg = req.getParameter("phaseImg");
				phaseImg = phaseImg.replaceAll("data:image/png;base64,", "").replaceAll(" ", "+");
				byte[] imgByte = Base64.decodeBase64(phaseImg);
				System.out.println("-------------------------------------imgByte-------------------------------------");*/
				
				ExcelUtil excel = new ExcelUtil("교차로신호운영계획입출력");
				
			    // 시작 위치
			    excel.setOffset(0, 0);
			    
			    Calendar cal = Calendar.getInstance();
			    String dDay = "";
			    if(cal.get(Calendar.DAY_OF_WEEK) == 1) dDay = "일요일";
			    else if(cal.get(Calendar.DAY_OF_WEEK) == 2) dDay = "월요일";
			    else if(cal.get(Calendar.DAY_OF_WEEK) == 3) dDay = "화요일";
			    else if(cal.get(Calendar.DAY_OF_WEEK) == 4) dDay = "수요일";
			    else if(cal.get(Calendar.DAY_OF_WEEK) == 5) dDay = "목요일";
			    else if(cal.get(Calendar.DAY_OF_WEEK) == 6) dDay = "금요일";
			    else if(cal.get(Calendar.DAY_OF_WEEK) == 7) dDay = "토요일";
			    
			    String today = cal.get(Calendar.YEAR)+"년"+(cal.get(Calendar.MONTH) + 1)+"월"+cal.get(Calendar.DAY_OF_MONTH)+"일"+" "+dDay;
		    	String groupNo = "-";
		    	String fileName = intNo+"_"+intNm;
		    	
		    	//예약계획
		    	List<Map<String,Object>> crrsList = new ArrayList<Map<String,Object>>();
		    	Map<String,Object> crrsMap = null;
		    	
		    	if(crrsVoList != null && crrsVoList.size() > 0)
		    	{
		    		groupNo = crrsVoList.get(0).getGROUP_NO();
		    		for(int i = 0; i < crrsVoList.size(); i++)
				    {
		    			crrsMap = new HashMap<String,Object>();
			    		PlanCRRSInfoVO crrsInfoVo = crrsVoList.get(i);
			    		crrsMap.put("crrsMm", crrsInfoVo.getRESRV_MM());
			    		crrsMap.put("crrsDd", crrsInfoVo.getRESRV_DD());
			    		crrsMap.put("crrsDy", crrsInfoVo.getRESRV_DY());
			    		crrsMap.put("crrsStrtHh", crrsInfoVo.getRESRV_STRT_HH());
			    		crrsMap.put("crrsStrtMi", crrsInfoVo.getRESRV_STRT_MI());
			    		crrsMap.put("crrsEndHh", crrsInfoVo.getRESRV_END_HH());
			    		crrsMap.put("crrsEndMi", crrsInfoVo.getRESRV_END_MI());
			    		crrsMap.put("crrsContrlCd", crrsInfoVo.getRESRV_CONTRL_CD());
			    		crrsMap.put("crrsPlanNo", crrsInfoVo.getRESRV_PLAN_NO());
				    	crrsList.add(crrsMap);
				    }
		    	}
		    	else
		    	{
		    		for(int ni = 0; ni < 10; ni++)
		    		{
		    			crrsMap = new HashMap<String,Object>();
		    			crrsMap.put("crrsMm", "-");
			    		crrsMap.put("crrsDd", "-");
			    		crrsMap.put("crrsDy", "-");
			    		crrsMap.put("crrsStrtHh", "-");
			    		crrsMap.put("crrsStrtMi", "-");
			    		crrsMap.put("crrsEndHh", "-");
			    		crrsMap.put("crrsEndMi", "-");
				    	crrsList.add(crrsMap);
		    		}
		    	}
		    	
			    //주간계획
			    List<Map<String,Object>> crwdList = new ArrayList<Map<String,Object>>();
			    Map<String,Object> crwdMap = null;
			    
			    if(crwdVoList != null && crwdVoList.size() > 0)
			    {
			    	for(int j = 0; j < crwdVoList.size(); j++)
				    {
			    		crwdMap = new HashMap<String,Object>();
			    		PlanCRWDInfoVO crwdInfoVo = crwdVoList.get(j);
			    		crwdMap.put("planNo", crwdInfoVo.getINT_PLAN_NO());
				    	crwdList.add(crwdMap);
				    }
			    }
			    else
		    	{
			    	for(int nj = 0; nj < 7; nj++)
			    	{
			    		crwdMap = new HashMap<String,Object>();
			    		crwdMap.put("planNo", "-");
			    		crwdList.add(crwdMap);
			    	}
		    	}
			    
			    //일계획
			    List<Map<String,Object>> cropList = new ArrayList<Map<String,Object>>();
			    Map<String,Object> cropMap = null;
			    
			    if(cropVoList != null && cropVoList.size() > 0)
			    {
			    	for(int k = 0; k < cropVoList.size(); k++)
				    {
			    		cropMap = new HashMap<String,Object>();
			    		PlanCROPInfoVO cropInfoVo = cropVoList.get(k);
			    		cropMap.put("idxNo",cropInfoVo.getINT_PLAN_IDX_NO());
			    		cropMap.put("planHh",cropInfoVo.getOPER_PLAN_HH());
			    		cropMap.put("planMi",cropInfoVo.getOPER_PLAN_MI());
			    		cropMap.put("planCycle",cropInfoVo.getINT_OPER_CYCLE_VAL());
				    	cropList.add(cropMap);
				    }
			    	if(cropList.size() < 18)
			    	{
			    		cropMap = new HashMap<String,Object>();
			    		cropMap.put("idxNo","-");
				    	cropMap.put("planHh","-");
				    	cropMap.put("planMi","-");
				    	cropMap.put("planCycle","-");
				    	cropList.add(cropMap);
				    	
				    	int restSize = 16 - cropList.size();
			    		for(int kk = 0; kk < restSize; kk++)
			    		{
			    			cropMap = new HashMap<String,Object>();
			    			cropMap.put("idxNo","-");
					    	cropMap.put("planHh","-");
					    	cropMap.put("planMi","-");
					    	cropMap.put("planCycle","-");
					    	cropList.add(cropMap);
			    		}
			    	}
			    }
			    else
		    	{
			    	for(int nk = 0; nk < 64; nk++)
			    	{
			    		cropMap = new HashMap<String,Object>();
			    		cropMap.put("idxNo","-");
				    	cropMap.put("planHh","-");
				    	cropMap.put("planMi","-");
				    	cropMap.put("planCycle","-");
				    	cropList.add(cropMap);
			    	}
		    	}
			    
			    //특수일계획
			    List<Map<String,Object>> crhdList = new ArrayList<Map<String,Object>>();
			    Map<String,Object> crhdMap = null;
		    	if(crhdVoList != null && crhdVoList.size() > 0)
			    {
			    	for(int l = 0; l < crhdVoList.size(); l++)
				    {
			    		crhdMap = new HashMap<String,Object>();
				    	PlanCRHDInfoVO crhdInfoVo = crhdVoList.get(l);
				    	crhdMap.put("planSn", crhdInfoVo.getPLAN_SN());
				    	crhdMap.put("holyMm", crhdInfoVo.getHOLYDD_PLAN_MM());
				    	crhdMap.put("holyDd", crhdInfoVo.getHOLYDD_PLAN_DD());
				    	crhdMap.put("todPln", crhdInfoVo.getINT_PLAN_NO());
				    	crhdList.add(crhdMap);
				    }
			    	if(crhdList.size() < 16)
			    	{
			    		crhdMap = new HashMap<String,Object>();
			    		int restSize = 16 - crhdList.size();
			    		for(int ll = 0; ll < restSize; ll++)
			    		{
			    			crhdMap.put("planSn", "-");
				    		crhdMap.put("holyMm", "-");
				    		crhdMap.put("holyDd", "-");
				    		crhdMap.put("todPln", "-");
					    	crhdList.add(crhdMap);
			    		}
			    	}
			    }
		    	else
		    	{
		    		for(int nl = 0; nl < 16; nl++)
		    		{
		    			crhdMap = new HashMap<String,Object>();
		    			crhdMap.put("planSn", "-");
			    		crhdMap.put("holyMm", "-");
			    		crhdMap.put("holyDd", "-");
			    		crhdMap.put("todPln", "-");
				    	crhdList.add(crhdMap);
		    		}
		    	}

		    	InputStream inputStream = null;
		    	InputStream inputStreamA = null;
		    	InputStream inputStreamB = null;
		    	File intPosImg = null;
		    	File apImg     = null;
		    	File bpImg     = null;
		    	
			    try {
			    	intPosImg = new File(req.getSession().getServletContext().getRealPath("/intPosImg/"+regionCd+"_"+intNo));
			    	inputStream = new FileInputStream(intPosImg+"/"+intNo+".png");
		            byte[] bytes = IOUtils.toByteArray(inputStream);
		            excel.setImage(bytes,3,9,0,17);
		            
		            apImg = new File(req.getSession().getServletContext().getRealPath("/intPosImg/"+regionCd+"_"+intNo+"/A"));
		            byte[] bytesA = null;
		            for(int ap = 0; ap < apImg.listFiles().length; ap++)
		            {
		            	inputStreamA = new FileInputStream(req.getSession().getServletContext().getRealPath("/intPosImg/"+regionCd+"_"+intNo+"/A")+"/ap_"+ap+".png");
			            bytesA = IOUtils.toByteArray(inputStreamA);
			            
			            if(ap == 0) excel.setImage(bytesA,5,3,18,5);
			            else if(ap == 1) excel.setImage(bytesA,5,3,23,5);
			            else if(ap == 2) excel.setImage(bytesA,5,3,28,5);
			            else if(ap == 3) excel.setImage(bytesA,5,3,33,5);
			            else if(ap == 4) excel.setImage(bytesA,5,3,38,5);
			            else if(ap == 5) excel.setImage(bytesA,5,3,43,5);
			            else if(ap == 6) excel.setImage(bytesA,5,3,48,5);
			            else if(ap == 7) excel.setImage(bytesA,5,3,53,5);
			            inputStreamA.close();
		            }
		            bpImg = new File(req.getSession().getServletContext().getRealPath("/intPosImg/"+regionCd+"_"+intNo+"/B"));
		            byte[] bytesB = null;
		            for(int bp = 0; bp < bpImg.listFiles().length; bp++)
		            {
		            	inputStreamB = new FileInputStream(req.getSession().getServletContext().getRealPath("/intPosImg/"+regionCd+"_"+intNo+"/B")+"/bp_"+bp+".png");
			            bytesB = IOUtils.toByteArray(inputStreamB);
			            if(bp == 0) excel.setImage(bytesB,8,3,18,5);
			            else if(bp == 1) excel.setImage(bytesB,8,3,23,5);
			            else if(bp == 2) excel.setImage(bytesB,8,3,28,5);
			            else if(bp == 3) excel.setImage(bytesB,8,3,33,5);
			            else if(bp == 4) excel.setImage(bytesB,8,3,38,5);
			            else if(bp == 5) excel.setImage(bytesB,8,3,43,5);
			            else if(bp == 6) excel.setImage(bytesB,8,3,48,5);
			            else if(bp == 7) excel.setImage(bytesB,8,3,48,5);
			            inputStreamB.close();
		            }
				    inputStream.close();
			    } catch(IOException ioe) {
//			    	System.out.println("---------------------IOException---------------------");
			    }

			    // 교차로위치    -----------총열수 58개--------------
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("신호제어기 모델(        )","","","","","","","","","","","","","","","","","","작성일자 : "+today+"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", (short)0, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("교차로위치","","","","","","","","","","","","","","","","","","그룹","","","","","",""+groupNo+"","","","","","","교차로번호","","","","","",""+intNo+"","","","","","","교차로명","","","","","",""+intNm+"","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","","1현시","","","","","2현시","","","","","3현시","","","","","4현시","","","","","5현시","","","","","6현시","","","","","7현시","","","","","8현시","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","",""+a1FlowNum+"","","","","",""+a2FlowNum+"","","","","",""+a3FlowNum+"","","","","",""+a4FlowNum+"","","","","",""+a5FlowNum+"","","","","",""+a6FlowNum+"","","","","",""+a7FlowNum+"","","","","",""+a8FlowNum+"","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("","","","","","","","","","","","","","","","","","",""+b1FlowNum+"","","","","",""+b2FlowNum+"","","","","",""+b3FlowNum+"","","","","",""+b4FlowNum+"","","","","",""+b5FlowNum+"","","","","",""+b6FlowNum+"","","","","",""+b7FlowNum+"","","","","",""+b8FlowNum+"","","","",""));
			    excel.addRow("ffffff", (short)0, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));

			    //주간계획
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("주간계획","","","","","","","","예약\n계획","","월","","일","","요일","","시작","","종료","","기능","","","","시차","","월","","일","","요일","","시작","","종료","","기능","","","","시차","","월","","일","","요일","","시작","","종료","","기능","","","","시차",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("월","화","수","목","금","토","일","","","",""+crrsList.get(0).get("crrsMm")+"","",""+crrsList.get(0).get("crrsDd")+"","",""+crrsList.get(0).get("crrsDy")+"","",""+crrsList.get(0).get("crrsStrtHh")+" : "+crrsList.get(0).get("crrsStrtMi")+"","",""+crrsList.get(0).get("crrsEndHh")+" : "+crrsList.get(0).get("crrsEndMi")+"",
			    		     "",""+crrsList.get(0).get("crrsContrlCd")+"","","","",""+crrsList.get(0).get("crrsPlanNo")+"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList(""+crwdList.get(0).get("planNo")+"",""+crwdList.get(1).get("planNo")+"",""+crwdList.get(2).get("planNo")+"",""+crwdList.get(3).get("planNo")+"",""+crwdList.get(4).get("planNo")+"",""+crwdList.get(5).get("planNo")+"",""+crwdList.get(6).get("planNo")+"","","","",
			    			 ""+crrsList.get(1).get("crrsMm")+"","",""+crrsList.get(1).get("crrsDd")+"","",""+crrsList.get(1).get("crrsDy")+"","",""+crrsList.get(1).get("crrsStrtHh")+" : "+crrsList.get(1).get("crrsStrtMi")+"","",""+crrsList.get(1).get("crrsEndHh")+" : "+crrsList.get(1).get("crrsEndMi")+"",
			    			 "",""+crrsList.get(1).get("crrsContrlCd")+"","","","",""+crrsList.get(1).get("crrsPlanNo")+"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    excel.addRow("ffffff", (short)0, Arrays.asList("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""));
			    
			    //일계획
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("일계획(1)","","","","","","","","","","","","일계획(2)","","","","","","","","","","","","일계획(3)","","","","","","","","","","","","일계획(4)","","","","","","","","","","","","특수일계획","","","","","","","","",""));
			    excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList("번호","","시간","","","주기","","","Index","","","","번호","","시간","","","주기","","","Index","","","","번호","","시간","","","주기","","","Index","","","","번호","","시간","","","주기","","","Index","","","","PLN","","DAY","","","","TOD PLN","","",""));
			    
			    for(int kk = 0; kk < 16; kk++)
			    {
			    	excel.addRow("ffffff", Font.BOLDWEIGHT_BOLD, Arrays.asList(""+cropList.get(kk).get("idxNo")+"","",""+cropList.get(kk).get("planHh")+" : "+cropList.get(kk).get("planMi")+"","","",""+cropList.get(kk).get("planCycle")+"","","","","","","",
			    			                                                   ""+cropList.get(16+kk).get("idxNo")+"","",""+cropList.get(16+kk).get("planHh")+" : "+cropList.get(16+kk).get("planMi")+"","","",""+cropList.get(16+kk).get("planCycle")+"","","","","","","",
			    			                                                   ""+cropList.get(32+kk).get("idxNo")+"","",""+cropList.get(32+kk).get("planHh")+" : "+cropList.get(32+kk).get("planMi")+"","","",""+cropList.get(32+kk).get("planCycle")+"","","","","","","",
			    			                                                   ""+cropList.get(48+kk).get("idxNo")+"","",""+cropList.get(48+kk).get("planHh")+" : "+cropList.get(48+kk).get("planMi")+"","","",""+cropList.get(48+kk).get("planCycle")+"","","","","","","",
			    			                                                   ""+crhdList.get(kk).get("planSn")+"","",""+crhdList.get(kk).get("holyMm")+" / "+crhdList.get(kk).get("holyDd")+"","","","",""+crhdList.get(kk).get("todPln")+"","","",""));
			    }
			    
			    // 내용
			    for(int ii = 0; ii < 18; ii++)
			    {
			    	excel.setCellWidth(ii, 500);
			    }
			    for(int jj = 18; jj < 58; jj++)
			    {
			    	excel.setCellWidth(jj, 600);
			    }
			    
			    //폰트사이즈 설정
			    //excel.setFontSize(9, 8, 13);
			    excel.setFontSize(11, 0, 3);
			    
			    //백그라운드 컬러 설정
			    excel.setBackgroundColor(11,0,2);
			    excel.setBackgroundColor(11,18,2);
			    excel.setBackgroundColor(11,30,2);
			    excel.setBackgroundColor(11,42,2);
			    excel.setBackgroundColor(11,18,3);
			    excel.setBackgroundColor(11,23,3);
			    excel.setBackgroundColor(11,28,3);
			    excel.setBackgroundColor(11,33,3);
			    excel.setBackgroundColor(11,38,3);
			    excel.setBackgroundColor(11,43,3);
			    excel.setBackgroundColor(11,48,3);
			    excel.setBackgroundColor(11,53,3);
			    excel.setBackgroundColor(11,0,13);
			    excel.setBackgroundColor(9,8,13);
			    
			    for(int bg = 10; bg < 57; bg += 2)
			    {
			    	if(bg == 14 || bg == 15 || bg == 16) excel.setBackgroundColor(9,bg,13);
			    	else excel.setBackgroundColor(11,bg,13);
			    }
			    
			    excel.setBackgroundColor(9,0,18);
			    excel.setBackgroundColor(9,2,18);
			    excel.setBackgroundColor(9,5,18);
			    excel.setBackgroundColor(9,8,18);
			    excel.setBackgroundColor(9,12,18);
			    excel.setBackgroundColor(9,14,18);
			    excel.setBackgroundColor(9,17,18);
			    excel.setBackgroundColor(9,20,18);
			    excel.setBackgroundColor(9,24,18);
			    excel.setBackgroundColor(9,26,18);
			    excel.setBackgroundColor(9,29,18);
			    excel.setBackgroundColor(9,32,18);
			    excel.setBackgroundColor(9,36,18);
			    excel.setBackgroundColor(9,38,18);
			    excel.setBackgroundColor(9,41,18);
			    excel.setBackgroundColor(9,44,18);
			    excel.setBackgroundColor(9,48,18);
			    excel.setBackgroundColor(9,50,18);
			    excel.setBackgroundColor(9,54,18);
			    
			    for(int bg1 = 5; bg1 < 58; bg1 += 12)
			    {
			    	for(int bg2 = 19; bg2 < 35; bg2++)
				    {
				    	excel.setBackgroundColor(11,bg1,bg2);
				    }
			    }
			    
			    //공백 보더 삭제..
			    excel.setCellBorder(17,0,12);
			    excel.setCellBorder(7,13,16);
			    excel.setCellBorder(10,17,35);
			    excel.setCellBorder(11,17,35);
			    excel.setCellBorder(22,17,35);
			    excel.setCellBorder(23,17,35);
			    excel.setCellBorder(34,17,35);
			    excel.setCellBorder(35,17,35);
			    excel.setCellBorder(46,17,35);
			    excel.setCellBorder(47,17,35);
			    excel.setHeight(1, (short)50);
			    excel.setHeight(12, (short)50);
			    excel.setHeight(16, (short)50);
			    
			    // 병합  merge(firstCol, firstRow, lastCol, lastRow)
			    excel.merge(0, 0, 16, 0);  //1열 신호제어기모델
			    excel.merge(18, 0, 57, 1); //1 작성일자
			    excel.merge(0, 2, 16, 2); //2 교차로위치
			    excel.merge(18, 2, 23, 2); //2 그룹
			    excel.merge(24, 2, 29, 2); //2 그룹 번호
			    excel.merge(30, 2, 35, 2); //2 교차로 
			    excel.merge(36, 2, 41, 2); //2 교차로 번호
			    excel.merge(42, 2, 47, 2); //2 교차로
			    excel.merge(48, 2, 57, 2); //2 교차로명
			    excel.merge(0, 3, 16, 11); //3 교차로이미지
			    excel.merge(18, 3, 22, 3); //3 1현시
			    excel.merge(23, 3, 27, 3); //3 2현시
			    excel.merge(28, 3, 32, 3); //3 3현시
			    excel.merge(33, 3, 37, 3); //3 4현시
			    excel.merge(38, 3, 42, 3); //3 5현시
			    excel.merge(43, 3, 47, 3); //3 6현시
			    excel.merge(48, 3, 52, 3); //3 7현시
			    excel.merge(53, 3, 57, 3); //3 8현시
			    excel.merge(18, 4, 22, 4); //4 프로그레스1
			    excel.merge(23, 4, 27, 4); //4 프로그레스2
			    excel.merge(28, 4, 32, 4); //4 프로그레스3
			    excel.merge(33, 4, 37, 4); //4 프로그레스4
			    excel.merge(38, 4, 42, 4); //4 프로그레스5
			    excel.merge(43, 4, 47, 4); //4 프로그레스6
			    excel.merge(48, 4, 52, 4); //4 프로그레스7
			    excel.merge(53, 4, 57, 4); //4 프로그레스8
			    excel.merge(18, 5, 22, 7); //5 현시1
			    excel.merge(23, 5, 27, 7); //5 현시2
			    excel.merge(28, 5, 32, 7); //5 현시3
			    excel.merge(33, 5, 37, 7); //5 현시4
			    excel.merge(38, 5, 42, 7); //5 현시5
			    excel.merge(43, 5, 47, 7); //5 현시6
			    excel.merge(48, 5, 52, 7); //5 현시7
			    excel.merge(53, 5, 57, 7); //5 현시8
			    excel.merge(18, 8, 22, 10); //6 현시8
			    excel.merge(23, 8, 27, 10); //6 현시8
			    excel.merge(28, 8, 32, 10); //6 현시8
			    excel.merge(33, 8, 37, 10); //6 현시8
			    excel.merge(38, 8, 42, 10); //6 현시8
			    excel.merge(43, 8, 47, 10); //6 현시8
			    excel.merge(48, 8, 52, 10); //6 현시8
			    excel.merge(53, 8, 57, 10); //6 현시8
			    excel.merge(18, 11, 22, 11); //7 프로그레스1
			    excel.merge(23, 11, 27, 11); //7 프로그레스2
			    excel.merge(28, 11, 32, 11); //7 프로그레스3
			    excel.merge(33, 11, 37, 11); //7 프로그레스4
			    excel.merge(38, 11, 42, 11); //7 프로그레스5
			    excel.merge(43, 11, 47, 11); //7 프로그레스6
			    excel.merge(48, 11, 52, 11); //7 프로그레스7
			    excel.merge(53, 11, 57, 11); //7 프로그레스8
			    excel.merge(0, 13, 6, 13); // 주간계획
			    excel.merge(8, 13, 9, 15); // 예약계획
			    excel.merge(10, 13, 11, 13); // 월
			    excel.merge(12, 13, 13, 13); // 일
			    excel.merge(14, 13, 15, 13); // 요일
			    excel.merge(16, 13, 17, 13); // 시작
			    excel.merge(18, 13, 19, 13); // 종료
			    excel.merge(20, 13, 23, 13); // 기능
			    excel.merge(24, 13, 25, 13); // 시차
			    excel.merge(26, 13, 27, 13); // 월
			    excel.merge(28, 13, 29, 13); // 일
			    excel.merge(30, 13, 31, 13); // 요일
			    excel.merge(32, 13, 33, 13); // 시작
			    excel.merge(34, 13, 35, 13); // 종료
			    excel.merge(36, 13, 39, 13); // 기능
			    excel.merge(40, 13, 41, 13); // 시차
			    excel.merge(42, 13, 43, 13); // 월
			    excel.merge(44, 13, 45, 13); // 일
			    excel.merge(46, 13, 47, 13); // 요일
			    excel.merge(48, 13, 49, 13); // 시작
			    excel.merge(50, 13, 51, 13); // 종료
			    excel.merge(52, 13, 55, 13); // 기능
			    excel.merge(56, 13, 57, 13); // 시차
			    excel.merge(10, 14, 11, 14); //14 월
			    excel.merge(12, 14, 13, 14); //14 일
			    excel.merge(14, 14, 15, 14); //14 요일
			    excel.merge(16, 14, 17, 14); //14 시작
			    excel.merge(18, 14, 19, 14); //14 종료
			    excel.merge(20, 14, 23, 14); //14 기능
			    excel.merge(24, 14, 25, 14); //14 시차
			    excel.merge(26, 14, 27, 14); //14 월
			    excel.merge(28, 14, 29, 14); //14 일
			    excel.merge(30, 14, 31, 14); //14 요일
			    excel.merge(32, 14, 33, 14); //14 시작
			    excel.merge(34, 14, 35, 14); //14 종료
			    excel.merge(36, 14, 39, 14); //14 기능
			    excel.merge(40, 14, 41, 14); //14 시차
			    excel.merge(42, 14, 43, 14); //14 월
			    excel.merge(44, 14, 45, 14); //14 일
			    excel.merge(46, 14, 47, 14); //14 요일
			    excel.merge(48, 14, 49, 14); //14 시작
			    excel.merge(50, 14, 51, 14); //14 종료
			    excel.merge(52, 14, 55, 14); //14 기능
			    excel.merge(56, 14, 57, 14); //14 시차
			    excel.merge(10, 15, 11, 15); //15 월
			    excel.merge(12, 15, 13, 15); //15 일
			    excel.merge(14, 15, 15, 15); //15 요일
			    excel.merge(16, 15, 17, 15); //15 시작
			    excel.merge(18, 15, 19, 15); //15 종료
			    excel.merge(20, 15, 23, 15); //15 기능
			    excel.merge(24, 15, 25, 15); //15 시차
			    excel.merge(26, 15, 27, 15); //15 월
			    excel.merge(28, 15, 29, 15); //15 일
			    excel.merge(30, 15, 31, 15); //15 요일
			    excel.merge(32, 15, 33, 15); //15 시작
			    excel.merge(34, 15, 35, 15); //15 종료
			    excel.merge(36, 15, 39, 15); //15 기능
			    excel.merge(40, 15, 41, 15); //15 시차
			    excel.merge(42, 15, 43, 15); //15 월
			    excel.merge(44, 15, 45, 15); //15 일
			    excel.merge(46, 15, 47, 15); //15 요일
			    excel.merge(48, 15, 49, 15); //15 시작
			    excel.merge(50, 15, 51, 15); //15 종료
			    excel.merge(52, 15, 55, 15); //15 기능
			    excel.merge(56, 15, 57, 15); //15 시차
			    //일계획
			    excel.merge(0, 17, 9, 17); //일계획(1)
			    excel.merge(10, 17, 11, 17); //공백
			    excel.merge(12, 17, 21, 17); //일계획(2)
			    excel.merge(22, 17, 23, 17); //공백
			    excel.merge(24, 17, 33, 17); //일계획(3)
			    excel.merge(34, 17, 35, 17); //공백
			    excel.merge(36, 17, 45, 17); //일계획(4)
			    excel.merge(46, 17, 47, 17); //공백
			    excel.merge(48, 17, 57, 17); //특수일계획
			    
			    for(int i = 18; i < 37; i++)
			    {
			    	excel.merge(0, i, 1, i); //번호
				    excel.merge(2, i, 4, i); //시간
				    excel.merge(5, i, 7, i); //주기
				    excel.merge(8, i, 9, i); //Index
				    excel.merge(10, i, 11, i); //공백
				    excel.merge(12, i, 13, i); //번호
				    excel.merge(14, i, 16, i); //시간
				    excel.merge(17, i, 19, i); //주기
				    excel.merge(20, i, 21, i); //Index
				    excel.merge(22, i, 23, i); //공백
				    excel.merge(24, i, 25, i); //번호
				    excel.merge(26, i, 28, i); //시간
				    excel.merge(29, i, 31, i); //주기
				    excel.merge(32, i, 33, i); //Index
				    excel.merge(34, i, 35, i); //공백
				    excel.merge(36, i, 37, i); //번호
				    excel.merge(38, i, 40, i); //시간
				    excel.merge(41, i, 43, i); //주기
				    excel.merge(44, i, 45, i); //Index
				    excel.merge(46, i, 47, i); //공백
				    excel.merge(48, i, 49, i); //PLN
				    excel.merge(50, i, 53, i); //DAY
				    excel.merge(54, i, 57, i); //TOD PLN
			    }
			    
			    try {
		        	String filePath = req.getSession().getServletContext().getRealPath("/excelFiles/"+regionNm+"/");
		            File xlsFile = new File(filePath,fileName+".xlsx");
		            FileOutputStream fos = new FileOutputStream(xlsFile);
		            excel.write(fos);
		            fos.close();
			    } catch(FileNotFoundException e) {
//			    	System.out.println("-------------------------FileNotFoundException Excepion!-------------------------");
			    	e.printStackTrace();
			    } catch(IOException ie) {
//			    	System.out.println("-------------------------IOException Excepion!-------------------------");
			    	ie.printStackTrace();
			    }
			}
		}
	}
	
}

class SheetHandler implements XSSFSheetXMLHandler.SheetContentsHandler {
	
	//header를 제외한 데이터부분
    private List<List<String>> rows = new ArrayList<List<String>>();

    //cell 호출시마다 쌓아놓을 1 row List
    private List<String> row = new ArrayList<String>();

    //Header 정보를 입력
    private List<String> header = new ArrayList<String>();

    //빈 값을 체크하기 위해 사용할 셀번호
    private int currentCol = -1;

    public void startRow(int rowNum) {
        //empty 값을 체크하기 위한 초기 셋팅값
        this.currentCol = -1;
    }

    public void endRow(int rowNum) {

		if(rowNum ==0) 
        {
            header = new ArrayList<String>(row);
        } 
        else 
        {
            //헤더의 길이가 현재 로우보다 더 길다면 Cell의 뒷자리가 빈값임으로 해당값만큼 공백
            if(row.size() < header.size()) 
            {
                for (int i = row.size(); i < header.size(); i++) 
                {
                    row.add("");
                }
            }
            rows.add(new ArrayList<String>(row));
        }
		row.clear();
	}

    public void cell(String columnName, String value, XSSFComment var3) {

        int iCol = (new CellReference(columnName)).getCol();
        int emptyCol = iCol - currentCol - 1;

        //읽은 Cell의 번호를 이용하여 빈Cell 자리에 빈값을 강제로 저장시켜줌

        for(int i = 0 ; i < emptyCol ; i++) 
        {
            row.add("");
        }
        currentCol = iCol;
        row.add(value);
    }

    public void headerFooter(String text, boolean isHeader, String tagName) {}
    
    public List<List<String>> getRows() {
    	return this.rows;
    }

}