package com.its.wthr.service;

import com.its.app.utils.SysUtils;
import com.its.wthr.config.AtmpConfig;
import com.its.wthr.mapper.AtmpMapper;
import com.its.wthr.openApi.arpltnInforInqireService.MsrStnAcctoRltmMesureDnsty;
import com.its.wthr.openApi.arpltnInforInqireService.entity.AtmpItem;
import com.its.wthr.process.DbmsJobData;
import com.its.wthr.process.DbmsJobProcess;
import com.its.wthr.process.DbmsJobType;
import com.its.wthr.repository.AppRepository;
import com.its.wthr.ui.MainUI;
import com.its.wthr.vo.AtmpPltnSttsVo;
import com.its.wthr.vo.AtmpPltnVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.annotation.PostConstruct;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@RequiredArgsConstructor
@Service
@Transactional(rollbackFor = {Exception.class})
public class AtmpService extends AbstractXmlService {

    private final AtmpMapper mapper;
    private final AtmpConfig config;
    private final DbmsJobProcess dbmsJobProcess;

    @PostConstruct
    private void postConstruct() {
        log.info("init");
        if (this.config.isEnabled()) {
            load();
        }
    }

    public void load() {
        try {
            for (Map.Entry<String, AtmpPltnVo> e : AppRepository.getInstance().getAtmpPltnMap().entrySet()) {
                e.getValue().setDEL_YN("Y");
            }

            List<AtmpPltnVo> infoList = this.mapper.selectAll();
            for (AtmpPltnVo obj : infoList) {
                AppRepository.getInstance().getAtmpPltnMap().put(obj.getATMP_STTN_NMBR(), obj);
            }
            for (Map.Entry<String, AtmpPltnVo> e : AppRepository.getInstance().getAtmpPltnMap().entrySet()) {
                e.getValue().setRequestResult(1);
//                log.info("{}", e.getValue());
            }
        }
        catch (Exception e) {
            log.error("{}", e.getMessage());
        }
    }

    public void doJob() {
        if (!this.config.isEnabled()) {
            return;
        }

        String sysTime = SysUtils.getSysTimeStr();
        log.info("AtmpService doJob Start...{}", Thread.currentThread().getName());

        int errCnt = 0;
        List<AtmpPltnSttsVo> atmpPltnSttsList = new ArrayList<>();
        try {
            log.info("AtmpService.doJbo: {} EA", AppRepository.getInstance().getAtmpPltnMap().size());
            for (Map.Entry<String, AtmpPltnVo> e : AppRepository.getInstance().getAtmpPltnMap().entrySet()) {
                AtmpPltnVo obj = e.getValue();
                if (obj.getDEL_YN().equals("Y")) continue;

                MsrStnAcctoRltmMesureDnsty request = new MsrStnAcctoRltmMesureDnsty();
                boolean result = request.getMsrStnAcctoRltmMesureDnsty(this.config.getApiKey(), obj.getATMP_STTN_NM(), this.config.getApiVer());
                if (result) {
                    AtmpItem item = request.getItem();
                    AtmpPltnSttsVo stts = new AtmpPltnSttsVo();

                    stts.setATMP_STTN_NMBR(obj.getATMP_STTN_NMBR());
                    stts.setMSRM_DT(item.getDataTime());
                    stts.setMSRM_SYST_NM(item.getMangName());
                    stts.setCO_VAL(item.getCoValue());
                    stts.setSO2_VAL(item.getSo2Value());
                    stts.setNO2_VAL(item.getNo2Value());
                    stts.setO3_VAL(item.getO3Value());
                    stts.setPM10_VAL(item.getPm10Value());
                    stts.setPM10_24HH_VAL(item.getPm10Value24());
                    stts.setPM25_VAL(item.getPm25Value());
                    stts.setPM25_24HH_VAL(item.getPm25Value24());
                    stts.setINTG_ATMP_VAL(item.getKhaiValue());
                    stts.setINTG_ATMP_GRAD(item.getKhaiGrade());
                    stts.setSO2_GRAD(item.getSo2Grade());
                    stts.setCO_GRAD(item.getCoGrade());
                    stts.setO3_GRAD(item.getO3Grade());
                    stts.setNO2_GRAD(item.getNo2Grade());
                    stts.setPM10_24HH_GRAD(item.getPm10Grade());
                    stts.setPM25_24HH_GRAD(item.getPm25Grade());
                    stts.setPM10_1HH_GRAD(item.getPm10Grade1h());
                    stts.setPM25_1HH_GRAD(item.getPm25Grade1h());
                    stts.setUPDT_DT(SysUtils.getSysTime());

                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(1);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(stts.toString());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(stts.getValue());

                    atmpPltnSttsList.add(stts);
                }
                else {
                    errCnt++;
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(0);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(request.getErrorMsg());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(request.getErrorMsg());
                }
            }
        }
        catch(Exception e) {
            log.error("AtmpService.doJob: {}", e.toString());
        }

        if (!atmpPltnSttsList.isEmpty()) {
            this.dbmsJobProcess.add(new DbmsJobData(DbmsJobType.DATA_TYPE_ATMP, false, atmpPltnSttsList, atmpPltnSttsList.size()));
        }

        //////////////
        ////////////// 네트워크 또는 기상청 서버 오류로 인한 오류가 발생했을 경우 재시도
        //////////////
        if (errCnt > 0) {
            List<AtmpPltnSttsVo> atmpPltnSttsList2 = new ArrayList<>();
            errCnt = 0;

            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                log.error("AtmpService doJob thread sleep exception");
            }

            for (Map.Entry<String, AtmpPltnVo> e : AppRepository.getInstance().getAtmpPltnMap().entrySet()) {
                AtmpPltnVo obj = e.getValue();
                if (obj.getRequestResult() == 1) {
                    continue;
                }

                log.info("AtmpService.doJob-retry: {}-{}", obj.getATMP_STTN_NMBR(), obj.getATMP_STTN_NM());
                MsrStnAcctoRltmMesureDnsty request = new MsrStnAcctoRltmMesureDnsty();
                boolean result = request.getMsrStnAcctoRltmMesureDnsty(this.config.getApiKey(), obj.getATMP_STTN_NM(), this.config.getApiVer());
                if (result) {
                    AtmpItem item = request.getItem();
                    AtmpPltnSttsVo stts = new AtmpPltnSttsVo();

                    stts.setATMP_STTN_NMBR(obj.getATMP_STTN_NMBR());
                    stts.setMSRM_DT(item.getDataTime());
                    stts.setMSRM_SYST_NM(item.getMangName());
                    stts.setCO_VAL(item.getCoValue());
                    stts.setSO2_VAL(item.getSo2Value());
                    stts.setNO2_VAL(item.getNo2Value());
                    stts.setO3_VAL(item.getO3Value());
                    stts.setPM10_VAL(item.getPm10Value());
                    stts.setPM10_24HH_VAL(item.getPm10Value24());
                    stts.setPM25_VAL(item.getPm25Value());
                    stts.setPM25_24HH_VAL(item.getPm25Value24());
                    stts.setINTG_ATMP_VAL(item.getKhaiValue());
                    stts.setINTG_ATMP_GRAD(item.getKhaiGrade());
                    stts.setSO2_GRAD(item.getSo2Grade());
                    stts.setCO_GRAD(item.getCoGrade());
                    stts.setO3_GRAD(item.getO3Grade());
                    stts.setNO2_GRAD(item.getNo2Grade());
                    stts.setPM10_24HH_GRAD(item.getPm10Grade());
                    stts.setPM25_24HH_GRAD(item.getPm25Grade());
                    stts.setPM10_1HH_GRAD(item.getPm10Grade1h());
                    stts.setPM25_1HH_GRAD(item.getPm25Grade1h());
                    stts.setUPDT_DT(SysUtils.getSysTime());

                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(1);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(stts.toString());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(stts.getValue());

                    atmpPltnSttsList2.add(stts);
                }
                else {
                    errCnt++;
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(0);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(request.getErrorMsg());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(request.getErrorMsg());
                }

                if (!atmpPltnSttsList2.isEmpty()) {
                    this.dbmsJobProcess.add(new DbmsJobData(DbmsJobType.DATA_TYPE_ATMP, false, atmpPltnSttsList2, atmpPltnSttsList2.size()));
                }
            }
        }
        log.info("AtmpService doJob ..End...");

        MainUI UI = MainUI.getInstance();
        if (UI != null) {
            UI.updateAtmpPltnStts(sysTime);
        }
    }

    public void doJob_XML() {
        if (!this.config.isEnabled()) {
            return;
        }

        String sysTime = SysUtils.getSysTimeStr();
        log.info("AtmpService doJob Start...");

        //load();

        int errCnt = 0;
        //List<AtmpPltnSttsVo> atmpPltnSttsList = Collections.synchronizedList(new ArrayList<>());
        List<AtmpPltnSttsVo> atmpPltnSttsList = new ArrayList<>();
        try {
            log.info("AtmpService.doJbo: {} EA", AppRepository.getInstance().getAtmpPltnMap().size());
            for (Map.Entry<String, AtmpPltnVo> e : AppRepository.getInstance().getAtmpPltnMap().entrySet()) {
                AtmpPltnVo obj = e.getValue();
                if (obj.getDEL_YN().equals("Y")) continue;

                //log.info("AtmpService.doJob: {}-{}", obj.getATMP_STTN_NMBR(), obj.getATMP_STTN_NM());
                try {
                    AtmpPltnSttsVo stts = requestJob(obj);
                    if (stts != null) {
                        atmpPltnSttsList.add(stts);
                    } else {
                        errCnt++;
                    }
                }
                catch(Exception e1) {
                    errCnt++;
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(0);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(e1.toString());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(e1.toString());
                    log.error("AtmpService.doJob: getAtmpInfo, {}: {}, {}", obj.getATMP_STTN_NMBR(), obj.getATMP_STTN_NM(), e1.toString());
                }
            }
        }
        catch(Exception e) {
            log.error("AtmpService.doJob: {}", e.toString());
        }

        if (atmpPltnSttsList.size() > 0) {
            this.dbmsJobProcess.add(new DbmsJobData(DbmsJobType.DATA_TYPE_ATMP, false, atmpPltnSttsList, atmpPltnSttsList.size()));
        }

        //////////////
        ////////////// 네트워크 또는 기상청 서버 오류로 인한 오류가 발생했을 경우 재시도
        //////////////
        if (errCnt > 0) {
            //List<AtmpPltnSttsVo> atmpPltnSttsList2 = Collections.synchronizedList(new ArrayList<>());
            List<AtmpPltnSttsVo> atmpPltnSttsList2 = new ArrayList<>();
            errCnt = 0;

            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                log.error("AtmpService doJob thread sleep exception");
            }

            for (Map.Entry<String, AtmpPltnVo> e : AppRepository.getInstance().getAtmpPltnMap().entrySet()) {
                AtmpPltnVo obj = e.getValue();
                if (obj.getRequestResult() == 1) {
                    continue;
                }

                log.info("AtmpService.doJob-retry: {}-{}", obj.getATMP_STTN_NMBR(), obj.getATMP_STTN_NM());
                try {
                    AtmpPltnSttsVo stts = requestJob(obj);
                    if (stts != null) {
                        atmpPltnSttsList2.add(stts);
                    } else {
                        errCnt++;
                    }
                }
                catch (Exception e1) {
                    errCnt++;
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(0);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(e.toString());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(e.toString());
                    log.error("AtmpService.doJob-retry:, {}: {}, Exception: {}", obj.getATMP_STTN_NMBR(), obj.getATMP_STTN_NM(), e1.toString());
                }

                if (atmpPltnSttsList2.size() > 0) {
                    this.dbmsJobProcess.add(new DbmsJobData(DbmsJobType.DATA_TYPE_ATMP, false, atmpPltnSttsList2, atmpPltnSttsList2.size()));
                }
            }
        }
        log.info("AtmpService doJob ..End...");

        MainUI UI = MainUI.getInstance();
        if (UI != null) {
            UI.updateAtmpPltnStts(sysTime);
        }
    }

    public AtmpPltnSttsVo requestJob(AtmpPltnVo obj) {
        AtmpPltnSttsVo stts = null;
        try {
            //log.info("AtmpService.requestJob: {}-{}", obj.getATMP_STTN_NMBR(), obj.getATMP_STTN_NM());
            try {
                AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestTime(SysUtils.getSysTimeStr());

                stts = getAtmpInfo(obj.getATMP_STTN_NM(), obj.getATMP_STTN_NMBR());
                if (stts != null && stts.getATMP_STTN_NMBR().equals(obj.getATMP_STTN_NMBR())) {
                    stts.setATMP_STTN_NMBR(obj.getATMP_STTN_NMBR());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(1);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(stts.toString());
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(stts.getValue());
                }
                else {
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(0);
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue("");
                    AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue("");
                }
            }
            catch(Exception e) {
                AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestResult(0);
                AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setRequestValue(e.toString());
                AppRepository.getInstance().getAtmpPltnMap().get(obj.getATMP_STTN_NMBR()).setValue(e.toString());
                log.error("AtmpService.requestJob: {}: {}, Exception: {}", obj.getATMP_STTN_NMBR(), obj.getATMP_STTN_NM(), e.toString());
            }
        }
        catch(Exception e) {
            log.error("AtmpService.requestJob: Exception: {}", e.toString());
        }

        return stts;
    }

    AtmpPltnSttsVo getAtmpInfo(String atmpSttnNm, String atmpNmbr) {
        String atmpSttnNmUTF8 = atmpSttnNm;
        try {
            atmpSttnNmUTF8 = URLEncoder.encode(atmpSttnNm, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            log.error("{}, {}", atmpSttnNm, e.toString());
            atmpSttnNmUTF8 = atmpSttnNm;
        }
        //            https://apis.data.go.kr/B552584/ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty
        //            ?serviceKey=2y3qwo%2BwhlG6E%2BZfcyDKLMCr5Lp4gy%2BNgGuvWmgAdq7O%2Bf%2Fs4DPQz2ZD1rzDLowBq%2F6pfSi5F6UWlyM5meRiaw%3D%3D
        //            &returnType=json
        //            &numOfRows=100&
        //            pageNo=1
        //            &stationName=%EB%AA%85%EB%A5%9C%EB%8F%99
        //            &dataTerm=DAILY
        //            &ver=1.3
        String url = "http://apis.data.go.kr/B552584/ArpltnInforInqireSvc/getMsrstnAcctoRltmMesureDnsty?";
        url = url + "serviceKey=" + this.config.getApiKey();
        url = url + "&returnType=xml";
        url = url + "&numOfRows=1";
        url = url + "&pageNo=1";
        url = url + "&stationName=" + atmpSttnNmUTF8;
        url = url + "&dataTerm=DAILY";
        url = url + "&ver=" + this.config.getApiVer();

        log.info("AtmpService.getAtmpInfo: {}: {}, {}", atmpNmbr, atmpSttnNm, url);

        NodeList list = getXmlNodeList(url, "item");
        if (list == null || list.getLength() == 0) {
            log.error("AtmpService.getAtmpInfo: nodeList null");
            return null;
        }

        log.info("AtmpService.getAtmpInfo: {}, list.getLength: {} EA", atmpSttnNm, list.getLength());
        AtmpPltnSttsVo stts = new AtmpPltnSttsVo();

        try {
            for (int ii = 0; ii < list.getLength(); ii++) {
                Node node = list.item(ii);
                if (node.getNodeType() != 1)
                    continue;

                Element element = (Element)node;

                stts.setATMP_STTN_NMBR(atmpNmbr);

                String msrmDt = element.getElementsByTagName("dataTime").item(0).getTextContent().trim();
                msrmDt = msrmDt.replaceAll("-", "");
                msrmDt = msrmDt.replaceAll(":", "");
                msrmDt = msrmDt.replaceAll(" ", "");
                msrmDt = msrmDt  + "00";
                //YYYYMMDDHHMISS
                //0123456789
                String HH = msrmDt.substring(8, 10);
                //logger.info("HOUR {} {}", msrmDt, HH);
                if (HH.equals("24"))
                {
                    // XML로 받아올때 24시인경우 날짜가 변경되지 않고 24로 넘어오기 때문에 00시로 바꿔주기위해...
                    SimpleDateFormat sdformat = new SimpleDateFormat("yyyyMMddHHmmss");
                    //                        String sDateTime = msrmDt.substring(0,4) + "-" +
                    //             		           msrmDt.substring(4,6) + "-" +
                    //             		           msrmDt.substring(6,8) + " " +
                    //                                "23:00:00";
                    String sDateTime = msrmDt.substring(0,8) + "230000";
                    Date date = null;
                    try {
                        date = sdformat.parse(sDateTime);
                    } catch (ParseException e) {
                        log.error("getAtmpInfo ParseException exception");
                    }
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    cal.add(Calendar.HOUR, 1);
                    msrmDt = new SimpleDateFormat("yyyyMMddHHmmss").format(cal.getTime());
                    log.info("24 HOUR {} ==> {}", sDateTime, msrmDt);
                }
                stts.setMSRM_DT(msrmDt);

                stts.setMSRM_SYST_NM(element.getElementsByTagName("mangName").item(0).getTextContent().trim());
                stts.setCO_VAL(element.getElementsByTagName("coValue").item(0).getTextContent().trim());
                stts.setSO2_VAL(element.getElementsByTagName("so2Value").item(0).getTextContent().trim());
                stts.setNO2_VAL(element.getElementsByTagName("no2Value").item(0).getTextContent().trim());
                stts.setO3_VAL(element.getElementsByTagName("o3Value").item(0).getTextContent().trim());
                stts.setPM10_VAL(element.getElementsByTagName("pm10Value").item(0).getTextContent().trim());
                stts.setPM10_24HH_VAL(element.getElementsByTagName("pm10Value24").item(0).getTextContent().trim());
                stts.setPM25_VAL(element.getElementsByTagName("pm25Value").item(0).getTextContent().trim());
                stts.setPM25_24HH_VAL(element.getElementsByTagName("pm25Value24").item(0).getTextContent().trim());
                stts.setINTG_ATMP_VAL(element.getElementsByTagName("khaiValue").item(0).getTextContent().trim());
                stts.setINTG_ATMP_GRAD(element.getElementsByTagName("khaiGrade").item(0).getTextContent().trim());
                stts.setSO2_GRAD(element.getElementsByTagName("so2Grade").item(0).getTextContent().trim());
                stts.setCO_GRAD(element.getElementsByTagName("coGrade").item(0).getTextContent().trim());
                stts.setO3_GRAD(element.getElementsByTagName("o3Grade").item(0).getTextContent().trim());
                stts.setNO2_GRAD(element.getElementsByTagName("no2Grade").item(0).getTextContent().trim());
                stts.setPM10_24HH_GRAD(element.getElementsByTagName("pm10Grade").item(0).getTextContent().trim());
                stts.setPM25_24HH_GRAD(element.getElementsByTagName("pm25Grade").item(0).getTextContent().trim());
                stts.setPM10_1HH_GRAD(element.getElementsByTagName("pm10Grade1h").item(0).getTextContent().trim());
                stts.setPM25_1HH_GRAD(element.getElementsByTagName("pm25Grade1h").item(0).getTextContent().trim());
                stts.setUPDT_DT(SysUtils.getSysTime());
            }
        }
        catch (Exception e) {
            log.error("{}, {}", atmpSttnNm, e.toString());
            return null;
        }
        //log.info("AtmpService.getAtmpInfo: {} ==> {}", atmpSttnNm, stts.toString());
        return stts;
    }
/*
    public static void requestFrcs() throws IOException {
        StringBuilder urlBuilder = new StringBuilder("http://apis.data.go.kr/1360000/VilageFcstInfoService/getVilageFcst"); *//*URL*//*
        urlBuilder.append("?" + URLEncoder.encode("ServiceKey","UTF-8") + "=2y3qwo%2BwhlG6E%2BZfcyDKLMCr5Lp4gy%2BNgGuvWmgAdq7O%2Bf%2Fs4DPQz2ZD1rzDLowBq%2F6pfSi5F6UWlyM5meRiaw%3D%3D"); *//*Service Key*//*
        urlBuilder.append("&" + URLEncoder.encode("ServiceKey","UTF-8") + "=" + URLEncoder.encode("-", "UTF-8")); *//*공공데이터포털에서 받은 인증키*//*
        urlBuilder.append("&" + URLEncoder.encode("pageNo","UTF-8") + "=" + URLEncoder.encode("1", "UTF-8")); *//*페이지번호*//*
        urlBuilder.append("&" + URLEncoder.encode("numOfRows","UTF-8") + "=" + URLEncoder.encode("10", "UTF-8")); *//*한 페이지 결과 수*//*
        urlBuilder.append("&" + URLEncoder.encode("dataType","UTF-8") + "=" + URLEncoder.encode("XML", "UTF-8")); *//*요청자료형식(XML/JSON)Default: XML*//*
        urlBuilder.append("&" + URLEncoder.encode("base_date","UTF-8") + "=" + URLEncoder.encode("20210412", "UTF-8")); *//*15년 12월 1일발표*//*
        urlBuilder.append("&" + URLEncoder.encode("base_time","UTF-8") + "=" + URLEncoder.encode("1440", "UTF-8")); *//*05시 발표*//*
        urlBuilder.append("&" + URLEncoder.encode("nx","UTF-8") + "=" + URLEncoder.encode("84", "UTF-8")); *//*예보지점 X 좌표값*//*
        urlBuilder.append("&" + URLEncoder.encode("ny","UTF-8") + "=" + URLEncoder.encode("96", "UTF-8")); *//*예보지점의 Y 좌표값*//*
        URL url = new URL(urlBuilder.toString());
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-type", "application/json");
        System.out.println("Response code: " + conn.getResponseCode());
        BufferedReader rd;
        if(conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) {
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        } else {
            rd = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
        }
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        rd.close();
        conn.disconnect();
        System.out.println(sb.toString());
        log.error(sb.toString());
    }*/
}
