변화탐지 API 커밋, 에러로그 진행중

This commit is contained in:
2025-11-28 18:05:36 +09:00
parent 9a06955e32
commit 55564cfce6
11 changed files with 259 additions and 73 deletions

View File

@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
@Tag(name = "변화탐지", description = "변화탐지 API")
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/change-detection")
@RequestMapping({"/api/change-detection", "/demo/api/change-detection"})
@Transactional
public class ChangeDetectionApiController {
@@ -41,11 +41,12 @@ public class ChangeDetectionApiController {
}
@Operation(summary = "변화탐지 분류별 건수", description = "변화탐지 분류별 건수")
@GetMapping("/class-count/{id}")
@GetMapping("/class-count")
public ApiResponseDto<List<ChangeDetectionDto.CountDto>> getChangeDetectionClassCount(
@Parameter(description = "변화탐지 년도(차수) /year-list 의 analUid", example = "1") @PathVariable
Long id) {
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionClassCount(id));
@Parameter(description = "변화탐지 년도(차수) /year-list 의 analUid", example = "1") @RequestParam
Long id,
@Parameter(description = "탐지된 도엽번호", example = "34602060") @RequestParam String mapSheetNum) {
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionClassCount(id, mapSheetNum));
}
@Operation(summary = "변화탐지 COG Url", description = "변화탐지 COG Url")
@@ -64,4 +65,29 @@ public class ChangeDetectionApiController {
public ApiResponseDto<List<ChangeDetectionDto.AnalYearList>> getChangeDetectionYearList() {
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionYearList());
}
@Operation(summary = "변화탐지 탐지된 도엽 목록", description = "변화탐지 탐지된 도엽 목록")
@GetMapping("/map-list")
public ApiResponseDto<List<ChangeDetectionDto.MapSheetList>> getChangeDetectionMapSheetList(
@Parameter(description = "년도목록 id", example = "1") @RequestParam Long analUid) {
return ApiResponseDto.ok(changeDetectionService.getChangeDetectionMapSheetList(analUid));
}
@Operation(summary = "변화탐지 결과 Polygon", description = "변화탐지 결과 Polygon")
@GetMapping("/polygon")
public ApiResponseDto<List<ChangeDetectionDto.PolygonGeometry>> getChangeDetectionPolygonList(
@Parameter(description = "년도목록 id", example = "1") @RequestParam Long analUid,
@Parameter(description = "도엽번호", example = "34602060") @RequestParam String mapSheetNum) {
return ApiResponseDto.ok(
changeDetectionService.getChangeDetectionPolygonList(analUid, mapSheetNum));
}
@Operation(summary = "변화탐지 결과 Point", description = "변화탐지 결과 Point")
@GetMapping("/point")
public ApiResponseDto<List<ChangeDetectionDto.PointGeometry>> getChangeDetectionPointList(
@Parameter(description = "년도목록 id", example = "1") @RequestParam Long analUid,
@Parameter(description = "도엽번호", example = "34602060") @RequestParam String mapSheetNum) {
return ApiResponseDto.ok(
changeDetectionService.getChangeDetectionPointList(analUid, mapSheetNum));
}
}

View File

@@ -18,7 +18,6 @@ public class ChangeDetectionDto {
private Long id;
private Geometry polygon;
private Double centroidX;
;
private Double centroidY;
}
@@ -68,6 +67,17 @@ public class ChangeDetectionDto {
private String baseMapSheetNum;
}
@Schema(name = "MapSheetList", description = "년도에 해당하는 도엽 목록")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class MapSheetList {
private String mapSheetNum;
private String mapSheetName;
private String alias;
}
@Schema(name = "PolygonGeometry", description = "폴리곤 리턴 객체")
@Getter
@Setter
@@ -75,37 +85,30 @@ public class ChangeDetectionDto {
@AllArgsConstructor
public static class PointGeometry {
private Long geoUid;
private String type; // "Point"
private Geometry coordinates; // Point 값
private String before_class; // 기준 분류
private String after_class; // 비교 분류
private Geometry geometry; // Point
private String classCd; // after 분류
}
@Schema(name = "PolygonGeometry", description = "폴리곤 리턴 객체")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class PolygonGeometry {
private Long geoUid;
private String type; // "MultiPolygon"
private Geometry coordinates; // Polygon 값
private Double center_latitude; // 폴리곤 중심 위도
private Double center_longitude; // 폴리곤 중심 경도
private Geometry geometry; // Polygon
private PolygonProperties properties;
}
@Schema(name = "PolygonProperties", description = "폴리곤 정보")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class PolygonProperties {
private Double area; // 면적
private String before_year; // 기준년도
private Double before_confidence; // 기준 신뢰도(확률)
private String before_class; // 기준 분류
private String after_year; // 비교년도
private Double after_confidence; // 비교 신뢰도(확률)
private String after_class; // 비교 분류
private Integer beforeYear; // 기준년도
private Double beforeConfidence; // 기준 신뢰도(확률)
private String beforeClass; // 기준 분류
private Integer afterYear; // 비교년도
private Double afterConfidence; // 비교 신뢰도(확률)
private String afterClass; // 비교 분류
}
}

View File

@@ -21,8 +21,9 @@ public class ChangeDetectionService {
return changeDetectionCoreService.getPolygonToJson();
}
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id) {
return changeDetectionCoreService.getChangeDetectionClassCount(id);
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(
Long id, String mapSheetNum) {
return changeDetectionCoreService.getChangeDetectionClassCount(id, mapSheetNum);
}
public ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req) {
@@ -32,4 +33,18 @@ public class ChangeDetectionService {
public List<ChangeDetectionDto.AnalYearList> getChangeDetectionYearList() {
return changeDetectionCoreService.getChangeDetectionYearList();
}
public List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
Long analUid, String mapSheetNum) {
return changeDetectionCoreService.getChangeDetectionPolygonList(analUid, mapSheetNum);
}
public List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
Long analUid, String mapSheetNum) {
return changeDetectionCoreService.getChangeDetectionPointList(analUid, mapSheetNum);
}
public List<ChangeDetectionDto.MapSheetList> getChangeDetectionMapSheetList(Long analUid) {
return changeDetectionCoreService.getChangeDetectionMapSheetList(analUid);
}
}

View File

@@ -41,4 +41,14 @@ public enum DetectionClassification {
return ETC;
}
}
/**
* Desc 한글명 get 하기
*
* @return
*/
public static String fromStrDesc(String text) {
DetectionClassification dtf = fromString(text);
return dtf.getDesc();
}
}

View File

@@ -31,11 +31,18 @@ public class ErrorLogApiController {
@RequestParam(required = false) LocalDate endDate,
@RequestParam int page,
@RequestParam(defaultValue = "20") int size) {
ErrorLogDto.ErrorSearchReq searchReq =
new ErrorLogDto.ErrorSearchReq(
logErrorLevel, eventType, startDate, endDate, page, size, "created_dttm,desc");
Page<ErrorLogDto.Basic> result = errorLogService.findLogByError(searchReq);
try {
return ApiResponseDto.ok(result);
ErrorLogDto.ErrorSearchReq searchReq =
new ErrorLogDto.ErrorSearchReq(
logErrorLevel, eventType, startDate, endDate, page, size, "created_dttm,desc");
Page<ErrorLogDto.Basic> result = errorLogService.findLogByError(searchReq);
return ApiResponseDto.ok(result);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -1,11 +1,8 @@
package com.kamco.cd.kamcoback.log.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
import com.kamco.cd.kamcoback.config.enums.EnumType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -18,43 +15,21 @@ public class ErrorLogDto {
@Schema(name = "ErrorLogBasic", description = "에러로그 기본 정보")
@Getter
@Setter
@AllArgsConstructor
public static class Basic {
@JsonIgnore private final Long id;
private final String requestId;
private final Long id;
private final String serviceName;
private final String menuNm;
private final String loginId;
private final String userName;
private final EventType errorType;
private final String errorName;
private final LogErrorLevel errorLevel;
private final String errorCode;
private final String errorMessage;
private final String stackTrace;
private final Long handlerUid;
@JsonFormatDttm private final ZonedDateTime handledDttm;
@JsonFormatDttm private final ZonedDateTime createdDttm;
public Basic(
Long id,
String requestId,
EventType errorType,
LogErrorLevel errorLevel,
String errorCode,
String errorMessage,
String stackTrace,
Long handlerUid,
ZonedDateTime handledDttm,
ZonedDateTime createdDttm) {
this.id = id;
this.requestId = requestId;
this.errorType = errorType;
this.errorLevel = errorLevel;
this.errorCode = errorCode;
this.errorMessage = errorMessage;
this.stackTrace = stackTrace;
this.handlerUid = handlerUid;
this.handledDttm = handledDttm;
this.createdDttm = createdDttm;
}
private final String createDate; // to_char해서 가져옴
}
@Schema(name = "ErrorSearchReq", description = "에러로그 검색 요청")

View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kamco.cd.kamcoback.changedetection.dto.ChangeDetectionDto;
import com.kamco.cd.kamcoback.common.enums.DetectionClassification;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetAnalDataGeomEntity;
import com.kamco.cd.kamcoback.postgres.repository.changedetection.ChangeDetectionRepository;
import java.util.List;
@@ -51,8 +52,20 @@ public class ChangeDetectionCoreService {
.collect(Collectors.toList());
}
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id) {
return changeDetectionRepository.getChangeDetectionClassCount(id);
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(
Long id, String mapSheetNum) {
List<ChangeDetectionDto.CountDto> list =
changeDetectionRepository.getChangeDetectionClassCount(id, mapSheetNum);
return list.stream()
.map(
s -> {
String classCd = String.valueOf(s.getClassCd());
s.setClassCd(DetectionClassification.fromString(classCd).name());
s.setClassName(DetectionClassification.fromStrDesc(classCd));
return s;
})
.collect(Collectors.toList());
}
public ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req) {
@@ -62,4 +75,27 @@ public class ChangeDetectionCoreService {
public List<ChangeDetectionDto.AnalYearList> getChangeDetectionYearList() {
return changeDetectionRepository.getChangeDetectionYearList();
}
public List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
Long analUid, String mapSheetNum) {
return changeDetectionRepository.getChangeDetectionPolygonList(analUid, mapSheetNum);
}
public List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
Long analUid, String mapSheetNum) {
return changeDetectionRepository.getChangeDetectionPointList(analUid, mapSheetNum);
}
public List<ChangeDetectionDto.MapSheetList> getChangeDetectionMapSheetList(Long analUid) {
List<ChangeDetectionDto.MapSheetList> list =
changeDetectionRepository.getChangeDetectionMapSheetList(analUid);
return list.stream()
.map(
s -> {
String name = s.getMapSheetName();
s.setAlias(name + s.getMapSheetNum().substring(5, 8));
return s;
})
.collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,34 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.common.utils.interfaces.JsonFormatDttm;
import jakarta.persistence.*;
import java.time.ZonedDateTime;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Table(name = "demo_learning_analysis_scene_item")
@Entity
public class DemoLearningAnalysisSceneItemEntity {
@Id
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "demo_learning_analysis_scene_item_group_item_id_gen")
@SequenceGenerator(
name = "demo_learning_analysis_scene_item_group_item_id_gen",
sequenceName = "demo_learning_analysis_scene_item_group_item_id_seq",
allocationSize = 1)
@Column(name = "group_item_id", nullable = false)
private Long id;
@Column(name = "group_id")
private Long groupId;
@Column(name = "fid")
private Long fid;
@JsonFormatDttm
@Column(name = "created_dttm")
private ZonedDateTime createdDttm;
}

View File

@@ -9,9 +9,17 @@ public interface ChangeDetectionRepositoryCustom {
List<String> findPolygonJson();
List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id);
List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id, String mapSheetNum);
ChangeDetectionDto.CogUrlDto getChangeDetectionCogUrl(ChangeDetectionDto.CogUrlReq req);
List<ChangeDetectionDto.AnalYearList> getChangeDetectionYearList();
List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
Long analUid, String mapSheetNum);
List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
Long analUid, String mapSheetNum);
List<ChangeDetectionDto.MapSheetList> getChangeDetectionMapSheetList(Long analUid);
}

View File

@@ -1,5 +1,6 @@
package com.kamco.cd.kamcoback.postgres.repository.changedetection;
import static com.kamco.cd.kamcoback.postgres.entity.QDemoLearningAnalysisSceneItemEntity.demoLearningAnalysisSceneItemEntity;
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;
@@ -13,6 +14,7 @@ import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
@@ -43,20 +45,23 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
}
@Override
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(Long id) {
public List<ChangeDetectionDto.CountDto> getChangeDetectionClassCount(
Long id, String mapSheetNum) {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.CountDto.class,
mapSheetAnalSttcEntity.classAfterCd.toUpperCase(),
null, // TOOD classAfterName 삭제해서 수정 필요
mapSheetAnalSttcEntity.classAfterCd.as("classCd"),
mapSheetAnalSttcEntity.classAfterCd.as("classNm"), // 앞단 CoreService 에서 한글명으로 변환
mapSheetAnalSttcEntity.classAfterCnt.sum()))
.from(mapSheetAnalEntity)
.innerJoin(mapSheetAnalDataEntity)
.on(mapSheetAnalDataEntity.analUid.eq(mapSheetAnalEntity.id))
.innerJoin(mapSheetAnalSttcEntity)
.on(mapSheetAnalSttcEntity.dataUid.eq(mapSheetAnalDataEntity.id))
.where(mapSheetAnalEntity.id.eq(id))
.where(
mapSheetAnalEntity.id.eq(id),
mapSheetAnalSttcEntity.id.mapSheetNum.eq(Long.valueOf(mapSheetNum)))
.groupBy(mapSheetAnalSttcEntity.classAfterCd)
.fetch();
}
@@ -99,6 +104,72 @@ public class ChangeDetectionRepositoryImpl extends QuerydslRepositorySupport
.fetch();
}
@Override
public List<ChangeDetectionDto.PolygonGeometry> getChangeDetectionPolygonList(
Long analUid, String mapSheetNum) {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.PolygonGeometry.class,
mapSheetAnalDataGeomEntity.id,
mapSheetAnalDataGeomEntity.geom, // polygon
Projections.constructor(
ChangeDetectionDto.PolygonProperties.class,
mapSheetAnalDataGeomEntity.area,
mapSheetAnalDataGeomEntity.compareYyyy,
mapSheetAnalDataGeomEntity.classBeforeProb,
mapSheetAnalDataGeomEntity.classBeforeCd.toUpperCase(),
mapSheetAnalDataGeomEntity.targetYyyy,
mapSheetAnalDataGeomEntity.classAfterProb,
mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase())))
.from(mapSheetAnalDataGeomEntity)
.where(
mapSheetAnalDataGeomEntity.dataUid.in(
JPAExpressions.select(mapSheetAnalDataEntity.id)
.from(mapSheetAnalDataEntity)
.where(mapSheetAnalDataEntity.analUid.eq(analUid))),
mapSheetAnalDataGeomEntity.mapSheetNum.eq(Long.valueOf(mapSheetNum)))
.fetch();
}
@Override
public List<ChangeDetectionDto.PointGeometry> getChangeDetectionPointList(
Long analUid, String mapSheetNum) {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.PointGeometry.class,
mapSheetAnalDataGeomEntity.id,
mapSheetAnalDataGeomEntity.geomCenter, // point
mapSheetAnalDataGeomEntity.classAfterCd.toUpperCase()))
.from(mapSheetAnalDataGeomEntity)
.where(
mapSheetAnalDataGeomEntity.dataUid.in(
JPAExpressions.select(mapSheetAnalDataEntity.id)
.from(mapSheetAnalDataEntity)
.where(mapSheetAnalDataEntity.analUid.eq(analUid))),
mapSheetAnalDataGeomEntity.mapSheetNum.eq(Long.valueOf(mapSheetNum)))
.fetch();
}
@Override
public List<ChangeDetectionDto.MapSheetList> getChangeDetectionMapSheetList(Long analUid) {
return queryFactory
.select(
Projections.constructor(
ChangeDetectionDto.MapSheetList.class,
mapInkx5kEntity.mapidcdNo,
mapInkx5kEntity.mapidNm,
mapInkx5kEntity.mapidNm // alias 앞단 core에서
))
.from(demoLearningAnalysisSceneItemEntity)
.innerJoin(mapInkx5kEntity)
.on(demoLearningAnalysisSceneItemEntity.fid.eq(mapInkx5kEntity.fid.longValue()))
.where(demoLearningAnalysisSceneItemEntity.groupId.eq(analUid))
.orderBy(mapInkx5kEntity.mapidNm.asc(), mapInkx5kEntity.mapidcdNo.asc())
.fetch();
}
private StringExpression makeCogUrl(Integer year) {
return new CaseBuilder()
.when(imageryEntity.year.eq(year))

View File

@@ -43,7 +43,7 @@ public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport
Projections.constructor(
ErrorLogDto.Basic.class,
errorLogEntity.id.as("logId"),
Expressions.constant("한국자산관리공사"), // serviceName
Expressions.stringTemplate("{0}", "한국자산관리공사"), // serviceName
menuEntity.menuNm.as("menuName"),
userEntity.userId.as("loginId"),
userEntity.userNm.as("userName"),
@@ -54,7 +54,8 @@ public class ErrorLogRepositoryImpl extends QuerydslRepositorySupport
errorLogEntity.errorCode.as("errorCode"),
errorLogEntity.errorMessage.as("errorMessage"),
errorLogEntity.stackTrace.as("errorDetail"),
errorLogEntity.createdDate))
Expressions.stringTemplate(
"to_char({0}, 'YYYY-MM-DD')", errorLogEntity.createdDate)))
.from(errorLogEntity)
.leftJoin(auditLogEntity)
.on(errorLogEntity.id.eq(auditLogEntity.errorLogUid))