Geojson DATA Operation change to Stable - Daniel C No.7
This commit is contained in:
@@ -61,8 +61,23 @@ public class GeometryConversionService {
|
|||||||
List<Long> geometryIds = new ArrayList<>();
|
List<Long> geometryIds = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 기존 geometry 데이터 삭제 (재생성)
|
// 기존 geometry 데이터 확인 - 데이터가 이미 존재하고 유효한 경우 재처리 건너뛰기
|
||||||
mapSheetLearnDataGeomRepository.deleteByDataUid(learnData.getId());
|
List<MapSheetLearnDataGeomEntity> existingGeoms = mapSheetLearnDataGeomRepository.findByDataUid(learnData.getId());
|
||||||
|
if (!existingGeoms.isEmpty() && isValidGeometryData(existingGeoms)) {
|
||||||
|
log.debug("유효한 geometry 데이터가 이미 존재합니다. 재처리를 건너뜁니다: {}", learnData.getId());
|
||||||
|
return existingGeoms.stream().map(MapSheetLearnDataGeomEntity::getId).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 유효하지 않은 데이터만 조건부 삭제 (null geometry 또는 잘못된 형식)
|
||||||
|
if (!existingGeoms.isEmpty()) {
|
||||||
|
List<MapSheetLearnDataGeomEntity> invalidGeoms = existingGeoms.stream()
|
||||||
|
.filter(g -> g.getGeom() == null || g.getGeom().isEmpty())
|
||||||
|
.toList();
|
||||||
|
if (!invalidGeoms.isEmpty()) {
|
||||||
|
mapSheetLearnDataGeomRepository.deleteAll(invalidGeoms);
|
||||||
|
log.debug("유효하지 않은 geometry 데이터만 삭제했습니다: {}개", invalidGeoms.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// JSON 데이터에서 GeoJSON 추출
|
// JSON 데이터에서 GeoJSON 추출
|
||||||
Map<String, Object> dataJson = learnData.getDataJson();
|
Map<String, Object> dataJson = learnData.getDataJson();
|
||||||
@@ -433,4 +448,15 @@ public class GeometryConversionService {
|
|||||||
|
|
||||||
return processedIds;
|
return processedIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Geometry 데이터의 유효성 검사 */
|
||||||
|
private boolean isValidGeometryData(List<MapSheetLearnDataGeomEntity> geometryEntities) {
|
||||||
|
if (geometryEntities == null || geometryEntities.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 모든 geometry가 null이 아니고 유효한지 확인
|
||||||
|
return geometryEntities.stream()
|
||||||
|
.allMatch(entity -> entity.getGeom() != null && !entity.getGeom().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,12 @@ public interface MapSheetLearnDataGeomRepository
|
|||||||
/** 지오메트리 타입별 조회 */
|
/** 지오메트리 타입별 조회 */
|
||||||
List<MapSheetLearnDataGeomEntity> findByGeoType(String geoType);
|
List<MapSheetLearnDataGeomEntity> findByGeoType(String geoType);
|
||||||
|
|
||||||
/** 데이터 UID로 기존 지오메트리 데이터 삭제 (재생성 전에 사용) */
|
/** 데이터 UID로 유효하지 않은 지오메트리 데이터만 조건부 삭제 (안전성을 위해 직접 사용 금지) */
|
||||||
void deleteByDataUid(Long dataUid);
|
@Deprecated
|
||||||
|
@Query("DELETE FROM MapSheetLearnDataGeomEntity g WHERE g.dataUid = :dataUid AND (g.geom IS NULL OR g.geom.isEmpty() = true)")
|
||||||
|
@Modifying
|
||||||
|
@Transactional
|
||||||
|
void deleteInvalidGeometryByDataUid(@Param("dataUid") Long dataUid);
|
||||||
|
|
||||||
/** PostGIS 함수를 사용하여 geometry 데이터를 직접 삽입 ST_SetSRID(ST_GeomFromGeoJSON(...), 5186) 형식으로 저장 */
|
/** PostGIS 함수를 사용하여 geometry 데이터를 직접 삽입 ST_SetSRID(ST_GeomFromGeoJSON(...), 5186) 형식으로 저장 */
|
||||||
@Modifying
|
@Modifying
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
spring:
|
spring:
|
||||||
config:
|
config:
|
||||||
activate:
|
activate:
|
||||||
on-profile: dev
|
on-profile: prod
|
||||||
|
|
||||||
jpa:
|
jpa:
|
||||||
show-sql: false
|
show-sql: false
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ spring:
|
|||||||
leak-detection-threshold: 60000
|
leak-detection-threshold: 60000
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: update # 테이블이 없으면 생성, 있으면 업데이트
|
ddl-auto: validate # 스키마 검증만 수행, 자동 변경하지 않음 (안전)
|
||||||
properties:
|
properties:
|
||||||
hibernate:
|
hibernate:
|
||||||
jdbc:
|
jdbc:
|
||||||
|
|||||||
@@ -4,11 +4,25 @@
|
|||||||
-- 1. First ensure PostGIS is enabled
|
-- 1. First ensure PostGIS is enabled
|
||||||
CREATE EXTENSION IF NOT EXISTS postgis;
|
CREATE EXTENSION IF NOT EXISTS postgis;
|
||||||
|
|
||||||
-- 2. Clear existing data since it's in incorrect format (JTS serialized objects)
|
-- 2. Check if column needs to be recreated (only if it's bytea type)
|
||||||
-- This data needs to be reprocessed anyway with the correct PostGIS approach
|
-- Only clear data if the column type is incorrect and needs conversion
|
||||||
DELETE FROM public.tb_map_sheet_learn_data_geom;
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
-- Only delete data if geom column exists and is bytea type
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT 1 FROM information_schema.columns
|
||||||
|
WHERE table_name = 'tb_map_sheet_learn_data_geom'
|
||||||
|
AND column_name = 'geom'
|
||||||
|
AND data_type = 'bytea'
|
||||||
|
) THEN
|
||||||
|
DELETE FROM public.tb_map_sheet_learn_data_geom WHERE geom IS NOT NULL;
|
||||||
|
RAISE NOTICE 'Cleared incorrect bytea geometry data for conversion';
|
||||||
|
ELSE
|
||||||
|
RAISE NOTICE 'Geometry column is already correct type, skipping data deletion';
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
-- 3. Drop and recreate the geom column with correct PostGIS geometry type
|
-- 3. Drop and recreate the geom column with correct PostGIS geometry type (only if needed)
|
||||||
ALTER TABLE public.tb_map_sheet_learn_data_geom DROP COLUMN IF EXISTS geom;
|
ALTER TABLE public.tb_map_sheet_learn_data_geom DROP COLUMN IF EXISTS geom;
|
||||||
ALTER TABLE public.tb_map_sheet_learn_data_geom ADD COLUMN geom geometry(Polygon, 5186);
|
ALTER TABLE public.tb_map_sheet_learn_data_geom ADD COLUMN geom geometry(Polygon, 5186);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user