package com.siginfo.controller;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.sql.BLOB;

import org.apache.poi.util.SystemOutLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.siginfo.vo.IntFlowVO;
import com.siginfo.vo.OperBean;
import com.siginfo.vo.PlanCRHDInfoVO;
import com.siginfo.vo.PlanCROPInfoVO;
import com.siginfo.vo.PlanCRRSInfoVO;
import com.siginfo.vo.PlanCRWDInfoVO;
import com.siginfo.vo.SignalInfoVO;
import com.siginfo.vo.TbIntVO;
import com.siginfo.vo.TbRegionCenterVO;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.siginfo.common.AppUtils;
import com.siginfo.common.CommonUtil;
import com.siginfo.controller.base.BaseController;
import com.siginfo.schedule.SigInfoRepository;
import com.siginfo.service.CommonService;
import com.siginfo.service.MainService;

/**
 * Handles requests for the application home page.
 */
@SuppressWarnings("deprecation")
@Controller
public class MainController extends BaseController{
	private static final Logger log = LoggerFactory.getLogger(MainController.class); 
			
	@Autowired
	private CommonService commonService;
	
	@Autowired
	private MainService mainService;
	
	@Autowired
	private SigInfoRepository sigInfoRepository;
	
	private final ObjectMapper objectMapper = new ObjectMapper();

	//매퍼를 만들자....
	
	@RequestMapping(value = "main.do", method = RequestMethod.GET)
	public String main(Locale locale, Model model, HttpServletRequest req) throws Exception {
		OperBean ob = (OperBean) req.getSession().getAttribute("OPER_INFO");
		model.addAttribute("userType",ob.getOperUserType());
		return "main";
	}

	@RequestMapping(value = "getBottomListFrame")
	public String getBottomListFrame() throws Exception {
		return "bottomListFrame";
	}

	@RequestMapping(value = "moveIntCenter.do")
	public @ResponseBody List<Map<String,Object>> moveIntCenter(HttpServletRequest req) throws Exception {

		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "moveIntCenter");

		List<Map<String,Object>> result = commonService.list(paramMap);

		return result;
	}

	@RequestMapping(value = "getSidoSignalInfo.do")
	public void getSidoSignalInfo(HttpServletRequest req, HttpServletResponse res) throws Exception {

		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("queryId", "getSidoSignalInfo");

		List<Map<String,Object>> result = commonService.list(paramMap);

		callXmlToBean(res, result);
	}

	//좌표 값 얻기 위한 테스트
	@RequestMapping(value = "getSignalCoordinate.do")
	@ResponseBody
	public List<Map<String, Object>> getSignalCoordinate(HttpServletRequest req, HttpServletResponse res) throws Exception {
		Map<String, Object> paramMap = new HashMap<>();
		//commonService.list(paramMap);
		
		paramMap.put("queryId", "getSignalCoordInfo");
		List<Map<String, Object>> resultMap = commonService.list(paramMap);
		return resultMap;
	}
	
	//좌표 값 얻기 위한 테스트
	@RequestMapping(value = "insertSignalFlowInfo.do")
	@ResponseBody
	public Map<String, Object> insertSignalFlowInfo(@RequestBody List<Map<String, Object>> paramMap) throws Exception {
		
		String msg = "";
		
			int cnt = 0;

			for (int ii = 0; ii < paramMap.size(); ii++) {
				//Map<String, Object> paramMap = new HashMap<>();
				paramMap.get(ii).put("queryId", "insertSignalFlowInfo");
				try {
					cnt += commonService.insert(paramMap.get(ii));
				}
				catch(Exception e) {
					//success = false;
					System.out.println(paramMap.get(ii));
					e.printStackTrace();
					//msg = "신호 좌표 업로드 중 오류가 발생하였습니다.\n" + e.getMessage();
				}
			}
			
			msg = "신호 좌표 업로드 정보 " + paramMap.size() + "개 중 "+ cnt + "개가 업로드 되었습니다.";
			
			Map<String, Object> resultMap = new HashMap<>();
			resultMap.put("msg", msg);
			return resultMap;
	}
	
//	@RequestMapping(value = "getSignalInfo.do")
//	public void getSignalInfo(HttpServletRequest req, HttpServletResponse res) throws Exception {
//		SigInfoRepository sigInfoRepository = (SigInfoRepository)AppUtils.getBean(SigInfoRepository.class);
//		String sidoFlag = CommonUtil.checkNull(req.getParameter("sidoFlag"));
//		Map<String, Object> paramMap = new HashMap<String, Object>();
//
//		if(!sidoFlag.equals(""))
//		{
//			if(sidoFlag.substring(0,1).equals("L"))
//			{
//				String groupNo = sidoFlag.substring(3);
//				paramMap.put("groupNo", groupNo);
//				sidoFlag = "GROUP";
//			}
//		}
//
//		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
//		paramMap.put("minX", CommonUtil.checkNull(req.getParameter("minX")));
//		paramMap.put("minY", CommonUtil.checkNull(req.getParameter("minY")));
//		paramMap.put("maxX", CommonUtil.checkNull(req.getParameter("maxX")));
//		paramMap.put("maxY", CommonUtil.checkNull(req.getParameter("maxY")));
//		paramMap.put("sidoFlag", sidoFlag);
//		paramMap.put("queryId", "getSignalInfo");
//
//		List<Map<String,Object>> result = commonService.list(paramMap);

//		callXmlToBean(res, result);
//	}
	
	@RequestMapping(value = "getSignalInfo.do")
	@ResponseBody
	public Map<String, List<Map<String, Object>>> getSignalInfo(HttpServletRequest req, HttpServletResponse res) throws Exception {
		long start = System.currentTimeMillis();
		
		String sidoFlag = CommonUtil.checkNull(req.getParameter("sidoFlag"));
		Map<String, List<Map<String, Object>>> result = new HashMap<>();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		
		if (sigInfoRepository.centerStatusList.size() > 0) {
			result.put("centerStatus", sigInfoRepository.centerStatusList);
		}
		else {
			paramMap.put("queryId", "getOnlineCenterStatus");
			result.put("centerStatus", commonService.list(paramMap));
		}
		long mid1 = System.currentTimeMillis();
		
		
		if (sigInfoRepository.sigInfoList.size() > 0) {
			Double minX = Double.parseDouble(req.getParameter("minX"));
			Double minY = Double.parseDouble(req.getParameter("minY"));
			Double maxX = Double.parseDouble(req.getParameter("maxX"));
			Double maxY = Double.parseDouble(req.getParameter("maxY"));
			String regionCd = req.getParameter("regionCd");

			List<SignalInfoVO> list = sigInfoRepository.sigInfoList; 
			List<Map<String, Object>> resultList = new ArrayList<>();
			for (SignalInfoVO vo : list) {
				Double xCoord = vo.getX_COORD();
				Double yCoord = vo.getY_COORD();
				if (xCoord < minX || xCoord > maxX || yCoord < minY || yCoord > maxY) {
					continue;
				}
				
				if ("SIDO".equals(sidoFlag)) {
					if (regionCd.equals(vo.getREGION_CD())) {
						Map<String, Object> map = this.objectMapper.convertValue(vo, Map.class);
						resultList.add(map);
					}
				}
				else {
					Map<String, Object> map = this.objectMapper.convertValue(vo, Map.class);
					resultList.add(map);
				}
			}
			result.put("signalInfo", resultList);
		}
		else {
			if(!sidoFlag.equals(""))
			{
				if(sidoFlag.substring(0,1).equals("L"))
				{
					String groupNo = sidoFlag.substring(3);
					paramMap.put("groupNo", groupNo);
					sidoFlag = "GROUP";
				}
			}

			paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
			paramMap.put("minX", CommonUtil.checkNull(req.getParameter("minX")));
			paramMap.put("minY", CommonUtil.checkNull(req.getParameter("minY")));
			paramMap.put("maxX", CommonUtil.checkNull(req.getParameter("maxX")));
			paramMap.put("maxY", CommonUtil.checkNull(req.getParameter("maxY")));
			paramMap.put("sidoFlag", sidoFlag);
			paramMap.put("queryId", "getSignalInfo");

			result.put("signalInfo",commonService.list(paramMap));
		}
		
//		log.info("EalpasdMilliSeconds: {} ms.", System.currentTimeMillis() - start);
		return result;

		//callXmlToBean(res, result);
	}

	@RequestMapping(value = "getPopSignalInfo.do")
	public void getPopSignalInfo(HttpServletRequest req, HttpServletResponse res) throws Exception {

		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "getPopSignalInfo");

		List<Map<String,Object>> result = commonService.list(paramMap);
		for(Map<String,Object> map : result)
		{
			BLOB aRing1PStrtVtxBlob = (BLOB) map.get("A_RING_1_P_STRT_VTX");
			BLOB aRing1PEndVtxBlob = (BLOB) map.get("A_RING_1_P_END_VTX");
			BLOB aRing2PStrtVtxBlob = (BLOB) map.get("A_RING_2_P_STRT_VTX");
			BLOB aRing2PEndVtxBlob = (BLOB) map.get("A_RING_2_P_END_VTX");
			BLOB aRing3PStrtVtxBlob = (BLOB) map.get("A_RING_3_P_STRT_VTX");
			BLOB aRing3PEndVtxBlob = (BLOB) map.get("A_RING_3_P_END_VTX");
			BLOB aRing4PStrtVtxBlob = (BLOB) map.get("A_RING_4_P_STRT_VTX");
			BLOB aRing4PEndVtxBlob = (BLOB) map.get("A_RING_4_P_END_VTX");
			BLOB aRing5PStrtVtxBlob = (BLOB) map.get("A_RING_5_P_STRT_VTX");
			BLOB aRing5PEndVtxBlob = (BLOB) map.get("A_RING_5_P_END_VTX");
			BLOB aRing6PStrtVtxBlob = (BLOB) map.get("A_RING_6_P_STRT_VTX");
			BLOB aRing6PEndVtxBlob = (BLOB) map.get("A_RING_6_P_END_VTX");
			BLOB aRing7PStrtVtxBlob = (BLOB) map.get("A_RING_7_P_STRT_VTX");
			BLOB aRing7PEndVtxBlob = (BLOB) map.get("A_RING_7_P_END_VTX");
			BLOB aRing8PStrtVtxBlob = (BLOB) map.get("A_RING_8_P_STRT_VTX");
			BLOB aRing8PEndVtxBlob = (BLOB) map.get("A_RING_8_P_END_VTX");
			
			BLOB bRing1PStrtVtxBlob = (BLOB) map.get("B_RING_1_P_STRT_VTX");
			BLOB bRing1PEndVtxBlob = (BLOB) map.get("B_RING_1_P_END_VTX");
			BLOB bRing2PStrtVtxBlob = (BLOB) map.get("B_RING_2_P_STRT_VTX");
			BLOB bRing2PEndVtxBlob = (BLOB) map.get("B_RING_2_P_END_VTX");
			BLOB bRing3PStrtVtxBlob = (BLOB) map.get("B_RING_3_P_STRT_VTX");
			BLOB bRing3PEndVtxBlob = (BLOB) map.get("B_RING_3_P_END_VTX");
			BLOB bRing4PStrtVtxBlob = (BLOB) map.get("B_RING_4_P_STRT_VTX");
			BLOB bRing4PEndVtxBlob = (BLOB) map.get("B_RING_4_P_END_VTX");
			BLOB bRing5PStrtVtxBlob = (BLOB) map.get("B_RING_5_P_STRT_VTX");
			BLOB bRing5PEndVtxBlob = (BLOB) map.get("B_RING_5_P_END_VTX");
			BLOB bRing6PStrtVtxBlob = (BLOB) map.get("B_RING_6_P_STRT_VTX");
			BLOB bRing6PEndVtxBlob = (BLOB) map.get("B_RING_6_P_END_VTX");
			BLOB bRing7PStrtVtxBlob = (BLOB) map.get("B_RING_7_P_STRT_VTX");
			BLOB bRing7PEndVtxBlob = (BLOB) map.get("B_RING_7_P_END_VTX");
			BLOB bRing8PStrtVtxBlob = (BLOB) map.get("B_RING_8_P_STRT_VTX");
			BLOB bRing8PEndVtxBlob = (BLOB) map.get("B_RING_8_P_END_VTX");
			
			map.put("A_RING_1_P_STRT_VTX", linkVertexText(aRing1PStrtVtxBlob));
			map.put("A_RING_1_P_END_VTX", linkVertexText(aRing1PEndVtxBlob));
			map.put("A_RING_2_P_STRT_VTX", linkVertexText(aRing2PStrtVtxBlob));
			map.put("A_RING_2_P_END_VTX", linkVertexText(aRing2PEndVtxBlob));
			map.put("A_RING_3_P_STRT_VTX", linkVertexText(aRing3PStrtVtxBlob));
			map.put("A_RING_3_P_END_VTX", linkVertexText(aRing3PEndVtxBlob));
			map.put("A_RING_4_P_STRT_VTX", linkVertexText(aRing4PStrtVtxBlob));
			map.put("A_RING_4_P_END_VTX", linkVertexText(aRing4PEndVtxBlob));
			map.put("A_RING_5_P_STRT_VTX", linkVertexText(aRing5PStrtVtxBlob));
			map.put("A_RING_5_P_END_VTX", linkVertexText(aRing5PEndVtxBlob));
			map.put("A_RING_6_P_STRT_VTX", linkVertexText(aRing6PStrtVtxBlob));
			map.put("A_RING_6_P_END_VTX", linkVertexText(aRing6PEndVtxBlob));
			map.put("A_RING_7_P_STRT_VTX", linkVertexText(aRing7PStrtVtxBlob));
			map.put("A_RING_7_P_END_VTX", linkVertexText(aRing7PEndVtxBlob));
			map.put("A_RING_8_P_STRT_VTX", linkVertexText(aRing8PStrtVtxBlob));
			map.put("A_RING_8_P_END_VTX", linkVertexText(aRing8PEndVtxBlob));
			
			map.put("B_RING_1_P_STRT_VTX", linkVertexText(bRing1PStrtVtxBlob));
			map.put("B_RING_1_P_END_VTX", linkVertexText(bRing1PEndVtxBlob));
			map.put("B_RING_2_P_STRT_VTX", linkVertexText(bRing2PStrtVtxBlob));
			map.put("B_RING_2_P_END_VTX", linkVertexText(bRing2PEndVtxBlob));
			map.put("B_RING_3_P_STRT_VTX", linkVertexText(bRing3PStrtVtxBlob));
			map.put("B_RING_3_P_END_VTX", linkVertexText(bRing3PEndVtxBlob));
			map.put("B_RING_4_P_STRT_VTX", linkVertexText(bRing4PStrtVtxBlob));
			map.put("B_RING_4_P_END_VTX", linkVertexText(bRing4PEndVtxBlob));
			map.put("B_RING_5_P_STRT_VTX", linkVertexText(bRing5PStrtVtxBlob));
			map.put("B_RING_5_P_END_VTX", linkVertexText(bRing5PEndVtxBlob));
			map.put("B_RING_6_P_STRT_VTX", linkVertexText(bRing6PStrtVtxBlob));
			map.put("B_RING_6_P_END_VTX", linkVertexText(bRing6PEndVtxBlob));
			map.put("B_RING_7_P_STRT_VTX", linkVertexText(bRing7PStrtVtxBlob));
			map.put("B_RING_7_P_END_VTX", linkVertexText(bRing7PEndVtxBlob));
			map.put("B_RING_8_P_STRT_VTX", linkVertexText(bRing8PStrtVtxBlob));
			map.put("B_RING_8_P_END_VTX", linkVertexText(bRing8PEndVtxBlob));
		}
		
		callXmlToBean(res, result);
	}
	
	public String linkVertexText(BLOB blob) throws SQLException, IOException{
		if(blob != null)
		{
			BufferedInputStream in = new BufferedInputStream(blob.getBinaryStream());
			
			int nFileSize = (int) blob.length();
			
			byte[] buf = new byte[nFileSize];
			
			in.read(buf, 0, nFileSize);
			
			in.close();
			
			String contents = new String(buf);
			
			return contents;
		}
		else
		{
			return "";
		}
	}

	@RequestMapping(value = "sigInfoDetail.do", method = RequestMethod.GET)
	public String sigInfoDetail() throws Exception {
		
		return "sigInfoDetail";
	}
	
	//HOLYDAY PLAN
	@RequestMapping(value = "getCrhdInfoList.do")
	public @ResponseBody List<PlanCRHDInfoVO> getCrhdInfoList(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		
		List<PlanCRHDInfoVO> crhdVoList = mainService.crhdInfoList(paramMap);
		
		return crhdVoList;
	}

	//예약 설정 정보
	@RequestMapping(value = "getCrrsInfoList.do")
	public @ResponseBody List<PlanCRRSInfoVO> getCrrsInfoList(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		
		List<PlanCRRSInfoVO> crrsVoList = mainService.crrsInfoList(paramMap);
		
		return crrsVoList; 
	}
	
	//WEEK PLAN
	@RequestMapping(value = "getCrwdInfoList.do")
	public @ResponseBody List<PlanCRWDInfoVO> getCrwdInfoList(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		
		List<PlanCRWDInfoVO> crwdVoList = mainService.crwdInfoList(paramMap);
		
		return crwdVoList; 
	}
	
	//DAY PLAN
	@RequestMapping(value = "getCropInfoList.do")
	public @ResponseBody List<PlanCROPInfoVO> setDayPlanDetail(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("planNo", CommonUtil.checkNull(req.getParameter("planNo")));
	    paramMap.put("queryId", "getDayInfo");
		
		return mainService.cropInfoList(paramMap);
	}
		
	@RequestMapping(value = "getTodayPlanNo.do")
	public @ResponseBody String getTodayPlanNo(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("today", CommonUtil.checkNull(req.getParameter("today")));
		paramMap.put("queryId", "getTodayPlanNo");
		
		return commonService.selectOne(paramMap); 
	}
	
	@RequestMapping(value = "sigInfoPhaseDetail.do", method = RequestMethod.GET)
	public String sigInfoPhaseDetail(Model model, HttpServletRequest req) throws Exception {
		
		String regionNm = CommonUtil.checkNull(new String(req.getParameter("regionNm").getBytes("8859_1"),"UTF-8"));
		String intNm = CommonUtil.checkNull(new String(req.getParameter("intNm").getBytes("8859_1"),"UTF-8"));
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "getSimulFlag");
		
		model.addAttribute("regionCd",CommonUtil.checkNull(req.getParameter("regionCd")));
		model.addAttribute("regionNm",regionNm);
		model.addAttribute("intNo",CommonUtil.checkNull(req.getParameter("intNo")));
		model.addAttribute("intNm",intNm);
		model.addAttribute("yCoord",CommonUtil.checkNull(req.getParameter("yCoord")));
		model.addAttribute("xCoord",CommonUtil.checkNull(req.getParameter("xCoord")));
		model.addAttribute("groupNo",CommonUtil.checkNull(req.getParameter("groupNo")));
		
		List<Map<String,Object>> resultList = commonService.list(paramMap);
		String simulMap = "";
		String mapNo = "";
		String mapNoStatus = "0";
		
		if(resultList.size() > 0)
		{
			Map<String,Object> map = resultList.get(0);
			simulMap = map.get("SIMUL_FLAG").toString();
			mapNoStatus = (map.get("MAP_NO_STATUS") == null) ? "" : map.get("MAP_NO_STATUS").toString();
		}
		
		model.addAttribute("simulFlag", simulMap);
		model.addAttribute("mapNo", mapNo);
		model.addAttribute("mapNoStatus", mapNoStatus);
		model.addAttribute("resultList", resultList);
		
		return "sigInfoPhaseDetail";
	}
		
	@RequestMapping(value = "getSigInfoPhaseDetail.do")
	public @ResponseBody List<Map<String,Object>> getSigInfoPhaseDetail(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("mapNo", CommonUtil.checkNull(req.getParameter("mapNo")));
		paramMap.put("queryId", "getSigInfoPhaseDetail");
		
		List<Map<String,Object>> list = commonService.list(paramMap);
		
		return list;
		
	}
	
	@RequestMapping(value = "getTodInfoDetail.do")
	public @ResponseBody List<Map<String,Object>> getTodInfoDetail(HttpServletRequest req) throws Exception {
		
		String mapNo = CommonUtil.checkNull(req.getParameter("mapNo"));
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("mapNo", mapNo);
		paramMap.put("queryId", "getTodInfoDetail");
		
		List<Map<String,Object>> list = commonService.list(paramMap);
		for(Map<String,Object> map : list)
		{
			map.put("MAP_NO", mapNo);
		}
		
		return list;
		
	}
	
		
	@RequestMapping(value = "goSigInfoDetail.do")
	public @ResponseBody List<Map<String,Object>> goSigInfoDetail(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "goSigInfoDetail");
		
		List<Map<String,Object>> list = commonService.list(paramMap);
		
		return list;
		
	}
		
	@RequestMapping(value = "updateCenter.do", method = RequestMethod.GET)
	public String updateCenter() throws Exception {
		
		return "updateCenter";
	}
	
	@RequestMapping(value = "getCenterList.do")
	public @ResponseBody List<Map<String,Object>> getCenterList() throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("queryId", "getCenterList");
		
		List<Map<String,Object>> list = commonService.list(paramMap);
		
		return list;
		
	}
	
	@RequestMapping(value = "updateCenter.do")
	public @ResponseBody void updateCenter(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("regionNm", CommonUtil.checkNull(req.getParameter("regionNm")));
		paramMap.put("centerId", CommonUtil.checkNull(req.getParameter("centerId")));
		paramMap.put("centerPw", CommonUtil.checkNull(req.getParameter("centerPw")));
		paramMap.put("updDt", CommonUtil.checkNull(req.getParameter("updDt")));
		paramMap.put("simulFlag", CommonUtil.checkNull(req.getParameter("simulFlag")));
		paramMap.put("xCoord", CommonUtil.checkNull(req.getParameter("xCoord")));
		paramMap.put("yCoord", CommonUtil.checkNull(req.getParameter("yCoord")));
		paramMap.put("queryId", "updateCenter");
		
		commonService.update(paramMap);
	}
	
	@RequestMapping(value = "delCenter.do")
	public @ResponseBody void delCenter(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("queryId", "delCenter");
		
		commonService.update(paramMap);
	}
	
	@RequestMapping(value = "insertCenter.do")
	public @ResponseBody void insertCenter(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("regionNm", CommonUtil.checkNull(req.getParameter("regionNm")));
		paramMap.put("centerId", CommonUtil.checkNull(req.getParameter("centerId")));
		paramMap.put("centerPw", CommonUtil.checkNull(req.getParameter("centerPw")));
		paramMap.put("regionId", CommonUtil.checkNull(req.getParameter("regionId")));
		paramMap.put("updDt", CommonUtil.checkNull(req.getParameter("updDt")));
		paramMap.put("simulFlag", CommonUtil.checkNull(req.getParameter("simulFlag")));
		paramMap.put("xCoord", CommonUtil.checkNull(req.getParameter("xCoord")));
		paramMap.put("yCoord", CommonUtil.checkNull(req.getParameter("yCoord")));
		paramMap.put("queryId", "insertCenter");
		
		commonService.update(paramMap);
	}
	
	@RequestMapping(value = "openEventHistory.do", method = RequestMethod.GET)
	public String openEventHistory(Model model) throws Exception {
		Date d = new Date();
		SimpleDateFormat yyyymmdd = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat hh = new SimpleDateFormat("HH");
		SimpleDateFormat mm = new SimpleDateFormat("mm");
		String today = yyyymmdd.format(d);
		String hour = hh.format(d);
		String min = mm.format(d);
		
		Map<String,Object> paramMap1 = new HashMap<String,Object>();
		paramMap1.put("queryId", "getRegionCd");
		
		model.addAttribute("today",today);
		model.addAttribute("hour",hour);
		model.addAttribute("min",min);
		model.addAttribute("regionCd",commonService.list(paramMap1));
		
		return "eventHistory";
	}
	
	@RequestMapping(value = "getEventHistory.do")
	public @ResponseBody List<Map<String,Object>> getEventHistory(HttpServletRequest req) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("collctDtimeS", CommonUtil.checkNull(req.getParameter("collctDtimeS")));
		paramMap.put("collctDtimeE", CommonUtil.checkNull(req.getParameter("collctDtimeE")));
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		
		if(!"".equals(req.getParameter("eventCd"))) 
		{
			String[] eventCdArr = req.getParameter("eventCd").split(",");
			paramMap.put("eventCd1", eventCdArr[0]);
			paramMap.put("eventCd2", eventCdArr[1]);
		}
		else
		{
			paramMap.put("eventCd1", "");
		}
		
		paramMap.put("queryId", "getEventHistory");

		List<Map<String,Object>> regionCodeMapList = commonService.getQuery("getRegionCd");
		List<Map<String,Object>> eventCodeMapList  = commonService.getQuery("getEventCd");
		Map<String, String> regionMap = new HashMap<>();
		Map<String, String> eventMap  = new HashMap<>();
		
		if (regionCodeMapList.size() > 0) {
			for (Map<String, Object> map : regionCodeMapList) {
				regionMap.put((String)map.get("REGION_CD"), (String)map.get("REGION_NM"));
			}
		}
		
		if (eventCodeMapList.size() > 0) {
			for (Map<String, Object> map : eventCodeMapList) {
				eventMap.put((String)map.get("SUB_CD"), (String)map.get("CD_NM"));
			}
		}
		
		List<Map<String,Object>> resultMapList     = commonService.list(paramMap);
		
		for (Map<String, Object> map : resultMapList) {
			map.put("EVENT_CD", "");
			map.put("REGION_NM", "");
			if (map.get("CODE") != null && eventMap.get((String)map.get("CODE")) != null) {
				map.put("EVENT_CD", eventMap.get((String)map.get("CODE")));
			}
			
			if (map.get("REGION_CD") != null && regionMap.get((String)map.get("REGION_CD")) != null) {
				map.put("REGION_NM", regionMap.get((String)map.get("REGION_CD")));
			}
			
		}
		return resultMapList;
	}
	
	@RequestMapping(value = "getSignalMap.do")
	public @ResponseBody List<Map<String,Object>> getSignalMap(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("mapNo", CommonUtil.checkNull(req.getParameter("mapNo")));
		paramMap.put("queryId", "getSignalMap");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "updateSignal.do")
	public String getSigUpt(Model model, HttpServletRequest req) throws Exception {
		
		if(!"".equals(req.getParameter("regionCd")))
		{
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
			paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
			paramMap.put("queryId", "getUpdateSigObj");
			List<Map<String,Object>> list = commonService.list(paramMap);

			model.addAttribute("regionCd",list.get(0).get("REGION_CD"));
			model.addAttribute("intNo",list.get(0).get("INT_NO"));
			model.addAttribute("intNm",list.get(0).get("INT_NM"));
			model.addAttribute("intLcType",list.get(0).get("INT_LCTYPE"));
			model.addAttribute("intLampType",list.get(0).get("INT_LAMPTYPE"));
			model.addAttribute("mainIntNo",list.get(0).get("MAIN_INTNO"));
			model.addAttribute("groupNo",list.get(0).get("GROUP_NO"));
			model.addAttribute("xCoord",list.get(0).get("X_COORD"));
			model.addAttribute("yCoord",list.get(0).get("Y_COORD"));
			model.addAttribute("sigunguCd",list.get(0).get("SIGUNGU_CD"));
			model.addAttribute("networkType",list.get(0).get("NETWORK_TYPE"));
			model.addAttribute("modemIp",list.get(0).get("MODEM_IP"));
			model.addAttribute("intMainPhase",list.get(0).get("INT_MAINPHASE"));
		}
		
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		paramMap2.put("queryId", "getCenterList");
		List<Map<String,Object>> centerList = commonService.list(paramMap2);
		
		model.addAttribute("centerList",centerList);
		
		return "updateSignal";
	}
	
	@RequestMapping(value = "getMapNo.do")
	public @ResponseBody List<Map<String,Object>> getMapNo(HttpServletRequest req) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "getSimulFlag");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "getSigunguList.do")
	public @ResponseBody List<Map<String,Object>> getSigunguList(HttpServletRequest req) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String regionCd = CommonUtil.checkNull(req.getParameter("regionCd"));
		paramMap.put("regionCd", regionCd);
		paramMap.put("queryId", "getSigunguList");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "getIntNo.do")
	public @ResponseBody List<Map<String,Object>> getIntNo(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("pageCnt", CommonUtil.checkNull(req.getParameter("pageCnt")));
		paramMap.put("queryId", "getIntNo");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "getEventIntNo.do")
	public @ResponseBody List<Map<String,Object>> getEventIntNo(HttpServletRequest req) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("strtIntNo", CommonUtil.checkNull(req.getParameter("strtIntNo")));
		paramMap.put("endIntNo", CommonUtil.checkNull(req.getParameter("endIntNo")));
		paramMap.put("queryId", "getEventIntNo");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "goStaticMap.do")
	public String goStaticMap(Model model, HttpServletRequest req) throws Exception {
		model.addAttribute("regionCd",CommonUtil.checkNull(req.getParameter("regionCd")));
		model.addAttribute("regionNm",CommonUtil.checkNull(new String(req.getParameter("regionNm").getBytes("8859_1"),"UTF-8")));
		model.addAttribute("strtIntNo",CommonUtil.checkNull(req.getParameter("strtIntNo")));
		model.addAttribute("endIntNo",CommonUtil.checkNull(req.getParameter("endIntNo")));
		
		return "staticMap";
	}
	
	@RequestMapping(value = "getEventCd.do")
	public @ResponseBody List<Map<String,Object>> getEventCd() throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("queryId", "getEventCd");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "saveIntMap.do")
	public @ResponseBody void saveIntMap(HttpServletRequest req) throws Exception {
		
		String regionCd = req.getParameter("regionCd");
		String intNo    = req.getParameter("intNo");
		
		File filePath   = 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(filePath.exists())
		{
			File[] files = filePath.listFiles();
			if(files.length > 0)
			{
				for(int i = 0; i < files.length; i++)
				{
					files[i].delete();
				}
			}
			filePath.delete();
		}
		else
		{
			filePath.mkdirs();
			aPhasePath.mkdir();
			bPhasePath.mkdir();
		}
		
		String img = req.getParameter("mapImg");
		
		if(req.getParameter("aPhaseArr") != null)
		{
			String[] aPhaseArr = req.getParameter("aPhaseArr").split(",");
			String[] bPhaseArr = req.getParameter("bPhaseArr").split(",");
			
	        CommonUtil.makeImg(img, filePath, regionCd, intNo);
	        
	        for(int ii = 0; ii < aPhaseArr.length; ii++)
	        {
	        	CommonUtil.makeImg(aPhaseArr[ii], aPhasePath, regionCd, "ap_"+ii);
	        }
	        
	        for(int ii = 0; ii < bPhaseArr.length; ii++)
	        {
	        	CommonUtil.makeImg(bPhaseArr[ii], bPhasePath, regionCd, "bp_"+ii);
	        }
	        
		} 
	}
	
	@RequestMapping(value = "saveAddInt.do")
	public @ResponseBody void saveAddInt(HttpServletRequest req) throws Exception {
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		Map<String, Object> paramMap2 = new HashMap<String, Object>();
		
		String regionCd  = CommonUtil.checkNull(req.getParameter("regionCd"));
		String intNo     = CommonUtil.checkNull(req.getParameter("intNo"));
		String mainIntNo = CommonUtil.checkNull(req.getParameter("mainIntNo"));
		String groupNo   = CommonUtil.checkNull(req.getParameter("grpNo"));
		String intType   = CommonUtil.checkNull(req.getParameter("intType"));
		
		paramMap.put("regionCd", regionCd);
		paramMap.put("intNo", intNo);
		paramMap.put("intNm", CommonUtil.checkNull(req.getParameter("intNm")));
		paramMap.put("intType", intType);
		paramMap.put("intLcType", CommonUtil.checkNull(req.getParameter("intLcType")));
		paramMap.put("intLampType", CommonUtil.checkNull(req.getParameter("intLampType")));
		paramMap.put("mainIntNo", mainIntNo);
		paramMap.put("grpNo", groupNo);
		paramMap.put("xCoord", CommonUtil.checkNull(req.getParameter("xCoord")));
		paramMap.put("yCoord", CommonUtil.checkNull(req.getParameter("yCoord")));
		paramMap.put("sigunguCd", CommonUtil.checkNull(req.getParameter("sigunguCd")));
		paramMap.put("intNetworkType", CommonUtil.checkNull(req.getParameter("intNetworkType")));
		paramMap.put("intModemIp", CommonUtil.checkNull(req.getParameter("intModemIp")));
		paramMap.put("queryId", "saveAddInt");
		
		paramMap2.put("regionCd", regionCd);
		paramMap2.put("intNo", intNo);
		paramMap2.put("intMainphase", CommonUtil.checkNull(req.getParameter("intMainphase")));
		paramMap2.put("queryId", "saveAddIntPhase");
		
		commonService.update(paramMap);
		commonService.update(paramMap2);
		
	}
	
	@RequestMapping(value = "updateAddInt.do")
	public @ResponseBody void updateAddInt(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("intNm", CommonUtil.checkNull(req.getParameter("intNm")));
		paramMap.put("intType", CommonUtil.checkNull(req.getParameter("intType")));
		paramMap.put("intLcType", CommonUtil.checkNull(req.getParameter("intLcType")));
		paramMap.put("intLampType", CommonUtil.checkNull(req.getParameter("intLampType")));
		paramMap.put("mainIntNo", CommonUtil.checkNull(req.getParameter("mainIntNo")));
		paramMap.put("grpNo", CommonUtil.checkNull(req.getParameter("grpNo")));
		paramMap.put("xCoord", CommonUtil.checkNull(req.getParameter("xCoord")));
		paramMap.put("yCoord", CommonUtil.checkNull(req.getParameter("yCoord")));
		paramMap.put("sigunguCd", CommonUtil.checkNull(req.getParameter("sigunguCd")));
		paramMap.put("intNetworkType", CommonUtil.checkNull(req.getParameter("intNetworkType")));
		paramMap.put("intModemIp", CommonUtil.checkNull(req.getParameter("intModemIp")));
		paramMap.put("queryId", "updateAddInt");
		
		Map<String,Object> paramMap2 = new HashMap<String,Object>();
		paramMap2.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap2.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap2.put("intMainphase", CommonUtil.checkNull(req.getParameter("intMainphase")));
		paramMap2.put("queryId", "updateAddMainphase");
		
		commonService.update(paramMap);
		commonService.update(paramMap2);
	}
	
	@RequestMapping(value = "checkAddSig.do")
	public @ResponseBody boolean checkAddSig(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "checkAddSig");
		
		List<Map<String,Object>> result = commonService.list(paramMap);
		
		boolean resultFlag = false;
		if(result.size() > 0) resultFlag = true;
		
		return resultFlag;
	}
	
	@RequestMapping(value = "deleteSigInfo.do")
	public @ResponseBody void deleteSigInfo(HttpServletRequest req) throws Exception {
		String regionCd = CommonUtil.checkNull(req.getParameter("regionCd"));
		String intNo    = CommonUtil.checkNull(req.getParameter("intNo"));
		String mainIntNo = CommonUtil.checkNull(req.getParameter("mainIntNo"));
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		Map<String,Object> paramMap2 = new HashMap<String,Object>();
		Map<String,Object> paramMap3 = new HashMap<String,Object>();
		
		paramMap.put("regionCd", regionCd);
		paramMap.put("intNo", intNo);
		paramMap.put("queryId", "deleteSigInfo");
		
		paramMap2.put("regionCd", regionCd);
		paramMap2.put("intNo", intNo);
		paramMap2.put("queryId", "deleteAddIntPhase");
		
		commonService.update(paramMap);
		commonService.update(paramMap2);
		
		if(mainIntNo.equals("0"))
		{
			paramMap3.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
			paramMap3.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
			paramMap3.put("queryId", "deleteAddIntStatus");
			commonService.update(paramMap3);
		}
	}
	
	@RequestMapping(value = "savePhaseInfo.do")
	public @ResponseBody void savePhaseInfo(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("mapNo", CommonUtil.checkNull(req.getParameter("mapNo")));
		paramMap.put("phaseColumn", CommonUtil.checkNull(req.getParameter("phaseColumn")));
		paramMap.put("phaseCd", CommonUtil.checkNull(req.getParameter("phaseCd")));
		paramMap.put("queryId", "savePhaseInfo");
		commonService.update(paramMap);
	}
		
	@RequestMapping(value = "getLinkVtx.do")
	public @ResponseBody List<Map<String,Object>> getLinkVtx(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("sigunguCd", CommonUtil.checkNull(req.getParameter("sigunguCd")));
		paramMap.put("queryId", "getLinkVtx");
		List<Map<String,Object>> result = commonService.list(paramMap);
		
		for(Map<String,Object> map : result)
		{
			map.put("VERTEX", linkVertexText((BLOB) map.get("VERTEX")));
		}
		
		return result;
	}
	
	@RequestMapping(value = "getSelctLinkVtx.do")
	public @ResponseBody String getSelctLinkVtx(HttpServletRequest req) throws Exception {
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("linkId", CommonUtil.checkNull(req.getParameter("linkId")));
		paramMap.put("queryId", "getSelctLinkVtx");
		
		List<Map<String,Object>> resultList = commonService.list(paramMap);
		String result = "";
		if(resultList.size() > 0)
		{
			BLOB obj = (BLOB) resultList.get(0).get("VERTEX"); 
			result = linkVertexText(obj);
		}
		return result;
	}
	
	@RequestMapping(value = "updateLinkCd.do")
	public @ResponseBody void updateLinkCd(HttpServletRequest req) throws Exception {
		Map<String,Object> paramMap = new HashMap<String,Object>();
		
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("linkId", CommonUtil.checkNull(req.getParameter("linkId")));
		paramMap.put("linkCd", CommonUtil.checkNull(req.getParameter("linkCd")));
		paramMap.put("mapNo", CommonUtil.checkNull(req.getParameter("mapNo")));
		paramMap.put("queryId", "updateLinkCd");
		
		commonService.update(paramMap);
	}
	
	/*신호각도데이터 좌표로 변환*/
	
	@RequestMapping(value = "getCoordData.do")
	public void getCoordData(HttpServletResponse response) throws Exception {
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("queryId", "getCoordData");
		List<Map<String,Object>> result = commonService.list(paramMap);
		
		callXmlToBean(response, result);
	}
	
	@RequestMapping(value = "setSigCoord.do")
	public @ResponseBody List<Map<String,Object>> setSigCoord(HttpServletRequest req) throws Exception {
		Map<String,Object> paramMap = new HashMap<String,Object>();
		
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("mapNo", CommonUtil.checkNull(req.getParameter("mapNo")));
		paramMap.put("aRingPhase1StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase1StrtX")));
		paramMap.put("aRingPhase1StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase1StrtY")));
		paramMap.put("aRingPhase1MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase1MiddleX")));
		paramMap.put("aRingPhase1MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase1MiddleY")));
		paramMap.put("aRingPhase1EndX", CommonUtil.checkNull(req.getParameter("aRingPhase1EndX")));
		paramMap.put("aRingPhase1EndY", CommonUtil.checkNull(req.getParameter("aRingPhase1EndY")));
		paramMap.put("aRingPhase2StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase2StrtX")));
		paramMap.put("aRingPhase2StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase2StrtY")));
		paramMap.put("aRingPhase2MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase2MiddleX")));
		paramMap.put("aRingPhase2MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase2MiddleY")));
		paramMap.put("aRingPhase2EndX", CommonUtil.checkNull(req.getParameter("aRingPhase2EndX")));
		paramMap.put("aRingPhase2EndY", CommonUtil.checkNull(req.getParameter("aRingPhase2EndY")));
		paramMap.put("aRingPhase3StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase3StrtX")));
		paramMap.put("aRingPhase3StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase3StrtY")));
		paramMap.put("aRingPhase3MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase3MiddleX")));
		paramMap.put("aRingPhase3MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase3MiddleY")));
		paramMap.put("aRingPhase3EndX", CommonUtil.checkNull(req.getParameter("aRingPhase3EndX")));
		paramMap.put("aRingPhase3EndY", CommonUtil.checkNull(req.getParameter("aRingPhase3EndY")));
		paramMap.put("aRingPhase4StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase4StrtX")));
		paramMap.put("aRingPhase4StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase4StrtY")));
		paramMap.put("aRingPhase4MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase4MiddleX")));
		paramMap.put("aRingPhase4MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase4MiddleY")));
		paramMap.put("aRingPhase4EndX", CommonUtil.checkNull(req.getParameter("aRingPhase4EndX")));
		paramMap.put("aRingPhase4EndY", CommonUtil.checkNull(req.getParameter("aRingPhase4EndY")));
		paramMap.put("aRingPhase5StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase5StrtX")));
		paramMap.put("aRingPhase5StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase5StrtY")));
		paramMap.put("aRingPhase5MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase5MiddleX")));
		paramMap.put("aRingPhase5MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase5MiddleY")));
		paramMap.put("aRingPhase5EndX", CommonUtil.checkNull(req.getParameter("aRingPhase5EndX")));
		paramMap.put("aRingPhase5EndY", CommonUtil.checkNull(req.getParameter("aRingPhase5EndY")));
		paramMap.put("aRingPhase6StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase6StrtX")));
		paramMap.put("aRingPhase6StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase6StrtY")));
		paramMap.put("aRingPhase6MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase6MiddleX")));
		paramMap.put("aRingPhase6MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase6MiddleY")));
		paramMap.put("aRingPhase6EndX", CommonUtil.checkNull(req.getParameter("aRingPhase6EndX")));
		paramMap.put("aRingPhase6EndY", CommonUtil.checkNull(req.getParameter("aRingPhase6EndY")));
		paramMap.put("aRingPhase7StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase7StrtX")));
		paramMap.put("aRingPhase7StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase7StrtY")));
		paramMap.put("aRingPhase7MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase7MiddleX")));
		paramMap.put("aRingPhase7MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase7MiddleY")));
		paramMap.put("aRingPhase7EndX", CommonUtil.checkNull(req.getParameter("aRingPhase7EndX")));
		paramMap.put("aRingPhase7EndY", CommonUtil.checkNull(req.getParameter("aRingPhase7EndY")));
		paramMap.put("aRingPhase8StrtX", CommonUtil.checkNull(req.getParameter("aRingPhase8StrtX")));
		paramMap.put("aRingPhase8StrtY", CommonUtil.checkNull(req.getParameter("aRingPhase8StrtY")));
		paramMap.put("aRingPhase8MiddleX", CommonUtil.checkNull(req.getParameter("aRingPhase8MiddleX")));
		paramMap.put("aRingPhase8MiddleY", CommonUtil.checkNull(req.getParameter("aRingPhase8MiddleY")));
		paramMap.put("aRingPhase8EndX", CommonUtil.checkNull(req.getParameter("aRingPhase8EndX")));
		paramMap.put("aRingPhase8EndY", CommonUtil.checkNull(req.getParameter("aRingPhase8EndY")));
		paramMap.put("bRingPhase1StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase1StrtX")));
		paramMap.put("bRingPhase1StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase1StrtY")));
		paramMap.put("bRingPhase1MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase1MiddleX")));
		paramMap.put("bRingPhase1MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase1MiddleY")));
		paramMap.put("bRingPhase1EndX", CommonUtil.checkNull(req.getParameter("bRingPhase1EndX")));
		paramMap.put("bRingPhase1EndY", CommonUtil.checkNull(req.getParameter("bRingPhase1EndY")));                 
		paramMap.put("bRingPhase2StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase2StrtX")));
		paramMap.put("bRingPhase2StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase2StrtY")));
		paramMap.put("bRingPhase2MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase2MiddleX")));
		paramMap.put("bRingPhase2MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase2MiddleY")));
		paramMap.put("bRingPhase2EndX", CommonUtil.checkNull(req.getParameter("bRingPhase2EndX")));
		paramMap.put("bRingPhase2EndY", CommonUtil.checkNull(req.getParameter("bRingPhase2EndY")));
		paramMap.put("bRingPhase3StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase3StrtX")));
		paramMap.put("bRingPhase3StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase3StrtY")));
		paramMap.put("bRingPhase3MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase3MiddleX")));
		paramMap.put("bRingPhase3MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase3MiddleY")));
		paramMap.put("bRingPhase3EndX", CommonUtil.checkNull(req.getParameter("bRingPhase3EndX")));
		paramMap.put("bRingPhase3EndY", CommonUtil.checkNull(req.getParameter("bRingPhase3EndY")));
		paramMap.put("bRingPhase4StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase4StrtX")));
		paramMap.put("bRingPhase4StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase4StrtY")));
		paramMap.put("bRingPhase4MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase4MiddleX")));
		paramMap.put("bRingPhase4MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase4MiddleY")));
		paramMap.put("bRingPhase4EndX", CommonUtil.checkNull(req.getParameter("bRingPhase4EndX")));
		paramMap.put("bRingPhase4EndY", CommonUtil.checkNull(req.getParameter("bRingPhase4EndY")));
		paramMap.put("bRingPhase5StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase5StrtX")));
		paramMap.put("bRingPhase5StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase5StrtY")));
		paramMap.put("bRingPhase5MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase5MiddleX")));
		paramMap.put("bRingPhase5MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase5MiddleY")));
		paramMap.put("bRingPhase5EndX", CommonUtil.checkNull(req.getParameter("bRingPhase5EndX")));
		paramMap.put("bRingPhase5EndY", CommonUtil.checkNull(req.getParameter("bRingPhase5EndY")));
		paramMap.put("bRingPhase6StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase6StrtX")));
		paramMap.put("bRingPhase6StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase6StrtY")));
		paramMap.put("bRingPhase6MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase6MiddleX")));
		paramMap.put("bRingPhase6MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase6MiddleY")));
		paramMap.put("bRingPhase6EndX", CommonUtil.checkNull(req.getParameter("bRingPhase6EndX")));
		paramMap.put("bRingPhase6EndY", CommonUtil.checkNull(req.getParameter("bRingPhase6EndY")));
		paramMap.put("bRingPhase7StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase7StrtX")));
		paramMap.put("bRingPhase7StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase7StrtY")));
		paramMap.put("bRingPhase7MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase7MiddleX")));
		paramMap.put("bRingPhase7MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase7MiddleY")));
		paramMap.put("bRingPhase7EndX", CommonUtil.checkNull(req.getParameter("bRingPhase7EndX")));
		paramMap.put("bRingPhase7EndY", CommonUtil.checkNull(req.getParameter("bRingPhase7EndY")));
		paramMap.put("bRingPhase8StrtX", CommonUtil.checkNull(req.getParameter("bRingPhase8StrtX")));
		paramMap.put("bRingPhase8StrtY", CommonUtil.checkNull(req.getParameter("bRingPhase8StrtY")));
		paramMap.put("bRingPhase8MiddleX", CommonUtil.checkNull(req.getParameter("bRingPhase8MiddleX")));
		paramMap.put("bRingPhase8MiddleY", CommonUtil.checkNull(req.getParameter("bRingPhase8MiddleY")));
		paramMap.put("bRingPhase8EndX", CommonUtil.checkNull(req.getParameter("bRingPhase8EndX")));
		paramMap.put("bRingPhase8EndY", CommonUtil.checkNull(req.getParameter("bRingPhase8EndY")));

		paramMap.put("queryId", "setSigCoord");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "transAngle.do")
	public @ResponseBody void transAngle() throws Exception {
		mainService.transAngle();
	}
	
	//시군구 데이터 추가..
	@RequestMapping(value = "setSigunguData.do")
	public @ResponseBody void setSigunguData(HttpServletRequest req) throws Exception {
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("sigunguCd", CommonUtil.checkNull(req.getParameter("sigunguCd")));
		paramMap.put("sigunguNm", CommonUtil.checkNull(req.getParameter("sigunguNm")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "setSigunguData");
		
		commonService.update(paramMap);
	}
	
	
	@RequestMapping(value = "addLinkVertex.do")
	public @ResponseBody void addLinkVertex() throws Exception {
		
		BufferedReader br = null;
		List<String> list = new ArrayList<String>();
        String filePath = "c:\\LINK_VERTEX_181026.txt";
        
         try {
            br = new BufferedReader(new FileReader(filePath));
            String line = null;
            
            while ((line = br.readLine()) != null) {
            	list.add(line.toString());
            }
 
        } catch (IOException ioe) {
            System.out.println(ioe.getMessage());
        } finally {
            try { 
                if (br!=null) 
                    br.close(); 
            } catch (Exception e) {}
        }
		
        for(String col : list) {
        	
        	String [] listData = col.split("\\|");
        	byte[] byteConent = listData[2].getBytes();
        	
        	Map<String,Object> map = new HashMap<String,Object>();
        	map.put("linkId", listData[0]);
        	map.put("vertexCnt", listData[1]);
        	map.put("vertex", byteConent);
        	map.put("queryId", "addLinkVertex");
        	commonService.update(map);
        }
        
	}
	
	@RequestMapping(value = "writeSiginfoExcel.do")
	public @ResponseBody void writeSiginfoExcel(HttpServletRequest req, HttpServletResponse res) throws Exception {
		mainService.getSiginfoExcelList(req,res);
	}
	
	@RequestMapping(value = "deletePosImgs.do")
	public @ResponseBody void deletePosImgs(HttpServletRequest req) throws Exception {
		mainService.deletePosImgs(req);
	}
	
	@RequestMapping(value = "intInfoUpload.do")
	public @ResponseBody String intInfoUpload(MultipartHttpServletRequest req) throws Exception{
		
		String fileType = req.getParameter("intInfoFileType");
		String uploadId = "int";
		String resultMsg = "";
		
		if(fileType.equals("xls"))
		{
			resultMsg = mainService.xlsExcelReader(req,uploadId);
		}
		else if(fileType.equals("xlsx"))
		{
			resultMsg = mainService.xlsxExcelReader(req,uploadId);
		}
		
		return resultMsg;
	
	}
	
	@RequestMapping(value = "phaseInfoUpload.do")
	public @ResponseBody String phaseInfoUpload(MultipartHttpServletRequest req) throws Exception{
		
		String fileType = req.getParameter("phaseInfoFileType");
		String uploadId = "phase";
		String resultMsg = "";
		
		if(fileType.equals("xls"))
		{
			resultMsg = mainService.xlsExcelReader(req,uploadId);
		}
		else if(fileType.equals("xlsx"))
		{
			resultMsg = mainService.xlsxExcelReader(req,uploadId);
		}
		
		return resultMsg;
	}
	
	@RequestMapping(value = "/getExcelUploadFrame.do")
	public String getExcelUploadFrame(Model model) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("queryId", "getCenterList");
		
		List<Map<String,Object>> list = commonService.list(paramMap);
		model.addAttribute("centerList",list);
		
		return "excelUpload";
	}
	
	@RequestMapping(value = "updateSigunguCd.do")
	public @ResponseBody void updateSigunguCd(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("sigunguCd", CommonUtil.checkNull(req.getParameter("sigunguCd")));
		paramMap.put("queryId", "updateSigunguCd");
		
		commonService.update(paramMap);
	}
	
	@RequestMapping(value = "getCvibInfo.do")
	public @ResponseBody List<Map<String,Object>> getCvibInfo(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		String[] regionCdArr = req.getParameter("regionCd").split(",");
		String[] intNoArr    = req.getParameter("intNo").split(",");
		
		paramMap.put("regionCdArr", regionCdArr);
		paramMap.put("intNoArr", intNoArr);
		paramMap.put("queryId", "getCvibInfo");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "cvibInfoDetail.do")
	public String cvibInfoDetail() throws Exception {
		return "cvibtest";
	}
	
	@RequestMapping(value = "getCvibInfoDetail.do")
	public @ResponseBody List<Map<String,Object>> getCvibInfoDetail(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("queryId", "getCvibInfoDetail");
		
		return commonService.list(paramMap);
	}
	
	@RequestMapping(value = "getCvibEventHistory.do")
	public @ResponseBody List<Map<String,Object>> getCvibEventHistory(HttpServletRequest req) throws Exception {
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("collctDtimeS", CommonUtil.checkNull(req.getParameter("collctDtimeS")));
		paramMap.put("collctDtimeE", CommonUtil.checkNull(req.getParameter("collctDtimeE")));
		paramMap.put("regionCd", CommonUtil.checkNull(req.getParameter("regionCd")));
		paramMap.put("intNo", CommonUtil.checkNull(req.getParameter("intNo")));
		paramMap.put("eventCd", CommonUtil.checkNull(req.getParameter("eventCd")));
		paramMap.put("queryId", "getCvibEventHistory");
		
		return commonService.list(paramMap);
	}
	
}
