|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.palnet.biz.scheduler.external.service; |
|
|
|
package com.palnet.biz.scheduler.external.service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.palnet.biz.api.external.model.SunRiseSetErrorXmlRs; |
|
|
|
import com.palnet.biz.api.external.model.SunRiseSetRs; |
|
|
|
import com.palnet.biz.api.external.model.SunRiseSetRs; |
|
|
|
import com.palnet.biz.api.external.model.SunRiseSetXmlRs; |
|
|
|
import com.palnet.biz.api.external.model.SunRiseSetXmlRs; |
|
|
|
import com.palnet.biz.api.external.service.SunRiseSetMapper; |
|
|
|
import com.palnet.biz.api.external.service.SunRiseSetMapper; |
|
|
@ -69,8 +70,12 @@ public class SunRiseSchedulerService { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int dayCallCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
public void sunsetSchedule(){ |
|
|
|
public void sunsetSchedule(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.dayCallCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
List<String> todayLocation = this.todayLocation(); |
|
|
|
List<String> todayLocation = this.todayLocation(); |
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
List<String> timeColumn = List.of("sunrise", "suntransit", "sunset", "moonrise", "moontransit", "moonset", "civilm", "civile", "nautm", "naute", "astm", "aste"); |
|
|
|
List<String> timeColumn = List.of("sunrise", "suntransit", "sunset", "moonrise", "moontransit", "moonset", "civilm", "civile", "nautm", "naute", "astm", "aste"); |
|
|
@ -83,42 +88,51 @@ public class SunRiseSchedulerService { |
|
|
|
String locdate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
|
|
|
String locdate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
|
|
|
|
|
|
|
|
|
|
|
for(int j = 0; j < todayLocation.size(); j ++){ |
|
|
|
for(int j = 0; j < todayLocation.size(); j ++){ |
|
|
|
String location = todayLocation.get(j); |
|
|
|
try { |
|
|
|
|
|
|
|
String location = todayLocation.get(j); |
|
|
|
List<SunRiseSetRs> results = callSunRiseSet(locdate, location); |
|
|
|
|
|
|
|
// trim 제거 및 6자리로 맞추기
|
|
|
|
List<SunRiseSetRs> results = callSunRiseSet(locdate, location); |
|
|
|
results.forEach(result -> { |
|
|
|
// trim 제거 및 6자리로 맞추기
|
|
|
|
Class<? extends SunRiseSetRs> aClass = result.getClass(); |
|
|
|
results.forEach(result -> { |
|
|
|
Field[] declaredFields = aClass.getDeclaredFields(); |
|
|
|
Class<? extends SunRiseSetRs> aClass = result.getClass(); |
|
|
|
for (Field field: declaredFields){ |
|
|
|
Field[] declaredFields = aClass.getDeclaredFields(); |
|
|
|
if(timeColumn.contains(field.getName())){ |
|
|
|
for (Field field: declaredFields){ |
|
|
|
field.setAccessible(true); |
|
|
|
if(timeColumn.contains(field.getName())){ |
|
|
|
try { |
|
|
|
field.setAccessible(true); |
|
|
|
Object o = field.get(result); |
|
|
|
try { |
|
|
|
if(o instanceof String){ |
|
|
|
Object o = field.get(result); |
|
|
|
String str = (String) o; |
|
|
|
if(o instanceof String){ |
|
|
|
if(!str.isEmpty()) { |
|
|
|
String str = (String) o; |
|
|
|
String trim = str.trim(); |
|
|
|
if(!str.isEmpty()) { |
|
|
|
if(trim.length() <= 6 && trim.length() >= 4 && trim.matches("-?\\d+(\\.\\d+)?")) { |
|
|
|
String trim = str.trim(); |
|
|
|
field.set(result, String.format("%-6s", trim).replace(' ', '0')); |
|
|
|
if(trim.length() <= 6 && trim.length() >= 4 && trim.matches("-?\\d+(\\.\\d+)?")) { |
|
|
|
} else { |
|
|
|
field.set(result, String.format("%-6s", trim).replace(' ', '0')); |
|
|
|
field.set(result, null); |
|
|
|
} else { |
|
|
|
|
|
|
|
field.set(result, null); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ComRiseSetBasPK pk = SunRiseSetMapper.MAPPER.toEntityPk(result); |
|
|
|
ComRiseSetBasPK pk = SunRiseSetMapper.MAPPER.toEntityPk(result); |
|
|
|
ComRiseSetBas entity = SunRiseSetMapper.MAPPER.toEntity(result); |
|
|
|
ComRiseSetBas entity = SunRiseSetMapper.MAPPER.toEntity(result); |
|
|
|
entity.setId(pk); |
|
|
|
entity.setId(pk); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sunRiseSet.add(entity); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}catch (CustomException e) { |
|
|
|
|
|
|
|
String errorCode = e.getErrorCode(); |
|
|
|
|
|
|
|
|
|
|
|
sunRiseSet.add(entity); |
|
|
|
if(errorCode.equals("LT001")) throw new CustomException(ErrorCode.fromCode(errorCode)); |
|
|
|
}); |
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
log.error("API CALL Error :: location {} , locdate {}", locdate, locdate); |
|
|
|
|
|
|
|
log.error("", e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(i%30 == 0){ |
|
|
|
if(i%30 == 0){ |
|
|
@ -127,9 +141,11 @@ public class SunRiseSchedulerService { |
|
|
|
sunRiseSet.clear(); |
|
|
|
sunRiseSet.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("dayCallCount => {}", this.dayCallCount); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<SunRiseSetRs> callSunRiseSet(String locdate, String location) { |
|
|
|
private List<SunRiseSetRs> callSunRiseSet(String locdate, String location) throws CustomException { |
|
|
|
|
|
|
|
|
|
|
|
String uriStr = UriComponentsBuilder.fromUriString(AREA_RISE_SEET_INFO_URL) |
|
|
|
String uriStr = UriComponentsBuilder.fromUriString(AREA_RISE_SEET_INFO_URL) |
|
|
|
.queryParam("serviceKey", SUN_KEY) |
|
|
|
.queryParam("serviceKey", SUN_KEY) |
|
|
@ -142,17 +158,37 @@ public class SunRiseSchedulerService { |
|
|
|
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) |
|
|
|
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
ResponseEntity<SunRiseSetXmlRs> resp = client.get() |
|
|
|
try { |
|
|
|
.uri(uriStr) |
|
|
|
ResponseEntity<SunRiseSetXmlRs> resp = client.get() |
|
|
|
.retrieve() |
|
|
|
.uri(uriStr) |
|
|
|
.toEntity(SunRiseSetXmlRs.class) |
|
|
|
.retrieve() |
|
|
|
.block(); |
|
|
|
.toEntity(SunRiseSetXmlRs.class) |
|
|
|
|
|
|
|
.block(); |
|
|
|
log.debug(">>> resp : {}", resp); |
|
|
|
log.debug(">>> resp : {}", resp); |
|
|
|
|
|
|
|
List<SunRiseSetRs> items = resp.getBody().getBody().getItems(); |
|
|
|
List<SunRiseSetRs> items = resp.getBody().getBody().getItems(); |
|
|
|
|
|
|
|
|
|
|
|
return items; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e){ |
|
|
|
|
|
|
|
ResponseEntity<SunRiseSetErrorXmlRs> resp = client.get() |
|
|
|
|
|
|
|
.uri(uriStr) |
|
|
|
|
|
|
|
.retrieve() |
|
|
|
|
|
|
|
.toEntity(SunRiseSetErrorXmlRs.class) |
|
|
|
|
|
|
|
.block(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SunRiseSetErrorXmlRs errorModel = resp.getBody(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (errorModel.getCmmMsgHeader().getReturnReasonCode()){ |
|
|
|
|
|
|
|
case "22" /* LIMITED_NUMBER_OF_SERVICE_REQUESTS_EXCEEDS_ERROR[API 콜 트래픽 10,000건 초과함] */ : |
|
|
|
|
|
|
|
throw new CustomException(ErrorCode.LIMIT_CALL); |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return items; |
|
|
|
return null; |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
this.dayCallCount++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<String> todayLocation (){ |
|
|
|
private List<String> todayLocation (){ |
|
|
@ -206,5 +242,4 @@ public class SunRiseSchedulerService { |
|
|
|
return (day % 4) + 1; |
|
|
|
return (day % 4) + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|