235 lines
6.8 KiB
Java
235 lines
6.8 KiB
Java
package itn.let.mjo.mjocommon;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.client.HttpClient;
|
|
import org.apache.http.client.methods.HttpGet;
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.json.simple.JSONArray;
|
|
import org.json.simple.JSONObject;
|
|
import org.json.simple.parser.JSONParser;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import com.ibm.icu.text.SimpleDateFormat;
|
|
|
|
import itn.let.mjo.msgholiday.service.MsgAlarmSetVO;
|
|
import itn.let.mjo.msgholiday.service.MsgHolidayVO;
|
|
|
|
@Component
|
|
public class MjonHolidayApi {
|
|
|
|
public List<MsgHolidayVO> getYearHolidayApiData(MsgHolidayVO msgHolidayVO) throws Exception{
|
|
|
|
try {
|
|
|
|
String sendUrl = "http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/getHoliDeInfo?";
|
|
String numOfRows = "100";
|
|
String serviceKey = "J8QXC%2BtOGvxwmH8blG7nmqIq%2B0MrkNrxTo1PCmFMRdtSldlGN8vWDW2NpZ2om8k9LctZT6oubfFt5dMmbEDeoA%3D%3D";
|
|
String solYear = msgHolidayVO.getSearchHoliYear();
|
|
String frstRegisterId = msgHolidayVO.getFrstRegisterId();
|
|
|
|
|
|
String strUrl = sendUrl + "&solYear=" + solYear + "&numOfRows=" + numOfRows + "&serviceKey=" + serviceKey;
|
|
|
|
HttpClient httpClient = HttpClientBuilder.create().build();
|
|
HttpGet httpGet = new HttpGet(strUrl);
|
|
httpGet.addHeader("Content-type", "application/json");
|
|
httpGet.addHeader("Accept", "application/json");
|
|
|
|
HttpResponse response = httpClient.execute(httpGet);
|
|
|
|
String result = "";
|
|
String statusCode = Integer.toString(response.getStatusLine().getStatusCode());
|
|
|
|
if(statusCode.equals("200")) {
|
|
|
|
result = EntityUtils.toString(response.getEntity());
|
|
|
|
result = new String(result.getBytes("iso-8859-1"));//한글 깨짐 현상이 있어서 변환 해줌.
|
|
//System.out.println(result);
|
|
JSONParser parser = new JSONParser();
|
|
Object obj = parser.parse(result);
|
|
JSONObject object = (JSONObject) obj;
|
|
|
|
Object objResp = parser.parse(object.get("response").toString());
|
|
JSONObject objectResp = (JSONObject) objResp;
|
|
|
|
Object objBody = parser.parse(objectResp.get("body").toString());
|
|
JSONObject objectBody = (JSONObject) objBody;
|
|
|
|
Object objItems = parser.parse(objectBody.get("items").toString());
|
|
JSONObject objectItems = (JSONObject) objItems;
|
|
|
|
JSONArray objItemArr = (JSONArray) objectItems.get("item");
|
|
|
|
List<MsgHolidayVO> msgHolidayVoList = new ArrayList<MsgHolidayVO>();
|
|
|
|
for(Object tmpObj : objItemArr) {
|
|
|
|
JSONObject tmpObject = (JSONObject) tmpObj;
|
|
MsgHolidayVO tmpMsgHolidayVO = new MsgHolidayVO();
|
|
|
|
String isHoli = tmpObject.get("isHoliday").toString();
|
|
String holiNm = tmpObject.get("dateName").toString();
|
|
String holiDate = tmpObject.get("locdate").toString();
|
|
|
|
|
|
if(isHoli.equals("Y")) {
|
|
|
|
tmpMsgHolidayVO.setHolidayNm(holiNm);
|
|
tmpMsgHolidayVO.setHolidayDate(holiDate);
|
|
tmpMsgHolidayVO.setHolidayType("1");
|
|
tmpMsgHolidayVO.setApiType("Y");
|
|
tmpMsgHolidayVO.setFrstRegisterId(frstRegisterId);
|
|
tmpMsgHolidayVO.setLastUpdusrId(frstRegisterId);
|
|
|
|
msgHolidayVoList.add(tmpMsgHolidayVO);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
return msgHolidayVoList;
|
|
|
|
}else {
|
|
return null;
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
System.out.println("+++++++++++++++++++++++++++++++++ getYearHolidayApiData Method Error!!!!" + e);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public boolean getHolidaySmishingPassStatus(List<MsgAlarmSetVO> resultAlarmList, List<MsgHolidayVO> resultHolidayList) throws Exception{
|
|
|
|
boolean holiCompareSts = false; //공휴일 일치 날자가 있는지 여부
|
|
boolean smishingAlarmPassSts = false; //스미싱 알람 Pass 시킬건지 여부
|
|
|
|
//현재 날짜의 요일 구하기
|
|
Date currentDate = new Date();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
int year = calendar.get(Calendar.YEAR);
|
|
int month = calendar.get(Calendar.MONTH);
|
|
int day = calendar.get(Calendar.DATE);
|
|
|
|
calendar.setTime(currentDate);
|
|
|
|
// 3. 텍스트 요일 구하기 (숫자)
|
|
int dayOfWeekNumber = calendar.get(Calendar.DAY_OF_WEEK);
|
|
// 4. 요일 출력 - 1은 일요일, 7은 토요일
|
|
//System.out.println(dayOfWeekNumber); // 7
|
|
|
|
|
|
//월에 대한 자릿수 처리 : 10미만은 앞에 0을 추가해주어 자릿수 맞춰준다.
|
|
String strMonth = "";
|
|
if((month +1) < 10) {
|
|
strMonth = "0" + Integer.toString(month +1);
|
|
}else {
|
|
strMonth = Integer.toString(month + 1);
|
|
}
|
|
|
|
String strNowDate = year + "-" + strMonth + "-" + day;
|
|
|
|
for(MsgHolidayVO holiVO : resultHolidayList) {
|
|
|
|
String holiDate = holiVO.getHolidayDate();
|
|
|
|
if(strNowDate.equals(holiDate)) {
|
|
|
|
//System.out.println("공휴일이 동일한 날이 있습니다.");
|
|
holiCompareSts = true;
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
for(MsgAlarmSetVO alarmVO : resultAlarmList) {
|
|
|
|
String alarmType = alarmVO.getAlarmType();
|
|
String startTime = alarmVO.getAlarmStart();
|
|
String sDate = strNowDate + " " + startTime;
|
|
|
|
String endTime = alarmVO.getAlarmEnd();
|
|
String eDate = strNowDate + " " + endTime;
|
|
|
|
Date nowDate = currentDate;
|
|
Date startDate = sdf.parse(sDate);
|
|
Date endDate = sdf.parse(eDate);
|
|
|
|
//평일인 경우 비교
|
|
if(dayOfWeekNumber > 1 && dayOfWeekNumber < 7 ) {
|
|
|
|
if(alarmType.equals("W")) {
|
|
|
|
int copStart = nowDate.compareTo(startDate);
|
|
int copEnd = nowDate.compareTo(endDate);
|
|
|
|
if(copStart > 0 && copEnd < 0) {
|
|
|
|
//System.out.println("평일 알림 일정 해당시간에 포함됩니다.");
|
|
smishingAlarmPassSts = true;
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
//주말인 경우 비교
|
|
if(alarmType.equals("E")) {
|
|
|
|
int copStart = nowDate.compareTo(startDate);
|
|
int copEnd = nowDate.compareTo(endDate);
|
|
|
|
if(copStart > 0 && copEnd < 0) {
|
|
|
|
//System.out.println("주말 알림 일정 해당시간에 포함됩니다.");
|
|
smishingAlarmPassSts = true;
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//공휴일인 경우 비교
|
|
if(alarmType.equals("H")) {
|
|
|
|
if(holiCompareSts) {//오늘 날짜가 공휴일이면 실행
|
|
|
|
int copStart = nowDate.compareTo(startDate);
|
|
int copEnd = nowDate.compareTo(endDate);
|
|
|
|
if(copStart > 0 && copEnd < 0) {
|
|
|
|
//System.out.println("공휴일 알림 일정 해당시간에 포함됩니다.");
|
|
smishingAlarmPassSts = true;
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return smishingAlarmPassSts;
|
|
}
|
|
|
|
}
|