From b76f2331f1cf15478d7c3ff6ce7c03a180e7394f Mon Sep 17 00:00:00 2001 From: Moon Date: Fri, 12 Dec 2025 13:58:35 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8F=99=EC=98=81=EC=83=81=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapsheet/MapSheetMngApiController.java | 31 +-- .../mapsheet/dto/MapSheetMngDto.java | 90 ++++++--- .../mapsheet/service/MapSheetMngService.java | 7 +- .../postgres/core/MapSheetMngCoreService.java | 8 +- .../entity/MapSheetMngFileEntity.java | 54 +++++ .../mapsheet/MapSheetMngRepositoryCustom.java | 11 +- .../mapsheet/MapSheetMngRepositoryImpl.java | 186 +++++++++++------- 7 files changed, 261 insertions(+), 126 deletions(-) create mode 100644 src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetMngFileEntity.java diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java index 03f478b7..31380a60 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java @@ -26,17 +26,7 @@ public class MapSheetMngApiController { private final CommonCodeService commonCodeService; private final MapSheetMngService mapSheetMngService; - /** - * 오류데이터 목록 조회 - * - * @param searchReq - * @return - */ - @PostMapping("/error-list") - public ApiResponseDto> findMapSheetErrorList( - @RequestBody @Valid MapSheetMngDto.searchReq searchReq) { - return ApiResponseDto.ok(mapSheetMngService.findMapSheetErrorList(searchReq)); - } + @Operation(summary = "영상데이터관리목록 조회", description = "영상데이터관리목록 조회") @ApiResponses( @@ -53,7 +43,7 @@ public class MapSheetMngApiController { }) @PostMapping("/mng-list") public ApiResponseDto> findMapSheetMngList( - @RequestBody @Valid MapSheetMngDto.searchReq searchReq) { + @RequestBody MapSheetMngDto.MngSearchReq searchReq) { return ApiResponseDto.ok(mapSheetMngService.findMapSheetMngList(searchReq)); } @@ -77,6 +67,21 @@ public class MapSheetMngApiController { return ApiResponseDto.ok(mapSheetMngService.mngDataSave(AddReq)); } + + + /** + * 오류데이터 목록 조회 + * + * @param searchReq + * @return + */ + @PostMapping("/error-list") + public ApiResponseDto> findMapSheetErrorList( + @RequestBody @Valid MapSheetMngDto.ErrorSearchReq searchReq) { + return ApiResponseDto.ok(mapSheetMngService.findMapSheetErrorList(searchReq)); + } + + /** * @param hstUidList * @return @@ -86,7 +91,7 @@ public class MapSheetMngApiController { value = { @ApiResponse( responseCode = "201", - description = "공통코드 저장 성공", + description = "업로드 처리 성공", content = @Content( mediaType = "application/json", diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/MapSheetMngDto.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/MapSheetMngDto.java index aaf6594a..6da982ae 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/MapSheetMngDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/MapSheetMngDto.java @@ -14,12 +14,12 @@ import org.springframework.data.domain.Sort; public class MapSheetMngDto { - @Schema(name = "searchReq", description = "영상관리 오류데이터 검색 요청") + @Schema(name = "MngSearchReq", description = "영상관리 검색 요청") @Getter @Setter @NoArgsConstructor @AllArgsConstructor - public static class searchReq { + public static class MngSearchReq { // 페이징 파라미터 @Schema(description = "페이지 번호 (0부터 시작) ", example = "0") @@ -28,42 +28,14 @@ public class MapSheetMngDto { @Schema(description = "페이지 크기", example = "20") private int size = 20; - @Schema(description = "정렬", example = "id desc") - private String sort; - - @Schema(description = "검색어", example = "부산3959") - private String searchValue; - @Schema(description = "년도", example = "2025") private Integer mngYyyy; public Pageable toPageable() { - if (sort != null && !sort.isEmpty()) { - String[] sortParams = sort.split(","); - String property = sortParams[0]; - Sort.Direction direction = - sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC; - return PageRequest.of(page, size, Sort.by(direction, property)); - } return PageRequest.of(page, size); } } - @Schema(name = "ErrorDataDto", description = "영상관리 오류데이터 검색 리턴") - @Getter - @Setter - @NoArgsConstructor - @AllArgsConstructor - public static class ErrorDataDto { - private Long hstUid; - private Integer rowNum; - private String map50kName; - private String map5kName; - private Integer mapCodeSrc; - private String createdDttm; - private DataState dataState; - } - @Schema(name = "MngAddReq", description = "영상관리 생성 요청") @Getter @Setter @@ -98,6 +70,64 @@ public class MapSheetMngDto { @JsonFormatDttm private ZonedDateTime rgstEndDttm; } + + @Schema(name = "ErrorSearchReq", description = "영상관리 오류데이터 검색 요청") + @Getter + @Setter + @NoArgsConstructor + @AllArgsConstructor + public static class ErrorSearchReq { + + // 페이징 파라미터 + @Schema(description = "페이지 번호 (0부터 시작) ", example = "0") + private int page = 0; + + @Schema(description = "페이지 크기", example = "20") + private int size = 20; + + @Schema(description = "정렬", example = "id desc") + private String sort; + + @Schema(description = "검색어", example = "부산3959") + private String searchValue; + + @Schema(description = "년도", example = "2025") + private Integer mngYyyy; + + public Pageable toPageable() { + if (sort != null && !sort.isEmpty()) { + String[] sortParams = sort.split(","); + String property = sortParams[0]; + Sort.Direction direction = + sortParams.length > 1 ? Sort.Direction.fromString(sortParams[1]) : Sort.Direction.ASC; + return PageRequest.of(page, size, Sort.by(direction, property)); + } + return PageRequest.of(page, size); + } + } + + + + @Schema(name = "ErrorDataDto", description = "영상관리 오류데이터 검색 리턴") + @Getter + @Setter + @NoArgsConstructor + @AllArgsConstructor + public static class ErrorDataDto { + private Long hstUid; + private Integer rowNum; + private String map50kName; + private String map5kName; + private Integer mapCodeSrc; + private String createdDttm; + private DataState dataState; + } + + + + + + @Schema(name = "DmlReturn", description = "영상관리 DML 수행 후 리턴") @Getter @Setter diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java index b898b607..7ba41aa2 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java @@ -213,16 +213,17 @@ public class MapSheetMngService { } public Page findMapSheetErrorList( - MapSheetMngDto.@Valid searchReq searchReq) { + MapSheetMngDto.@Valid ErrorSearchReq searchReq) { return mapSheetMngCoreService.findMapSheetErrorList(searchReq); } public Page findMapSheetMngList( - MapSheetMngDto.@Valid searchReq searchReq) { + MapSheetMngDto.MngSearchReq searchReq) { return mapSheetMngCoreService.findMapSheetMngList(searchReq); } - public MapSheetMngDto.DmlReturn mngDataSave(@Valid MapSheetMngDto.AddReq AddReq) { + @Transactional + public MapSheetMngDto.DmlReturn mngDataSave(MapSheetMngDto.AddReq AddReq) { return mapSheetMngCoreService.mngDataSave(AddReq); } diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/core/MapSheetMngCoreService.java b/src/main/java/com/kamco/cd/kamcoback/postgres/core/MapSheetMngCoreService.java index c3d6c494..be5c4f63 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/core/MapSheetMngCoreService.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/core/MapSheetMngCoreService.java @@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -33,12 +34,12 @@ public class MapSheetMngCoreService { private String activeEnv; public Page findMapSheetErrorList( - MapSheetMngDto.@Valid searchReq searchReq) { + MapSheetMngDto.@Valid ErrorSearchReq searchReq) { return mapSheetMngRepository.findMapSheetErrorList(searchReq); } public Page findMapSheetMngList( - MapSheetMngDto.@Valid searchReq searchReq) { + MapSheetMngDto.@Valid MngSearchReq searchReq) { return mapSheetMngRepository.findMapSheetMngList(searchReq); } @@ -132,7 +133,10 @@ public class MapSheetMngCoreService { entity.setMngYyyy(addReq.getMngYyyy()); entity.setMngPath(addReq.getMngPath()); + //mapSheetMngRepository.deleteMngAll(addReq.getMngYyyy()); + MapSheetMngEntity saved = mapSheetMngRepository.save(entity); + int hstCnt = mapSheetMngRepository.insertMapSheetOrgDataToMapSheetMngHst(saved.getMngYyyy()); return new MapSheetMngDto.DmlReturn("success", saved.getMngYyyy().toString()); } diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetMngFileEntity.java b/src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetMngFileEntity.java new file mode 100644 index 00000000..b822662b --- /dev/null +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/entity/MapSheetMngFileEntity.java @@ -0,0 +1,54 @@ +package com.kamco.cd.kamcoback.postgres.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Entity +@Table(name = "tb_map_sheet_mng_files") +public class MapSheetMngFileEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "file_uid", nullable = false) + private Long fileUid; + + @NotNull + @Column(name = "mng_yyyy", nullable = false) + private Integer mngYyyy; + + @NotNull + @Column(name = "map_sheet_num", nullable = false) + private Integer mapSheetNum; + + @Column(name = "ref_map_sheet_num") + private Integer refMapSheetNum; + + @Size(max = 255) + @Column(name = "file_path") + private String filePath; + + @Size(max = 100) + @Column(name = "file_name", length = 100) + private String fileName; + + @Size(max = 20) + @Column(name = "file_ext", length = 20) + private String fileExt; + + @Column(name = "mng_uid") + private Long mngUid; + + @Column(name = "hst_uid") + private Long hstUid; + +} diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryCustom.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryCustom.java index 817cca55..72a72f31 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryCustom.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryCustom.java @@ -8,10 +8,15 @@ import org.springframework.data.domain.Page; public interface MapSheetMngRepositoryCustom { - Page findMapSheetErrorList( - MapSheetMngDto.@Valid searchReq searchReq); - Page findMapSheetMngList(MapSheetMngDto.@Valid searchReq searchReq); + Page findMapSheetMngList(MapSheetMngDto.MngSearchReq searchReq); Optional findMapSheetMngHstInfo(Long hstUid); + + int insertMapSheetOrgDataToMapSheetMngHst(int mngYyyy); + + void deleteMngAll(int mngYyyy); + + Page findMapSheetErrorList( + MapSheetMngDto.@Valid ErrorSearchReq searchReq); } diff --git a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryImpl.java b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryImpl.java index 2ca6853f..65b6d8b6 100644 --- a/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryImpl.java +++ b/src/main/java/com/kamco/cd/kamcoback/postgres/repository/mapsheet/MapSheetMngRepositoryImpl.java @@ -15,10 +15,13 @@ import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.types.dsl.NumberExpression; import com.querydsl.core.types.dsl.StringExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; import jakarta.validation.Valid; import java.util.List; import java.util.Objects; import java.util.Optional; +import org.hibernate.query.Query; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; @@ -31,67 +34,18 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport private final JPAQueryFactory queryFactory; private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)"); + @PersistenceContext + private EntityManager em; + public MapSheetMngRepositoryImpl(JPAQueryFactory queryFactory) { super(MapSheetMngHstEntity.class); this.queryFactory = queryFactory; } - @Override - public Page findMapSheetErrorList( - MapSheetMngDto.@Valid searchReq searchReq) { - - Pageable pageable = PageRequest.of(searchReq.getPage(), searchReq.getSize()); - List foundContent = - queryFactory - .select( - Projections.constructor( - MapSheetMngDto.ErrorDataDto.class, - mapSheetMngHstEntity.hstUid, - rowNum(), - Expressions.stringTemplate( - "concat({0}, {1})", - mapSheetMngHstEntity.mapSheetName, mapInkx50kEntity.mapidcdNo), - Expressions.stringTemplate( - "concat({0}, substring({1}, {2}, {3}))", - mapSheetMngHstEntity.mapSheetName, mapSheetMngHstEntity.mapSheetNum, 6, 8), - mapSheetMngHstEntity.mapSheetCodeSrc, - Expressions.stringTemplate( - "to_char({0}, 'YYYY-MM-DD')", mapSheetMngHstEntity.createdDate), - mapSheetMngHstEntity.dataState)) - .from(mapSheetMngHstEntity) - .innerJoin(mapInkx5kEntity) - .on(mapSheetMngHstEntity.mapSheetCode.eq(mapInkx5kEntity.fid)) - .leftJoin(mapInkx50kEntity) - .on(mapInkx5kEntity.fidK50.eq(mapInkx50kEntity.fid.longValue())) - .where( - mapSheetMngHstEntity.mngYyyy.eq(searchReq.getMngYyyy()), - // mapSheetMngHstEntity.dataState.eq(MapSheetMngDto.DataState.FAIL), // 오류만 검색 - mapSheetErrorSearchValue(searchReq)) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .orderBy(mapSheetMngHstEntity.createdDate.desc()) - .fetch(); - - Long countQuery = - queryFactory - .select(mapSheetMngHstEntity.hstUid.count()) - .from(mapSheetMngHstEntity) - .innerJoin(mapInkx5kEntity) - .on(mapSheetMngHstEntity.mapSheetCode.eq(mapInkx5kEntity.fid)) - .leftJoin(mapInkx50kEntity) - .on(mapInkx5kEntity.fidK50.eq(mapInkx50kEntity.fid.longValue())) - .where( - mapSheetMngHstEntity.mngYyyy.eq(searchReq.getMngYyyy()), - // mapSheetMngHstEntity.dataState.eq(MapSheetMngDto.DataState.FAIL), // 오류만 검색 - mapSheetErrorSearchValue(searchReq)) - .fetchOne(); - - return new PageImpl<>(foundContent, pageable, countQuery); - } @Override public Page findMapSheetMngList( - MapSheetMngDto.@Valid searchReq searchReq) { + MapSheetMngDto.MngSearchReq searchReq) { Pageable pageable = searchReq.toPageable(); BooleanBuilder whereBuilder = new BooleanBuilder(); @@ -100,27 +54,6 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport whereBuilder.and(mapSheetMngEntity.mngYyyy.eq(searchReq.getMngYyyy())); } - /* - QMapSheetMngEntity m = mapSheetMngEntity; - QMapSheetMngHstEntity h = mapSheetMngHstEntity; - - List summaryContent = - queryFactory - .select( - Projections.constructor( - MapSheetSummaryDto.class, - mapSheetMngHstEntity.mngYyyy, - mapSheetMngHstEntity.mngYyyy.count().as("syncTotCnt"), - new CaseBuilder() - .when(mapSheetMngHstEntity.syncState.eq("DONE")).then(1L).otherwise(0L) - .sum().as("syncStateDoneCnt") - )) - .from(mapSheetMngHstEntity) - .groupBy(mapSheetMngHstEntity.mngYyyy) // mng_yyyy 별로 그룹핑 - .fetch(); - - */ - List foundContent = queryFactory .select( @@ -183,6 +116,107 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport return new PageImpl<>(foundContent, pageable, countQuery); } + + + + + + @Override + public Page findMapSheetErrorList( + MapSheetMngDto.@Valid ErrorSearchReq searchReq) { + + Pageable pageable = PageRequest.of(searchReq.getPage(), searchReq.getSize()); + List foundContent = + queryFactory + .select( + Projections.constructor( + MapSheetMngDto.ErrorDataDto.class, + mapSheetMngHstEntity.hstUid, + rowNum(), + Expressions.stringTemplate( + "concat({0}, {1})", + mapSheetMngHstEntity.mapSheetName, mapInkx50kEntity.mapidcdNo), + Expressions.stringTemplate( + "concat({0}, substring({1}, {2}, {3}))", + mapSheetMngHstEntity.mapSheetName, mapSheetMngHstEntity.mapSheetNum, 6, 8), + mapSheetMngHstEntity.mapSheetCodeSrc, + Expressions.stringTemplate( + "to_char({0}, 'YYYY-MM-DD')", mapSheetMngHstEntity.createdDate), + mapSheetMngHstEntity.dataState)) + .from(mapSheetMngHstEntity) + .innerJoin(mapInkx5kEntity) + .on(mapSheetMngHstEntity.mapSheetCode.eq(mapInkx5kEntity.fid)) + .leftJoin(mapInkx50kEntity) + .on(mapInkx5kEntity.fidK50.eq(mapInkx50kEntity.fid.longValue())) + .where( + mapSheetMngHstEntity.mngYyyy.eq(searchReq.getMngYyyy()), + // mapSheetMngHstEntity.dataState.eq(MapSheetMngDto.DataState.FAIL), // 오류만 검색 + mapSheetErrorSearchValue(searchReq)) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .orderBy(mapSheetMngHstEntity.createdDate.desc()) + .fetch(); + + Long countQuery = + queryFactory + .select(mapSheetMngHstEntity.hstUid.count()) + .from(mapSheetMngHstEntity) + .innerJoin(mapInkx5kEntity) + .on(mapSheetMngHstEntity.mapSheetCode.eq(mapInkx5kEntity.fid)) + .leftJoin(mapInkx50kEntity) + .on(mapInkx5kEntity.fidK50.eq(mapInkx50kEntity.fid.longValue())) + .where( + mapSheetMngHstEntity.mngYyyy.eq(searchReq.getMngYyyy()), + // mapSheetMngHstEntity.dataState.eq(MapSheetMngDto.DataState.FAIL), // 오류만 검색 + mapSheetErrorSearchValue(searchReq)) + .fetchOne(); + + return new PageImpl<>(foundContent, pageable, countQuery); + } + + @Override + public void deleteMngAll(int mngYyyy){ + + } + + @Override + public int insertMapSheetOrgDataToMapSheetMngHst(int mngYyyy) { + + String sql = """ + INSERT INTO tb_map_sheet_mng_hst + ( + mng_yyyy + ,map_sheet_code + ,map_sheet_num + ,map_sheet_name + ,map_sheet_code_src + ,scale_ratio + ,ref_map_sheet_num + ,use_inference + ) + select + :mngYyyy as mng_yyyy + ,fid as map_sheet_code + ,mapidcd_no::INTEGER as map_sheet_num + ,mapid_nm as map_sheet_name + ,fid as map_sheet_code_src + ,5000 as scale_ratio + ,((mapidcd_no::INTEGER)/1000) as ref_map_sheet_num + ,use_inference + from + tb_map_inkx_5k + """; + + // Native Query 생성 및 실행 + Query query = (Query) em.createNativeQuery(sql); + query.setParameter("mngYyyy", mngYyyy); + + int exeCnt = query.executeUpdate(); // 실행 (영향받은 행의 개수 반환) + + return exeCnt; + + } + @Override public Optional findMapSheetMngHstInfo(Long hstUid) { return Optional.ofNullable( @@ -192,12 +226,14 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport .fetchOne()); } + + private NumberExpression rowNum() { return Expressions.numberTemplate( Integer.class, "row_number() over(order by {0} desc)", mapSheetMngHstEntity.createdDate); } - private BooleanExpression mapSheetErrorSearchValue(MapSheetMngDto.searchReq searchReq) { + private BooleanExpression mapSheetErrorSearchValue(MapSheetMngDto.ErrorSearchReq searchReq) { if (Objects.isNull(searchReq.getSearchValue())) { return null; }