:spotlessApply 실행
This commit is contained in:
@@ -9,12 +9,10 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Tag(name = "변화탐지", description = "변화탐지 API")
|
@Tag(name = "변화탐지", description = "변화탐지 API")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@@ -33,6 +31,7 @@ public class ChangeDetectionApiController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* PolygonData -> JsonNode 변환 예제
|
* PolygonData -> JsonNode 변환 예제
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Hidden
|
@Hidden
|
||||||
@@ -44,7 +43,8 @@ public class ChangeDetectionApiController {
|
|||||||
@Operation(summary = "변화탐지 분류별 건수", description = "변화탐지 분류별 건수")
|
@Operation(summary = "변화탐지 분류별 건수", description = "변화탐지 분류별 건수")
|
||||||
@GetMapping("/class-count/{id}")
|
@GetMapping("/class-count/{id}")
|
||||||
public ApiResponseDto<List<ChangeDetectionDto.CountDto>> getChangeDetectionClassCount(
|
public ApiResponseDto<List<ChangeDetectionDto.CountDto>> getChangeDetectionClassCount(
|
||||||
@Parameter(description = "변화탐지 년도(차수) /year-list 의 analUid", example = "1") @PathVariable Long id){
|
@Parameter(description = "변화탐지 년도(차수) /year-list 의 analUid", example = "1") @PathVariable
|
||||||
|
Long id) {
|
||||||
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionClassCount(id));
|
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionClassCount(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,8 @@ public class ChangeDetectionApiController {
|
|||||||
@Parameter(description = "이전 년도", example = "2023") @RequestParam Integer beforeYear,
|
@Parameter(description = "이전 년도", example = "2023") @RequestParam Integer beforeYear,
|
||||||
@Parameter(description = "이후 년도", example = "2024") @RequestParam Integer afterYear,
|
@Parameter(description = "이후 년도", example = "2024") @RequestParam Integer afterYear,
|
||||||
@Parameter(description = "도엽번호(5k)", example = "36809010") @RequestParam String mapSheetNum) {
|
@Parameter(description = "도엽번호(5k)", example = "36809010") @RequestParam String mapSheetNum) {
|
||||||
ChangeDetectionDto.CogUrlReq req = new ChangeDetectionDto.CogUrlReq(beforeYear, afterYear, mapSheetNum);
|
ChangeDetectionDto.CogUrlReq req =
|
||||||
|
new ChangeDetectionDto.CogUrlReq(beforeYear, afterYear, mapSheetNum);
|
||||||
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionCogUrl(req));
|
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionCogUrl(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ public class ChangeDetectionDto{
|
|||||||
public static class TestDto {
|
public static class TestDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
private Geometry polygon;
|
private Geometry polygon;
|
||||||
private Double centroidX;;
|
private Double centroidX;
|
||||||
|
;
|
||||||
private Double centroidY;
|
private Double centroidY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.kamco.cd.kamcoback.inference.service;
|
|||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnDataEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnDataEntity;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnDataGeomEntity;
|
|
||||||
import com.kamco.cd.kamcoback.postgres.repository.MapSheetLearnDataGeomRepository;
|
import com.kamco.cd.kamcoback.postgres.repository.MapSheetLearnDataGeomRepository;
|
||||||
import com.kamco.cd.kamcoback.postgres.repository.MapSheetLearnDataRepository;
|
import com.kamco.cd.kamcoback.postgres.repository.MapSheetLearnDataRepository;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -15,7 +14,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.locationtech.jts.geom.Geometry;
|
|
||||||
import org.locationtech.jts.io.geojson.GeoJsonReader;
|
import org.locationtech.jts.io.geojson.GeoJsonReader;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -39,9 +37,7 @@ public class LearningModelResultProcessor {
|
|||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
private final GeoJsonReader geoJsonReader = new GeoJsonReader();
|
private final GeoJsonReader geoJsonReader = new GeoJsonReader();
|
||||||
|
|
||||||
/**
|
/** Process large learning model result files with optimized batch processing */
|
||||||
* Process large learning model result files with optimized batch processing
|
|
||||||
*/
|
|
||||||
public int processLearningModelResultOptimized(Path geoJsonFilePath) {
|
public int processLearningModelResultOptimized(Path geoJsonFilePath) {
|
||||||
try {
|
try {
|
||||||
logger.info("Processing learning model result file (optimized): {}", geoJsonFilePath);
|
logger.info("Processing learning model result file (optimized): {}", geoJsonFilePath);
|
||||||
@@ -62,7 +58,8 @@ public class LearningModelResultProcessor {
|
|||||||
|
|
||||||
// Extract metadata from file name and content
|
// Extract metadata from file name and content
|
||||||
String fileName = geoJsonFilePath.getFileName().toString();
|
String fileName = geoJsonFilePath.getFileName().toString();
|
||||||
String mapSheetName = rootNode.has("name") ? rootNode.get("name").asText() : fileName.replace(".geojson", "");
|
String mapSheetName =
|
||||||
|
rootNode.has("name") ? rootNode.get("name").asText() : fileName.replace(".geojson", "");
|
||||||
|
|
||||||
// Parse years from filename
|
// Parse years from filename
|
||||||
String[] parts = mapSheetName.split("_");
|
String[] parts = mapSheetName.split("_");
|
||||||
@@ -75,14 +72,22 @@ public class LearningModelResultProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (beforeYear == null || afterYear == null || mapSheetNum == null) {
|
if (beforeYear == null || afterYear == null || mapSheetNum == null) {
|
||||||
throw new IllegalArgumentException("Cannot parse years and map sheet number from filename: " + fileName);
|
throw new IllegalArgumentException(
|
||||||
|
"Cannot parse years and map sheet number from filename: " + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalFeatures = features.size();
|
int totalFeatures = features.size();
|
||||||
logger.info("Total features to process: {}", totalFeatures);
|
logger.info("Total features to process: {}", totalFeatures);
|
||||||
|
|
||||||
// Step 1: Create main data record first
|
// Step 1: Create main data record first
|
||||||
MapSheetLearnDataEntity savedMainData = createMainDataRecord(geoJsonContent, fileName, geoJsonFilePath.toString(), beforeYear, afterYear, mapSheetNum);
|
MapSheetLearnDataEntity savedMainData =
|
||||||
|
createMainDataRecord(
|
||||||
|
geoJsonContent,
|
||||||
|
fileName,
|
||||||
|
geoJsonFilePath.toString(),
|
||||||
|
beforeYear,
|
||||||
|
afterYear,
|
||||||
|
mapSheetNum);
|
||||||
|
|
||||||
// Step 2: Process features in small batches to avoid transaction timeout
|
// Step 2: Process features in small batches to avoid transaction timeout
|
||||||
int totalProcessed = 0;
|
int totalProcessed = 0;
|
||||||
@@ -98,16 +103,22 @@ public class LearningModelResultProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int processed = processBatchSafely(batch, savedMainData.getId(), beforeYear, afterYear, mapSheetNum);
|
int processed =
|
||||||
|
processBatchSafely(batch, savedMainData.getId(), beforeYear, afterYear, mapSheetNum);
|
||||||
totalProcessed += processed;
|
totalProcessed += processed;
|
||||||
logger.info("Batch processed successfully. Total so far: {}/{}", totalProcessed, totalFeatures);
|
logger.info(
|
||||||
|
"Batch processed successfully. Total so far: {}/{}", totalProcessed, totalFeatures);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to process batch {}-{}: {}", i + 1, endIndex, e.getMessage());
|
logger.error("Failed to process batch {}-{}: {}", i + 1, endIndex, e.getMessage());
|
||||||
// Continue with next batch instead of failing completely
|
// Continue with next batch instead of failing completely
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Successfully processed {} out of {} features from file: {}", totalProcessed, totalFeatures, fileName);
|
logger.info(
|
||||||
|
"Successfully processed {} out of {} features from file: {}",
|
||||||
|
totalProcessed,
|
||||||
|
totalFeatures,
|
||||||
|
fileName);
|
||||||
return totalProcessed;
|
return totalProcessed;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -120,15 +131,28 @@ public class LearningModelResultProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private MapSheetLearnDataEntity createMainDataRecord(String geoJsonContent, String fileName, String filePath, String beforeYear, String afterYear, String mapSheetNum) {
|
private MapSheetLearnDataEntity createMainDataRecord(
|
||||||
MapSheetLearnDataEntity mainData = createMainDataEntity(geoJsonContent, fileName, filePath, beforeYear, afterYear, mapSheetNum);
|
String geoJsonContent,
|
||||||
|
String fileName,
|
||||||
|
String filePath,
|
||||||
|
String beforeYear,
|
||||||
|
String afterYear,
|
||||||
|
String mapSheetNum) {
|
||||||
|
MapSheetLearnDataEntity mainData =
|
||||||
|
createMainDataEntity(
|
||||||
|
geoJsonContent, fileName, filePath, beforeYear, afterYear, mapSheetNum);
|
||||||
MapSheetLearnDataEntity saved = mapSheetLearnDataRepository.save(mainData);
|
MapSheetLearnDataEntity saved = mapSheetLearnDataRepository.save(mainData);
|
||||||
logger.info("Created main data record with ID: {}", saved.getId());
|
logger.info("Created main data record with ID: {}", saved.getId());
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private int processBatchSafely(List<JsonNode> features, Long dataUid, String beforeYear, String afterYear, String mapSheetNum) {
|
private int processBatchSafely(
|
||||||
|
List<JsonNode> features,
|
||||||
|
Long dataUid,
|
||||||
|
String beforeYear,
|
||||||
|
String afterYear,
|
||||||
|
String mapSheetNum) {
|
||||||
int processed = 0;
|
int processed = 0;
|
||||||
|
|
||||||
for (JsonNode feature : features) {
|
for (JsonNode feature : features) {
|
||||||
@@ -138,7 +162,11 @@ public class LearningModelResultProcessor {
|
|||||||
processed++;
|
processed++;
|
||||||
|
|
||||||
// Small delay to prevent ID collisions
|
// Small delay to prevent ID collisions
|
||||||
try { Thread.sleep(1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
|
try {
|
||||||
|
Thread.sleep(1);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Failed to process individual feature: {}", e.getMessage());
|
logger.warn("Failed to process individual feature: {}", e.getMessage());
|
||||||
@@ -223,12 +251,17 @@ public class LearningModelResultProcessor {
|
|||||||
long geoUid = System.currentTimeMillis() + (long) (Math.random() * 10000) + j;
|
long geoUid = System.currentTimeMillis() + (long) (Math.random() * 10000) + j;
|
||||||
|
|
||||||
// Extract feature data and insert directly with PostGIS
|
// Extract feature data and insert directly with PostGIS
|
||||||
insertFeatureWithPostGIS(feature, geoUid, savedMainData.getId(), beforeYear, afterYear, mapSheetNum);
|
insertFeatureWithPostGIS(
|
||||||
|
feature, geoUid, savedMainData.getId(), beforeYear, afterYear, mapSheetNum);
|
||||||
featureCount++;
|
featureCount++;
|
||||||
|
|
||||||
// Small delay to prevent issues
|
// Small delay to prevent issues
|
||||||
if (j % 5 == 0) {
|
if (j % 5 == 0) {
|
||||||
try { Thread.sleep(10); } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -238,7 +271,8 @@ public class LearningModelResultProcessor {
|
|||||||
|
|
||||||
// Log progress after each batch
|
// Log progress after each batch
|
||||||
if (featureCount > 0 && endIndex % batchSize == 0) {
|
if (featureCount > 0 && endIndex % batchSize == 0) {
|
||||||
logger.info("Processed {} features so far, success rate: {:.1f}%",
|
logger.info(
|
||||||
|
"Processed {} features so far, success rate: {:.1f}%",
|
||||||
featureCount, (featureCount * 100.0) / endIndex);
|
featureCount, (featureCount * 100.0) / endIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,7 +327,12 @@ public class LearningModelResultProcessor {
|
|||||||
|
|
||||||
/** Insert GeoJSON feature directly using PostGIS functions */
|
/** Insert GeoJSON feature directly using PostGIS functions */
|
||||||
private void insertFeatureWithPostGIS(
|
private void insertFeatureWithPostGIS(
|
||||||
JsonNode feature, Long geoUid, Long dataUid, String beforeYear, String afterYear, String mapSheetNum)
|
JsonNode feature,
|
||||||
|
Long geoUid,
|
||||||
|
Long dataUid,
|
||||||
|
String beforeYear,
|
||||||
|
String afterYear,
|
||||||
|
String mapSheetNum)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
JsonNode properties = feature.get("properties");
|
JsonNode properties = feature.get("properties");
|
||||||
@@ -348,11 +387,19 @@ public class LearningModelResultProcessor {
|
|||||||
|
|
||||||
// Insert using PostGIS functions
|
// Insert using PostGIS functions
|
||||||
mapSheetLearnDataGeomRepository.insertWithPostGISGeometry(
|
mapSheetLearnDataGeomRepository.insertWithPostGISGeometry(
|
||||||
geoUid, cdProb, classBeforeName, classBeforeProb,
|
geoUid,
|
||||||
classAfterName, classAfterProb, Long.parseLong(mapSheetNum),
|
cdProb,
|
||||||
Integer.parseInt(beforeYear), Integer.parseInt(afterYear),
|
classBeforeName,
|
||||||
area, geometryJson, geoType, dataUid
|
classBeforeProb,
|
||||||
);
|
classAfterName,
|
||||||
|
classAfterProb,
|
||||||
|
Long.parseLong(mapSheetNum),
|
||||||
|
Integer.parseInt(beforeYear),
|
||||||
|
Integer.parseInt(afterYear),
|
||||||
|
area,
|
||||||
|
geometryJson,
|
||||||
|
geoType,
|
||||||
|
dataUid);
|
||||||
|
|
||||||
logger.debug("Inserted geometry entity with ID: {} using PostGIS", geoUid);
|
logger.debug("Inserted geometry entity with ID: {} using PostGIS", geoUid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ public class ChangeDetectionCoreService {
|
|||||||
|
|
||||||
public ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req) {
|
public ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req) {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ChangeDetectionDto.CogUrlDto resultDto = changeDetectionRepository.getChangeDetectionCogUrl(req);
|
ChangeDetectionDto.CogUrlDto resultDto =
|
||||||
|
changeDetectionRepository.getChangeDetectionCogUrl(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JsonNode geomNode = mapper.readTree(resultDto.getBbox().toString());
|
JsonNode geomNode = mapper.readTree(resultDto.getBbox().toString());
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.kamco.cd.kamcoback.postgres.entity;
|
package com.kamco.cd.kamcoback.postgres.entity;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Table(name = "imagery")
|
@Table(name = "imagery")
|
||||||
@@ -15,7 +14,10 @@ import java.util.UUID;
|
|||||||
public class ImageryEntity {
|
public class ImageryEntity {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "imagery_id_seq_gen")
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "imagery_id_seq_gen")
|
||||||
@SequenceGenerator(name = "imagery_id_seq_gen",sequenceName = "imagery_id_seq",allocationSize = 1)
|
@SequenceGenerator(
|
||||||
|
name = "imagery_id_seq_gen",
|
||||||
|
sequenceName = "imagery_id_seq",
|
||||||
|
allocationSize = 1)
|
||||||
@Column(name = "id", nullable = false)
|
@Column(name = "id", nullable = false)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|||||||
@@ -29,5 +29,4 @@ public class MapInkx50kEntity {
|
|||||||
|
|
||||||
@Column(name = "geom")
|
@Column(name = "geom")
|
||||||
private Geometry geom;
|
private Geometry geom;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,13 +29,12 @@ public interface MapSheetLearnDataGeomRepository
|
|||||||
/** 데이터 UID로 기존 지오메트리 데이터 삭제 (재생성 전에 사용) */
|
/** 데이터 UID로 기존 지오메트리 데이터 삭제 (재생성 전에 사용) */
|
||||||
void deleteByDataUid(Long dataUid);
|
void deleteByDataUid(Long dataUid);
|
||||||
|
|
||||||
/**
|
/** PostGIS 함수를 사용하여 geometry 데이터를 직접 삽입 ST_SetSRID(ST_GeomFromGeoJSON(...), 5186) 형식으로 저장 */
|
||||||
* PostGIS 함수를 사용하여 geometry 데이터를 직접 삽입
|
|
||||||
* ST_SetSRID(ST_GeomFromGeoJSON(...), 5186) 형식으로 저장
|
|
||||||
*/
|
|
||||||
@Modifying
|
@Modifying
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query(value = """
|
@Query(
|
||||||
|
value =
|
||||||
|
"""
|
||||||
INSERT INTO tb_map_sheet_learn_data_geom (
|
INSERT INTO tb_map_sheet_learn_data_geom (
|
||||||
geo_uid, cd_prob, class_before_name, class_before_prob,
|
geo_uid, cd_prob, class_before_name, class_before_prob,
|
||||||
class_after_name, class_after_prob, map_sheet_num,
|
class_after_name, class_after_prob, map_sheet_num,
|
||||||
@@ -48,7 +47,8 @@ public interface MapSheetLearnDataGeomRepository
|
|||||||
ST_SetSRID(ST_GeomFromGeoJSON(CAST(:geometryJson AS TEXT)), 5186),
|
ST_SetSRID(ST_GeomFromGeoJSON(CAST(:geometryJson AS TEXT)), 5186),
|
||||||
:geoType, :dataUid, NOW(), NOW()
|
:geoType, :dataUid, NOW(), NOW()
|
||||||
) ON CONFLICT (geo_uid) DO NOTHING
|
) ON CONFLICT (geo_uid) DO NOTHING
|
||||||
""", nativeQuery = true)
|
""",
|
||||||
|
nativeQuery = true)
|
||||||
void insertWithPostGISGeometry(
|
void insertWithPostGISGeometry(
|
||||||
@Param("geoUid") Long geoUid,
|
@Param("geoUid") Long geoUid,
|
||||||
@Param("cdProb") Double cdProb,
|
@Param("cdProb") Double cdProb,
|
||||||
@@ -62,6 +62,5 @@ public interface MapSheetLearnDataGeomRepository
|
|||||||
@Param("area") Double area,
|
@Param("area") Double area,
|
||||||
@Param("geometryJson") String geometryJson,
|
@Param("geometryJson") String geometryJson,
|
||||||
@Param("geoType") String geoType,
|
@Param("geoType") String geoType,
|
||||||
@Param("dataUid") Long dataUid
|
@Param("dataUid") Long dataUid);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.kamco.cd.kamcoback.postgres.repository.changedetection;
|
package com.kamco.cd.kamcoback.postgres.repository.changedetection;
|
||||||
|
|
||||||
import com.kamco.cd.kamcoback.changedetection.dto.ChangeDetectionDto;
|
import com.kamco.cd.kamcoback.changedetection.dto.ChangeDetectionDto;
|
||||||
import com.querydsl.core.Tuple;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ChangeDetectionRepositoryCustom {
|
public interface ChangeDetectionRepositoryCustom {
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package com.kamco.cd.kamcoback.postgres.repository.changedetection;
|
package com.kamco.cd.kamcoback.postgres.repository.changedetection;
|
||||||
|
|
||||||
|
import static com.kamco.cd.kamcoback.postgres.entity.QImageryEntity.imageryEntity;
|
||||||
|
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity.mapInkx5kEntity;
|
||||||
|
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataEntity.mapSheetAnalDataEntity;
|
||||||
|
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity;
|
||||||
|
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalEntity.mapSheetAnalEntity;
|
||||||
|
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalSttcEntity.mapSheetAnalSttcEntity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -11,17 +18,9 @@ import com.querydsl.core.types.dsl.CaseBuilder;
|
|||||||
import com.querydsl.core.types.dsl.Expressions;
|
import com.querydsl.core.types.dsl.Expressions;
|
||||||
import com.querydsl.core.types.dsl.StringExpression;
|
import com.querydsl.core.types.dsl.StringExpression;
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||||
import static com.kamco.cd.kamcoback.postgres.entity.QImageryEntity.imageryEntity;
|
|
||||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity.mapInkx5kEntity;
|
|
||||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataEntity.mapSheetAnalDataEntity;
|
|
||||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalDataGeomEntity.mapSheetAnalDataGeomEntity;
|
|
||||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalEntity.mapSheetAnalEntity;
|
|
||||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetAnalSttcEntity.mapSheetAnalSttcEntity;
|
|
||||||
|
|
||||||
public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
|
public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
|
||||||
implements ChangeDetectionRepositoryCustom {
|
implements ChangeDetectionRepositoryCustom {
|
||||||
@@ -51,12 +50,12 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
|
|||||||
@Override
|
@Override
|
||||||
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id) {
|
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id) {
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.select(Projections.constructor(
|
.select(
|
||||||
|
Projections.constructor(
|
||||||
ChangeDetectionDto.CountDto.class,
|
ChangeDetectionDto.CountDto.class,
|
||||||
mapSheetAnalSttcEntity.classAfterCd.toUpperCase(),
|
mapSheetAnalSttcEntity.classAfterCd.toUpperCase(),
|
||||||
mapSheetAnalSttcEntity.id.classAfterName,
|
mapSheetAnalSttcEntity.id.classAfterName,
|
||||||
mapSheetAnalSttcEntity.classAfterCnt.sum()
|
mapSheetAnalSttcEntity.classAfterCnt.sum()))
|
||||||
))
|
|
||||||
.from(mapSheetAnalEntity)
|
.from(mapSheetAnalEntity)
|
||||||
.innerJoin(mapSheetAnalDataEntity)
|
.innerJoin(mapSheetAnalDataEntity)
|
||||||
.on(mapSheetAnalDataEntity.analUid.eq(mapSheetAnalEntity.id))
|
.on(mapSheetAnalDataEntity.analUid.eq(mapSheetAnalEntity.id))
|
||||||
@@ -69,26 +68,31 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req) {
|
public ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req) {
|
||||||
Tuple result = queryFactory
|
Tuple result =
|
||||||
|
queryFactory
|
||||||
.select(
|
.select(
|
||||||
makeCogUrl(req.getBeforeYear()).max().as("beforeCogUrl"),
|
makeCogUrl(req.getBeforeYear()).max().as("beforeCogUrl"),
|
||||||
makeCogUrl(req.getAfterYear()).max().as("afterCogUrl"),
|
makeCogUrl(req.getAfterYear()).max().as("afterCogUrl"),
|
||||||
Expressions.stringTemplate("ST_AsGeoJSON({0})", mapInkx5kEntity.geom).as("bbox")
|
Expressions.stringTemplate("ST_AsGeoJSON({0})", mapInkx5kEntity.geom).as("bbox"))
|
||||||
)
|
|
||||||
.from(imageryEntity)
|
.from(imageryEntity)
|
||||||
.innerJoin(mapInkx5kEntity)
|
.innerJoin(mapInkx5kEntity)
|
||||||
.on(imageryEntity.scene5k.eq(mapInkx5kEntity.mapidcdNo))
|
.on(imageryEntity.scene5k.eq(mapInkx5kEntity.mapidcdNo))
|
||||||
.where(
|
.where(
|
||||||
imageryEntity.year.eq(req.getBeforeYear()).or(imageryEntity.year.eq(req.getAfterYear())),
|
imageryEntity
|
||||||
imageryEntity.scene5k.eq(req.getMapSheetNum())
|
.year
|
||||||
)
|
.eq(req.getBeforeYear())
|
||||||
|
.or(imageryEntity.year.eq(req.getAfterYear())),
|
||||||
|
imageryEntity.scene5k.eq(req.getMapSheetNum()))
|
||||||
.groupBy(mapInkx5kEntity.geom)
|
.groupBy(mapInkx5kEntity.geom)
|
||||||
.fetchOne();
|
.fetchOne();
|
||||||
|
|
||||||
// Polygon -> JsonNode 로 변환
|
// Polygon -> JsonNode 로 변환
|
||||||
JsonNode geometryJson = changeGeometryJson(String.valueOf(Objects.requireNonNull(result).get(2, StringExpression.class)));
|
JsonNode geometryJson =
|
||||||
|
changeGeometryJson(
|
||||||
|
String.valueOf(Objects.requireNonNull(result).get(2, StringExpression.class)));
|
||||||
|
|
||||||
return new ChangeDetectionDto.CogUrlDto(result.get(0, String.class), result.get(1, String.class), geometryJson);
|
return new ChangeDetectionDto.CogUrlDto(
|
||||||
|
result.get(0, String.class), result.get(1, String.class), geometryJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,21 +105,19 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
|
|||||||
mapSheetAnalEntity.analTitle,
|
mapSheetAnalEntity.analTitle,
|
||||||
mapSheetAnalEntity.compareYyyy.as("beforeYear"),
|
mapSheetAnalEntity.compareYyyy.as("beforeYear"),
|
||||||
mapSheetAnalEntity.targetYyyy.as("afterYear"),
|
mapSheetAnalEntity.targetYyyy.as("afterYear"),
|
||||||
mapSheetAnalEntity.baseMapSheetNum
|
mapSheetAnalEntity.baseMapSheetNum))
|
||||||
)
|
|
||||||
)
|
|
||||||
.from(mapSheetAnalEntity)
|
.from(mapSheetAnalEntity)
|
||||||
.orderBy(mapSheetAnalEntity.id.asc())
|
.orderBy(mapSheetAnalEntity.id.asc())
|
||||||
.fetch()
|
.fetch();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringExpression makeCogUrl(Integer year) {
|
private StringExpression makeCogUrl(Integer year) {
|
||||||
return new CaseBuilder()
|
return new CaseBuilder()
|
||||||
.when(imageryEntity.year.eq(year))
|
.when(imageryEntity.year.eq(year))
|
||||||
.then(Expressions.stringTemplate("{0} || {1}",imageryEntity.cogMiddlePath, imageryEntity.cogFilename))
|
.then(
|
||||||
.otherwise("")
|
Expressions.stringTemplate(
|
||||||
;
|
"{0} || {1}", imageryEntity.cogMiddlePath, imageryEntity.cogFilename))
|
||||||
|
.otherwise("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonNode changeGeometryJson(String geometry) {
|
private JsonNode changeGeometryJson(String geometry) {
|
||||||
|
|||||||
Reference in New Issue
Block a user