map sheet learn 변수타입 수정
This commit is contained in:
@@ -4,6 +4,7 @@ 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.repository.MapSheetLearnDataRepository;
|
import com.kamco.cd.kamcoback.postgres.repository.MapSheetLearnDataRepository;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -29,13 +30,13 @@ public class GeoJsonDataService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public List<Long> processGeoJsonFiles(Map<String, String> geoJsonContents, String archiveFileName) {
|
public List<Long> processGeoJsonFiles(Map<String, String> geoJsonContents, String archiveFileName) {
|
||||||
List<Long> savedIds = new ArrayList<>();
|
List<Long> savedIds = new ArrayList<>();
|
||||||
|
|
||||||
log.info("GeoJSON 파일 처리 시작: {} ({}개 파일)", archiveFileName, geoJsonContents.size());
|
log.info("GeoJSON 파일 처리 시작: {} ({}개 파일)", archiveFileName, geoJsonContents.size());
|
||||||
|
|
||||||
for (Map.Entry<String, String> entry : geoJsonContents.entrySet()) {
|
for (Map.Entry<String, String> entry : geoJsonContents.entrySet()) {
|
||||||
String fileName = entry.getKey();
|
String fileName = entry.getKey();
|
||||||
String geoJsonContent = entry.getValue();
|
String geoJsonContent = entry.getValue();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Long savedId = processGeoJsonFile(fileName, geoJsonContent, archiveFileName);
|
Long savedId = processGeoJsonFile(fileName, geoJsonContent, archiveFileName);
|
||||||
if (savedId != null) {
|
if (savedId != null) {
|
||||||
@@ -47,10 +48,10 @@ public class GeoJsonDataService {
|
|||||||
// 개별 파일 처리 실패는 전체 처리를 중단시키지 않음
|
// 개별 파일 처리 실패는 전체 처리를 중단시키지 않음
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("GeoJSON 파일 처리 완료: {} (성공: {}개, 전체: {}개)",
|
log.info("GeoJSON 파일 처리 완료: {} (성공: {}개, 전체: {}개)",
|
||||||
archiveFileName, savedIds.size(), geoJsonContents.size());
|
archiveFileName, savedIds.size(), geoJsonContents.size());
|
||||||
|
|
||||||
return savedIds;
|
return savedIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,22 +63,22 @@ public class GeoJsonDataService {
|
|||||||
// GeoJSON 파싱 및 검증
|
// GeoJSON 파싱 및 검증
|
||||||
JsonNode geoJsonNode = objectMapper.readTree(geoJsonContent);
|
JsonNode geoJsonNode = objectMapper.readTree(geoJsonContent);
|
||||||
validateGeoJsonStructure(geoJsonNode);
|
validateGeoJsonStructure(geoJsonNode);
|
||||||
|
|
||||||
// 파일이 이미 처리되었는지 확인
|
// 파일이 이미 처리되었는지 확인
|
||||||
String dataPath = generateDataPath(archiveFileName, fileName);
|
String dataPath = generateDataPath(archiveFileName, fileName);
|
||||||
Optional<MapSheetLearnDataEntity> existingData = mapSheetLearnDataRepository.findByDataPath(dataPath);
|
Optional<MapSheetLearnDataEntity> existingData = mapSheetLearnDataRepository.findByDataPath(dataPath);
|
||||||
|
|
||||||
if (existingData.isPresent()) {
|
if (existingData.isPresent()) {
|
||||||
log.warn("이미 처리된 파일입니다: {}", dataPath);
|
log.warn("이미 처리된 파일입니다: {}", dataPath);
|
||||||
return existingData.get().getId();
|
return existingData.get().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 새 엔티티 생성 및 저장
|
// 새 엔티티 생성 및 저장
|
||||||
MapSheetLearnDataEntity entity = createMapSheetLearnDataEntity(fileName, geoJsonContent, archiveFileName, geoJsonNode);
|
MapSheetLearnDataEntity entity = createMapSheetLearnDataEntity(fileName, geoJsonContent, archiveFileName, geoJsonNode);
|
||||||
MapSheetLearnDataEntity savedEntity = mapSheetLearnDataRepository.save(entity);
|
MapSheetLearnDataEntity savedEntity = mapSheetLearnDataRepository.save(entity);
|
||||||
|
|
||||||
return savedEntity.getId();
|
return savedEntity.getId();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("GeoJSON 파일 처리 중 오류 발생: {}", fileName, e);
|
log.error("GeoJSON 파일 처리 중 오류 발생: {}", fileName, e);
|
||||||
throw new RuntimeException("GeoJSON 파일 처리 실패: " + fileName, e);
|
throw new RuntimeException("GeoJSON 파일 처리 실패: " + fileName, e);
|
||||||
@@ -91,7 +92,7 @@ public class GeoJsonDataService {
|
|||||||
if (!geoJsonNode.has("type")) {
|
if (!geoJsonNode.has("type")) {
|
||||||
throw new IllegalArgumentException("유효하지 않은 GeoJSON: 'type' 필드가 없습니다.");
|
throw new IllegalArgumentException("유효하지 않은 GeoJSON: 'type' 필드가 없습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String type = geoJsonNode.get("type").asText();
|
String type = geoJsonNode.get("type").asText();
|
||||||
if (!"FeatureCollection".equals(type) && !"Feature".equals(type) && !"Geometry".equals(type)) {
|
if (!"FeatureCollection".equals(type) && !"Feature".equals(type) && !"Geometry".equals(type)) {
|
||||||
throw new IllegalArgumentException("지원하지 않는 GeoJSON type: " + type);
|
throw new IllegalArgumentException("지원하지 않는 GeoJSON type: " + type);
|
||||||
@@ -103,18 +104,18 @@ public class GeoJsonDataService {
|
|||||||
*/
|
*/
|
||||||
private MapSheetLearnDataEntity createMapSheetLearnDataEntity(
|
private MapSheetLearnDataEntity createMapSheetLearnDataEntity(
|
||||||
String fileName, String geoJsonContent, String archiveFileName, JsonNode geoJsonNode) {
|
String fileName, String geoJsonContent, String archiveFileName, JsonNode geoJsonNode) {
|
||||||
|
|
||||||
MapSheetLearnDataEntity entity = new MapSheetLearnDataEntity();
|
MapSheetLearnDataEntity entity = new MapSheetLearnDataEntity();
|
||||||
|
|
||||||
// 기본 정보 설정
|
// 기본 정보 설정
|
||||||
entity.setDataName(fileName);
|
entity.setDataName(fileName);
|
||||||
entity.setDataPath(generateDataPath(archiveFileName, fileName));
|
entity.setDataPath(generateDataPath(archiveFileName, fileName));
|
||||||
entity.setDataType("GeoJSON");
|
entity.setDataType("GeoJSON");
|
||||||
entity.setDataTitle(extractTitle(fileName, geoJsonNode));
|
entity.setDataTitle(extractTitle(fileName, geoJsonNode));
|
||||||
|
|
||||||
// CRS 정보 추출 및 설정
|
// CRS 정보 추출 및 설정
|
||||||
setCrsInformation(entity, geoJsonNode);
|
setCrsInformation(entity, geoJsonNode);
|
||||||
|
|
||||||
// JSON 데이터 저장
|
// JSON 데이터 저장
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -128,20 +129,20 @@ public class GeoJsonDataService {
|
|||||||
fallbackMap.put("parse_error", e.getMessage());
|
fallbackMap.put("parse_error", e.getMessage());
|
||||||
entity.setDataJson(fallbackMap);
|
entity.setDataJson(fallbackMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 연도 정보 추출 (파일명에서 추출 시도)
|
// 연도 정보 추출 (파일명에서 추출 시도)
|
||||||
setYearInformation(entity, fileName);
|
setYearInformation(entity, fileName);
|
||||||
|
|
||||||
// 상태 정보 설정
|
// 상태 정보 설정
|
||||||
entity.setDataState("PROCESSED");
|
entity.setDataState("PROCESSED");
|
||||||
entity.setAnalState("PENDING");
|
entity.setAnalState("PENDING");
|
||||||
|
|
||||||
// 시간 정보 설정
|
// 시간 정보 설정
|
||||||
Instant now = Instant.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
entity.setCreatedDttm(now);
|
entity.setCreatedDttm(now);
|
||||||
entity.setUpdatedDttm(now);
|
entity.setUpdatedDttm(now);
|
||||||
entity.setDataStateDttm(now);
|
entity.setDataStateDttm(now);
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +155,7 @@ public class GeoJsonDataService {
|
|||||||
if (crsNode.has("type") && crsNode.has("properties")) {
|
if (crsNode.has("type") && crsNode.has("properties")) {
|
||||||
String crsType = crsNode.get("type").asText();
|
String crsType = crsNode.get("type").asText();
|
||||||
entity.setDataCrsType(crsType);
|
entity.setDataCrsType(crsType);
|
||||||
|
|
||||||
JsonNode propertiesNode = crsNode.get("properties");
|
JsonNode propertiesNode = crsNode.get("properties");
|
||||||
if (propertiesNode.has("name")) {
|
if (propertiesNode.has("name")) {
|
||||||
String crsName = propertiesNode.get("name").asText();
|
String crsName = propertiesNode.get("name").asText();
|
||||||
@@ -207,13 +208,13 @@ public class GeoJsonDataService {
|
|||||||
return properties.get("name").asText();
|
return properties.get("name").asText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 파일명에서 확장자 제거하여 제목으로 사용
|
// 파일명에서 확장자 제거하여 제목으로 사용
|
||||||
int lastDotIndex = fileName.lastIndexOf('.');
|
int lastDotIndex = fileName.lastIndexOf('.');
|
||||||
if (lastDotIndex > 0) {
|
if (lastDotIndex > 0) {
|
||||||
return fileName.substring(0, lastDotIndex);
|
return fileName.substring(0, lastDotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,14 +232,14 @@ public class GeoJsonDataService {
|
|||||||
if (geoJsonContents == null || geoJsonContents.isEmpty()) {
|
if (geoJsonContents == null || geoJsonContents.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 최대 처리 가능한 파일 수 제한 (성능 고려)
|
// 최대 처리 가능한 파일 수 제한 (성능 고려)
|
||||||
int maxFiles = 50;
|
int maxFiles = 50;
|
||||||
if (geoJsonContents.size() > maxFiles) {
|
if (geoJsonContents.size() > maxFiles) {
|
||||||
log.warn("처리 가능한 최대 파일 수를 초과했습니다: {} > {}", geoJsonContents.size(), maxFiles);
|
log.warn("처리 가능한 최대 파일 수를 초과했습니다: {} > {}", geoJsonContents.size(), maxFiles);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnDataEntity;
|
|||||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnDataGeomEntity;
|
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.time.ZonedDateTime;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.locationtech.jts.geom.*;
|
import org.locationtech.jts.geom.*;
|
||||||
@@ -34,9 +35,9 @@ public class GeometryConversionService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public List<Long> convertToGeometryData(List<Long> learnDataIds) {
|
public List<Long> convertToGeometryData(List<Long> learnDataIds) {
|
||||||
List<Long> processedIds = new ArrayList<>();
|
List<Long> processedIds = new ArrayList<>();
|
||||||
|
|
||||||
log.info("Geometry 변환 시작: {} 개의 학습 데이터", learnDataIds.size());
|
log.info("Geometry 변환 시작: {} 개의 학습 데이터", learnDataIds.size());
|
||||||
|
|
||||||
for (Long dataId : learnDataIds) {
|
for (Long dataId : learnDataIds) {
|
||||||
try {
|
try {
|
||||||
if (dataId != null) {
|
if (dataId != null) {
|
||||||
@@ -54,7 +55,7 @@ public class GeometryConversionService {
|
|||||||
// 개별 변환 실패는 전체 처리를 중단시키지 않음
|
// 개별 변환 실패는 전체 처리를 중단시키지 않음
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Geometry 변환 완료: {} 개 처리, {} 개의 geometry 생성", learnDataIds.size(), processedIds.size());
|
log.info("Geometry 변환 완료: {} 개 처리, {} 개의 geometry 생성", learnDataIds.size(), processedIds.size());
|
||||||
return processedIds;
|
return processedIds;
|
||||||
}
|
}
|
||||||
@@ -64,22 +65,22 @@ public class GeometryConversionService {
|
|||||||
*/
|
*/
|
||||||
private List<Long> processLearnDataToGeometry(MapSheetLearnDataEntity learnData) {
|
private List<Long> processLearnDataToGeometry(MapSheetLearnDataEntity learnData) {
|
||||||
List<Long> geometryIds = new ArrayList<>();
|
List<Long> geometryIds = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 기존 geometry 데이터 삭제 (재생성)
|
// 기존 geometry 데이터 삭제 (재생성)
|
||||||
mapSheetLearnDataGeomRepository.deleteByDataUid(learnData.getId());
|
mapSheetLearnDataGeomRepository.deleteByDataUid(learnData.getId());
|
||||||
|
|
||||||
// JSON 데이터에서 GeoJSON 추출
|
// JSON 데이터에서 GeoJSON 추출
|
||||||
Map<String, Object> dataJson = learnData.getDataJson();
|
Map<String, Object> dataJson = learnData.getDataJson();
|
||||||
if (dataJson == null || dataJson.isEmpty()) {
|
if (dataJson == null || dataJson.isEmpty()) {
|
||||||
log.warn("JSON 데이터가 없습니다: {}", learnData.getId());
|
log.warn("JSON 데이터가 없습니다: {}", learnData.getId());
|
||||||
return geometryIds;
|
return geometryIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON을 GeoJSON으로 파싱
|
// JSON을 GeoJSON으로 파싱
|
||||||
String geoJsonString = objectMapper.writeValueAsString(dataJson);
|
String geoJsonString = objectMapper.writeValueAsString(dataJson);
|
||||||
JsonNode geoJsonNode = objectMapper.readTree(geoJsonString);
|
JsonNode geoJsonNode = objectMapper.readTree(geoJsonString);
|
||||||
|
|
||||||
// GeoJSON 타입에 따라 처리
|
// GeoJSON 타입에 따라 처리
|
||||||
String type = geoJsonNode.get("type").asText();
|
String type = geoJsonNode.get("type").asText();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -106,12 +107,12 @@ public class GeometryConversionService {
|
|||||||
default:
|
default:
|
||||||
log.warn("지원하지 않는 GeoJSON type: {} (데이터 ID: {})", type, learnData.getId());
|
log.warn("지원하지 않는 GeoJSON type: {} (데이터 ID: {})", type, learnData.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Geometry 변환 실패: 학습 데이터 ID {}", learnData.getId(), e);
|
log.error("Geometry 변환 실패: 학습 데이터 ID {}", learnData.getId(), e);
|
||||||
throw new RuntimeException("Geometry 변환 실패", e);
|
throw new RuntimeException("Geometry 변환 실패", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return geometryIds;
|
return geometryIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,12 +121,12 @@ public class GeometryConversionService {
|
|||||||
*/
|
*/
|
||||||
private List<Long> processFeatureCollection(JsonNode featureCollectionNode, MapSheetLearnDataEntity learnData) {
|
private List<Long> processFeatureCollection(JsonNode featureCollectionNode, MapSheetLearnDataEntity learnData) {
|
||||||
List<Long> geometryIds = new ArrayList<>();
|
List<Long> geometryIds = new ArrayList<>();
|
||||||
|
|
||||||
if (!featureCollectionNode.has("features")) {
|
if (!featureCollectionNode.has("features")) {
|
||||||
log.warn("FeatureCollection에 features 배열이 없습니다: {}", learnData.getId());
|
log.warn("FeatureCollection에 features 배열이 없습니다: {}", learnData.getId());
|
||||||
return geometryIds;
|
return geometryIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode featuresNode = featureCollectionNode.get("features");
|
JsonNode featuresNode = featureCollectionNode.get("features");
|
||||||
if (featuresNode.isArray()) {
|
if (featuresNode.isArray()) {
|
||||||
for (JsonNode featureNode : featuresNode) {
|
for (JsonNode featureNode : featuresNode) {
|
||||||
@@ -139,7 +140,7 @@ public class GeometryConversionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return geometryIds;
|
return geometryIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,12 +153,12 @@ public class GeometryConversionService {
|
|||||||
log.warn("Feature에 geometry가 없습니다: {}", learnData.getId());
|
log.warn("Feature에 geometry가 없습니다: {}", learnData.getId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode geometryNode = featureNode.get("geometry");
|
JsonNode geometryNode = featureNode.get("geometry");
|
||||||
JsonNode propertiesNode = featureNode.has("properties") ? featureNode.get("properties") : null;
|
JsonNode propertiesNode = featureNode.has("properties") ? featureNode.get("properties") : null;
|
||||||
|
|
||||||
return createGeometryEntity(geometryNode, propertiesNode, learnData);
|
return createGeometryEntity(geometryNode, propertiesNode, learnData);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Feature 처리 중 오류 (학습 데이터 ID: {})", learnData.getId(), e);
|
log.error("Feature 처리 중 오류 (학습 데이터 ID: {})", learnData.getId(), e);
|
||||||
return null;
|
return null;
|
||||||
@@ -177,18 +178,18 @@ public class GeometryConversionService {
|
|||||||
private Long createGeometryEntity(JsonNode geometryNode, JsonNode propertiesNode, MapSheetLearnDataEntity learnData) {
|
private Long createGeometryEntity(JsonNode geometryNode, JsonNode propertiesNode, MapSheetLearnDataEntity learnData) {
|
||||||
try {
|
try {
|
||||||
MapSheetLearnDataGeomEntity geometryEntity = new MapSheetLearnDataGeomEntity();
|
MapSheetLearnDataGeomEntity geometryEntity = new MapSheetLearnDataGeomEntity();
|
||||||
|
|
||||||
// 기본 정보 설정
|
// 기본 정보 설정
|
||||||
geometryEntity.setDataUid(learnData.getId());
|
geometryEntity.setDataUid(learnData.getId());
|
||||||
geometryEntity.setBeforeYyyy(learnData.getDataYyyy());
|
geometryEntity.setBeforeYyyy(learnData.getDataYyyy());
|
||||||
geometryEntity.setAfterYyyy(learnData.getCompareYyyy());
|
geometryEntity.setAfterYyyy(learnData.getCompareYyyy());
|
||||||
|
|
||||||
// Geometry 변환 및 설정
|
// Geometry 변환 및 설정
|
||||||
Geometry geometry = parseGeometryFromGeoJson(geometryNode);
|
Geometry geometry = parseGeometryFromGeoJson(geometryNode);
|
||||||
if (geometry != null) {
|
if (geometry != null) {
|
||||||
geometryEntity.setGeom(geometry);
|
geometryEntity.setGeom(geometry);
|
||||||
geometryEntity.setGeoType(geometry.getGeometryType());
|
geometryEntity.setGeoType(geometry.getGeometryType());
|
||||||
|
|
||||||
// 면적 계산 (Polygon인 경우)
|
// 면적 계산 (Polygon인 경우)
|
||||||
if (geometry instanceof Polygon || geometry.getGeometryType().contains("Polygon")) {
|
if (geometry instanceof Polygon || geometry.getGeometryType().contains("Polygon")) {
|
||||||
double area = geometry.getArea();
|
double area = geometry.getArea();
|
||||||
@@ -198,21 +199,21 @@ public class GeometryConversionService {
|
|||||||
log.warn("Geometry 변환 실패: {}", geometryNode);
|
log.warn("Geometry 변환 실패: {}", geometryNode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Properties에서 추가 정보 추출
|
// Properties에서 추가 정보 추출
|
||||||
if (propertiesNode != null) {
|
if (propertiesNode != null) {
|
||||||
extractPropertiesData(geometryEntity, propertiesNode, learnData);
|
extractPropertiesData(geometryEntity, propertiesNode, learnData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 시간 정보 설정
|
// 시간 정보 설정
|
||||||
Instant now = Instant.now();
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
geometryEntity.setCreatedDttm(now);
|
geometryEntity.setCreatedDttm(now);
|
||||||
geometryEntity.setUpdatedDttm(now);
|
geometryEntity.setUpdatedDttm(now);
|
||||||
|
|
||||||
// 저장
|
// 저장
|
||||||
MapSheetLearnDataGeomEntity savedEntity = mapSheetLearnDataGeomRepository.save(geometryEntity);
|
MapSheetLearnDataGeomEntity savedEntity = mapSheetLearnDataGeomRepository.save(geometryEntity);
|
||||||
return savedEntity.getId();
|
return savedEntity.getId();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("GeometryEntity 생성 실패 (학습 데이터 ID: {})", learnData.getId(), e);
|
log.error("GeometryEntity 생성 실패 (학습 데이터 ID: {})", learnData.getId(), e);
|
||||||
return null;
|
return null;
|
||||||
@@ -228,10 +229,10 @@ public class GeometryConversionService {
|
|||||||
log.warn("유효하지 않은 Geometry 형식: type 또는 coordinates가 없습니다.");
|
log.warn("유효하지 않은 Geometry 형식: type 또는 coordinates가 없습니다.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String geometryType = geometryNode.get("type").asText();
|
String geometryType = geometryNode.get("type").asText();
|
||||||
JsonNode coordinatesNode = geometryNode.get("coordinates");
|
JsonNode coordinatesNode = geometryNode.get("coordinates");
|
||||||
|
|
||||||
switch (geometryType.toLowerCase()) {
|
switch (geometryType.toLowerCase()) {
|
||||||
case "point":
|
case "point":
|
||||||
return createPoint(coordinatesNode);
|
return createPoint(coordinatesNode);
|
||||||
@@ -249,7 +250,7 @@ public class GeometryConversionService {
|
|||||||
log.warn("지원하지 않는 Geometry 타입: {}", geometryType);
|
log.warn("지원하지 않는 Geometry 타입: {}", geometryType);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Geometry 파싱 실패", e);
|
log.error("Geometry 파싱 실패", e);
|
||||||
return null;
|
return null;
|
||||||
@@ -275,7 +276,7 @@ public class GeometryConversionService {
|
|||||||
|
|
||||||
private Polygon createPolygon(JsonNode coordinatesNode) {
|
private Polygon createPolygon(JsonNode coordinatesNode) {
|
||||||
if (coordinatesNode.size() == 0) return null;
|
if (coordinatesNode.size() == 0) return null;
|
||||||
|
|
||||||
// Exterior ring
|
// Exterior ring
|
||||||
JsonNode exteriorRing = coordinatesNode.get(0);
|
JsonNode exteriorRing = coordinatesNode.get(0);
|
||||||
List<Coordinate> coords = new ArrayList<>();
|
List<Coordinate> coords = new ArrayList<>();
|
||||||
@@ -284,16 +285,16 @@ public class GeometryConversionService {
|
|||||||
coords.add(new Coordinate(coordNode.get(0).asDouble(), coordNode.get(1).asDouble()));
|
coords.add(new Coordinate(coordNode.get(0).asDouble(), coordNode.get(1).asDouble()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (coords.size() < 3) return null;
|
if (coords.size() < 3) return null;
|
||||||
|
|
||||||
// Close ring if not already closed
|
// Close ring if not already closed
|
||||||
if (!coords.get(0).equals2D(coords.get(coords.size() - 1))) {
|
if (!coords.get(0).equals2D(coords.get(coords.size() - 1))) {
|
||||||
coords.add(new Coordinate(coords.get(0)));
|
coords.add(new Coordinate(coords.get(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearRing shell = geometryFactory.createLinearRing(coords.toArray(new Coordinate[0]));
|
LinearRing shell = geometryFactory.createLinearRing(coords.toArray(new Coordinate[0]));
|
||||||
|
|
||||||
// Interior rings (holes)
|
// Interior rings (holes)
|
||||||
LinearRing[] holes = new LinearRing[coordinatesNode.size() - 1];
|
LinearRing[] holes = new LinearRing[coordinatesNode.size() - 1];
|
||||||
for (int i = 1; i < coordinatesNode.size(); i++) {
|
for (int i = 1; i < coordinatesNode.size(); i++) {
|
||||||
@@ -311,7 +312,7 @@ public class GeometryConversionService {
|
|||||||
holes[i - 1] = geometryFactory.createLinearRing(holeCoords.toArray(new Coordinate[0]));
|
holes[i - 1] = geometryFactory.createLinearRing(holeCoords.toArray(new Coordinate[0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return geometryFactory.createPolygon(shell, holes);
|
return geometryFactory.createPolygon(shell, holes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +362,7 @@ public class GeometryConversionService {
|
|||||||
log.debug("cd_prob 파싱 실패", e);
|
log.debug("cd_prob 파싱 실패", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before class 정보
|
// Before class 정보
|
||||||
if (propertiesNode.has("class_before_name")) {
|
if (propertiesNode.has("class_before_name")) {
|
||||||
geometryEntity.setClassBeforeName(propertiesNode.get("class_before_name").asText());
|
geometryEntity.setClassBeforeName(propertiesNode.get("class_before_name").asText());
|
||||||
@@ -374,7 +375,7 @@ public class GeometryConversionService {
|
|||||||
log.debug("class_before_prob 파싱 실패", e);
|
log.debug("class_before_prob 파싱 실패", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// After class 정보
|
// After class 정보
|
||||||
if (propertiesNode.has("class_after_name")) {
|
if (propertiesNode.has("class_after_name")) {
|
||||||
geometryEntity.setClassAfterName(propertiesNode.get("class_after_name").asText());
|
geometryEntity.setClassAfterName(propertiesNode.get("class_after_name").asText());
|
||||||
@@ -387,7 +388,7 @@ public class GeometryConversionService {
|
|||||||
log.debug("class_after_prob 파싱 실패", e);
|
log.debug("class_after_prob 파싱 실패", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 도엽 번호
|
// 도엽 번호
|
||||||
if (propertiesNode.has("map_sheet_num")) {
|
if (propertiesNode.has("map_sheet_num")) {
|
||||||
try {
|
try {
|
||||||
@@ -397,7 +398,7 @@ public class GeometryConversionService {
|
|||||||
log.debug("map_sheet_num 파싱 실패", e);
|
log.debug("map_sheet_num 파싱 실패", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 면적 (properties에서 제공되는 경우)
|
// 면적 (properties에서 제공되는 경우)
|
||||||
if (propertiesNode.has("area")) {
|
if (propertiesNode.has("area")) {
|
||||||
try {
|
try {
|
||||||
@@ -416,24 +417,24 @@ public class GeometryConversionService {
|
|||||||
public List<Long> processUnprocessedLearnData() {
|
public List<Long> processUnprocessedLearnData() {
|
||||||
// 분석 상태가 PENDING인 학습 데이터 조회
|
// 분석 상태가 PENDING인 학습 데이터 조회
|
||||||
List<MapSheetLearnDataEntity> unprocessedData = mapSheetLearnDataRepository.findByAnalState("PENDING");
|
List<MapSheetLearnDataEntity> unprocessedData = mapSheetLearnDataRepository.findByAnalState("PENDING");
|
||||||
|
|
||||||
if (unprocessedData.isEmpty()) {
|
if (unprocessedData.isEmpty()) {
|
||||||
log.debug("처리할 미완료 학습 데이터가 없습니다.");
|
log.debug("처리할 미완료 학습 데이터가 없습니다.");
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("미처리 학습 데이터 {}개에 대해 geometry 변환을 수행합니다.", unprocessedData.size());
|
log.info("미처리 학습 데이터 {}개에 대해 geometry 변환을 수행합니다.", unprocessedData.size());
|
||||||
|
|
||||||
List<Long> processedIds = new ArrayList<>();
|
List<Long> processedIds = new ArrayList<>();
|
||||||
for (MapSheetLearnDataEntity data : unprocessedData) {
|
for (MapSheetLearnDataEntity data : unprocessedData) {
|
||||||
try {
|
try {
|
||||||
List<Long> geometryIds = processLearnDataToGeometry(data);
|
List<Long> geometryIds = processLearnDataToGeometry(data);
|
||||||
processedIds.addAll(geometryIds);
|
processedIds.addAll(geometryIds);
|
||||||
|
|
||||||
// 처리 완료 상태로 업데이트
|
// 처리 완료 상태로 업데이트
|
||||||
data.setAnalState("COMPLETED");
|
data.setAnalState("COMPLETED");
|
||||||
mapSheetLearnDataRepository.save(data);
|
mapSheetLearnDataRepository.save(data);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("미처리 학습 데이터 처리 실패: {}", data.getId(), e);
|
log.error("미처리 학습 데이터 처리 실패: {}", data.getId(), e);
|
||||||
// 실패한 경우 ERROR 상태로 설정
|
// 실패한 경우 ERROR 상태로 설정
|
||||||
@@ -441,7 +442,7 @@ public class GeometryConversionService {
|
|||||||
mapSheetLearnDataRepository.save(data);
|
mapSheetLearnDataRepository.save(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return processedIds;
|
return processedIds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
package com.kamco.cd.kamcoback.postgres.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.JdbcTypeCode;
|
||||||
|
import org.hibernate.type.SqlTypes;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "tb_map_sheet_learn_data")
|
||||||
|
public class MapSheetLearnDataEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "data_uid", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "anal_end_dttm")
|
||||||
|
private ZonedDateTime analEndDttm;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "anal_map_sheet")
|
||||||
|
private String analMapSheet;
|
||||||
|
|
||||||
|
@Column(name = "anal_sec")
|
||||||
|
private Long analSec;
|
||||||
|
|
||||||
|
@Size(max = 20)
|
||||||
|
@Column(name = "anal_state", length = 20)
|
||||||
|
private String analState;
|
||||||
|
|
||||||
|
@Column(name = "anal_strt_dttm")
|
||||||
|
private ZonedDateTime analStrtDttm;
|
||||||
|
|
||||||
|
@Column(name = "compare_yyyy")
|
||||||
|
private Integer compareYyyy;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "created_dttm")
|
||||||
|
private ZonedDateTime createdDttm;
|
||||||
|
|
||||||
|
@Column(name = "created_uid")
|
||||||
|
private Long createdUid;
|
||||||
|
|
||||||
|
@Size(max = 128)
|
||||||
|
@Column(name = "data_crs_type", length = 128)
|
||||||
|
private String dataCrsType;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "data_crs_type_name")
|
||||||
|
private String dataCrsTypeName;
|
||||||
|
|
||||||
|
@Column(name = "data_json")
|
||||||
|
@JdbcTypeCode(SqlTypes.JSON)
|
||||||
|
private Map<String, Object> dataJson;
|
||||||
|
|
||||||
|
@Size(max = 128)
|
||||||
|
@Column(name = "data_name", length = 128)
|
||||||
|
private String dataName;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "data_path")
|
||||||
|
private String dataPath;
|
||||||
|
|
||||||
|
@Size(max = 20)
|
||||||
|
@Column(name = "data_state", length = 20)
|
||||||
|
private String dataState;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "data_state_dttm")
|
||||||
|
private ZonedDateTime dataStateDttm;
|
||||||
|
|
||||||
|
@Size(max = 255)
|
||||||
|
@Column(name = "data_title")
|
||||||
|
private String dataTitle;
|
||||||
|
|
||||||
|
@Size(max = 128)
|
||||||
|
@Column(name = "data_type", length = 128)
|
||||||
|
private String dataType;
|
||||||
|
|
||||||
|
@Column(name = "data_yyyy")
|
||||||
|
private Integer dataYyyy;
|
||||||
|
|
||||||
|
@Size(max = 20)
|
||||||
|
@Column(name = "gukuin_used", length = 20)
|
||||||
|
private String gukuinUsed;
|
||||||
|
|
||||||
|
@Column(name = "gukuin_used_dttm")
|
||||||
|
private ZonedDateTime gukuinUsedDttm;
|
||||||
|
|
||||||
|
@ColumnDefault("now()")
|
||||||
|
@Column(name = "updated_dttm")
|
||||||
|
private ZonedDateTime updatedDttm;
|
||||||
|
|
||||||
|
@Column(name = "updated_uid")
|
||||||
|
private Long updatedUid;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.kamco.cd.kamcoback.postgres.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
|
import org.locationtech.jts.geom.Geometry;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@Table(name = "tb_map_sheet_learn_data_geom")
|
||||||
|
public class MapSheetLearnDataGeomEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "geo_uid", nullable = false)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "after_yyyy")
|
||||||
|
private Integer afterYyyy;
|
||||||
|
|
||||||
|
@Column(name = "area")
|
||||||
|
private Double area;
|
||||||
|
|
||||||
|
@Column(name = "before_yyyy")
|
||||||
|
private Integer beforeYyyy;
|
||||||
|
|
||||||
|
@Column(name = "cd_prob")
|
||||||
|
private Double cdProb;
|
||||||
|
|
||||||
|
@Size(max = 100)
|
||||||
|
@Column(name = "class_after_name", length = 100)
|
||||||
|
private String classAfterName;
|
||||||
|
|
||||||
|
@Column(name = "class_after_prob")
|
||||||
|
private Double classAfterProb;
|
||||||
|
|
||||||
|
@Size(max = 100)
|
||||||
|
@Column(name = "class_before_name", length = 100)
|
||||||
|
private String classBeforeName;
|
||||||
|
|
||||||
|
@Column(name = "class_before_prob")
|
||||||
|
private Double classBeforeProb;
|
||||||
|
|
||||||
|
@Column(name = "created_dttm")
|
||||||
|
private ZonedDateTime createdDttm;
|
||||||
|
|
||||||
|
@Column(name = "created_uid")
|
||||||
|
private Long createdUid;
|
||||||
|
|
||||||
|
private Long dataUid;
|
||||||
|
|
||||||
|
@Size(max = 100)
|
||||||
|
@Column(name = "geo_type", length = 100)
|
||||||
|
private String geoType;
|
||||||
|
|
||||||
|
@Column(name = "geom")
|
||||||
|
private Geometry geom;
|
||||||
|
|
||||||
|
@Column(name = "map_sheet_num")
|
||||||
|
private Long mapSheetNum;
|
||||||
|
|
||||||
|
@Column(name = "updated_dttm")
|
||||||
|
private ZonedDateTime updatedDttm;
|
||||||
|
|
||||||
|
@Column(name = "updated_uid")
|
||||||
|
private Long updatedUid;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user