Compare commits

...

3 Commits

  1. 29
      pav-server/src/main/java/com/palnet/biz/jpa/repository/flt/FltPlanQueryRepository.java
  2. 114
      pav-server/src/main/java/com/palnet/comn/utils/FlightUtils.java

29
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;
@ -1872,6 +1875,9 @@ public class FltPlanQueryRepository {
}
Instant now = Instant.now();
Instant todayStart = LocalDate.now().atStartOfDay().toInstant(ZoneOffset.UTC);
Instant todayEnd = LocalDate.now().plusDays(1).atStartOfDay().toInstant(ZoneOffset.UTC);
List<MainDashFlightListModel> result = query
.select(Projections.bean(MainDashFlightListModel.class,
pgb.groupNm,
@ -1885,9 +1891,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))
@ -1896,11 +1903,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<Integer>) groupOrder).desc(), cib.createDt.asc())
.fetch();

114
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 {
}
}
// 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<Callable<JSONObject>> callables = new ArrayList<>();
for (int i = 0; i < coords.length-1; i++) {
int path = i;
callables.add(() -> getCoordinateGis(coord, coords[path], isNear));
}
try {
List<Future<JSONObject>> results = new ArrayList<>();
for (Callable<JSONObject> callable : callables) {
results.add(executorService.submit(callable));
}
executorService.shutdown();
if(isNear) {
JSONObject result = new JSONObject();
Double distance = 1000000.0;
for (Future<JSONObject> rslt : results) {
try {
JSONObject jsonObject = rslt.get();
if((Double)jsonObject.get("distance") < distance) {
distance = (Double)jsonObject.get("distance");
result = jsonObject;
public static JSONObject parseGeoJson(String path, Coordinate coordinate) throws IOException, ParseException {
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
} else {
for (Future<JSONObject> 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<features.size(); i++) {
JSONObject geometry = (JSONObject) features.get(i).get("geometry");
@ -265,11 +338,28 @@ public class FlightUtils {
Polygon polygon = geometryFactory.createPolygon(polygonPaths.toArray(new Coordinate[] {}));
if(polygon.contains(point)) return properties;
if(isNear) {
if(distance > 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;
}
}
}

Loading…
Cancel
Save