diff --git a/pav-server/src/main/java/com/palnet/biz/jpa/repository/flt/FltPlanQueryRepository.java b/pav-server/src/main/java/com/palnet/biz/jpa/repository/flt/FltPlanQueryRepository.java index d7fd7a6..0d76460 100644 --- a/pav-server/src/main/java/com/palnet/biz/jpa/repository/flt/FltPlanQueryRepository.java +++ b/pav-server/src/main/java/com/palnet/biz/jpa/repository/flt/FltPlanQueryRepository.java @@ -3,7 +3,10 @@ package com.palnet.biz.jpa.repository.flt; import java.time.Duration; import java.time.Instant; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Optional; @@ -1945,6 +1948,9 @@ public class FltPlanQueryRepository { builder.and(pgb.groupId.eq(groupId)); } Instant now = Instant.now(); + + Instant todayStart = LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC); + Instant todayEnd = LocalDate.now().plusDays(1).atStartOfDay().toInstant(ZoneOffset.UTC); List result = query .select(Projections.bean(MainDashFlightListModel.class, @@ -1959,9 +1965,10 @@ public class FltPlanQueryRepository { ccb.cntrlStDt ).as("totalFlightTime"), new CaseBuilder() - .when(ccb.statusCd.eq("01")).then("비행 중") - .when(ccb.statusCd.eq("99")).then("비행 완료") - .otherwise("비행 대기 중").as("status") + .when(ccb.statusCd.eq("01")).then("비행 중") + .when(ccb.statusCd.eq("99")).then("비행 완료") + .when(fpb.planSno.isNotNull()).then("비행 대기 중") + .otherwise("비행 없음").as("status") )) .from(fpa) .leftJoin(fpb).on(fpb.planSno.eq(fpa.planSno)) @@ -1970,11 +1977,17 @@ public class FltPlanQueryRepository { .leftJoin(fpccr).on(fpccr.planSno.eq(fpb.planSno)) .leftJoin(ccb).on(ccb.cntrlId.eq(fpccr.cntrlId)) .where( - builder - .and(fpb.schFltStDt.between(now, now.plus(Duration.ofDays(1)))) - .and(fpb.schFltEndDt.between(now, now.plus(Duration.ofDays(1)))) - .and(fpb.planSno.isNotNull()) - ) + builder + .and(fpb.schFltStDt.between( + now.atZone(ZoneId.of("Asia/Seoul")).truncatedTo(ChronoUnit.DAYS).toInstant(), + now.atZone(ZoneId.of("Asia/Seoul")).truncatedTo(ChronoUnit.DAYS).plus(1, ChronoUnit.DAYS).toInstant() + )) + .and(fpb.schFltEndDt.between( + now.atZone(ZoneId.of("Asia/Seoul")).truncatedTo(ChronoUnit.DAYS).toInstant(), + now.atZone(ZoneId.of("Asia/Seoul")).truncatedTo(ChronoUnit.DAYS).plus(1, ChronoUnit.DAYS).toInstant() + )) + .and(fpb.planSno.isNotNull()) + ) .orderBy(((ComparableExpressionBase) groupOrder).desc(), cib.createDt.asc()) .fetch(); diff --git a/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java b/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java index 8636c7d..24fd31a 100644 --- a/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java +++ b/pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java @@ -7,6 +7,10 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -159,15 +163,13 @@ public class FlightUtils { } //좌표의 읍면동 , 리 등 가장 세분화된 법정동 코드를 리턴 - public static JSONObject getCoordinateGis(Coordinate coordinate) throws IOException, ParseException { + public static JSONObject getCoordinateGis(Coordinate coordinate, int depth, boolean isNear) throws IOException, ParseException { String baseFileName = "all_location.geojson"; JSONObject obj = new JSONObject(); - log.info("path >>>>>> {}", basePath); - - String path = basePath; + String path = basePath + depth + "/"; while(true) { @@ -175,7 +177,9 @@ public class FlightUtils { if(!file.exists()) return obj; - obj = parseGeoJson(path+baseFileName, coordinate); + obj = parseGeoJson(path+baseFileName, coordinate, isNear); + + if(obj == null) return null; path += obj.get("CD")+"/"; @@ -183,14 +187,12 @@ public class FlightUtils { } //depth를 통해 좌표의 특정 구간(2 : 광역시, 5 : 시군구, 8 : 읍면동 / 리)에 해당하는 정보를 가져옴 - public static JSONObject getCoordinateGis(Coordinate coordinate, int depth) throws IOException, ParseException { + public static JSONObject getDepthPlace(Coordinate coordinate, int depth) throws IOException, ParseException { String baseFileName = "all_location.geojson"; JSONObject obj = new JSONObject(); - log.info("path >>>>>> {}", basePath); - String path = basePath; while(true) { @@ -199,7 +201,7 @@ public class FlightUtils { if(!file.exists()) return obj; - obj = parseGeoJson(path+baseFileName, coordinate); + obj = parseGeoJson(path+baseFileName, coordinate, false); if(obj.get("CD").toString().length() >= depth) return obj; @@ -208,8 +210,75 @@ public class FlightUtils { } } - - public static JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException { + // isNear == true -> 좌표가 육지가 아닌 바다 + // isNear == false -> 좌표가 육지 + public static JSONObject getPlace(Coordinate coord, boolean isNear) throws IOException, ParseException { + + int numberOfThreads = 5; + ExecutorService executorService = Executors.newFixedThreadPool(numberOfThreads); + + Integer[] coords = {11, 26, 27, 28, 29, 30, 31, 36, 41, 43, 44, 45, 46, 47, 48, 50, 51}; + + List> callables = new ArrayList<>(); + + for (int i = 0; i < coords.length-1; i++) { + + int path = i; + callables.add(() -> getCoordinateGis(coord, coords[path], isNear)); + + } + + try { + + List> results = new ArrayList<>(); + + for (Callable callable : callables) { + results.add(executorService.submit(callable)); + } + + executorService.shutdown(); + + if(isNear) { + + JSONObject result = new JSONObject(); + Double distance = 1000000.0; + + for (Future rslt : results) { + + try { + JSONObject jsonObject = rslt.get(); + + if((Double)jsonObject.get("distance") < distance) { + + distance = (Double)jsonObject.get("distance"); + result = jsonObject; + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + return result; + + } else { + for (Future rslt : results) { + + JSONObject jsonObject = rslt.get(); + + if(jsonObject != null) return jsonObject; + + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return null; // 모든 작업이 실패한 경우 null 반환 + + } + + public static JSONObject parseGeoJson(String path, Coordinate coordinate, boolean isNear) throws IOException, ParseException { GeometryFactory geometryFactory = new GeometryFactory(); @@ -229,6 +298,10 @@ public class FlightUtils { fileInputStream.close(); reader.close(); + JSONObject result = new JSONObject(); + + Double distance = 10000000.0; + for(int i=0; i polygon.distance(point)) { + + distance = polygon.distance(point); + + result = properties; + + } + }else { + + if(polygon.contains(point)) return properties; + + } } } - - return null; + + if(isNear) { + result.put("distance", distance); + return result; + }else { + return null; + } } }