feat: polishing

This commit is contained in:
2025-12-29 14:47:54 +09:00
parent 5d297ba456
commit 701192ecd2
7 changed files with 227 additions and 44 deletions

View File

@@ -1,8 +1,10 @@
package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.YearSearchReq;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngEntity;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
import com.kamco.cd.kamcoback.postgres.entity.YearEntity;
import com.kamco.cd.kamcoback.postgres.repository.mapsheet.MapSheetMngRepository;
import jakarta.persistence.EntityNotFoundException;
import jakarta.validation.Valid;
@@ -20,6 +22,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
@@ -40,6 +43,18 @@ public class MapSheetMngCoreService {
return mapSheetMngRepository.findMapSheetMngYyyyList();
}
/**
* 영상등록이 가능한 연도리스트
*
* @param req
* @return
*/
@Transactional(readOnly = true)
public Page<YearEntity> getListMapListYYYYWithPaging(YearSearchReq req) {
return mapSheetMngRepository.getYears(req);
}
public MapSheetMngDto.MngDto findMapSheetMng(int mngYyyy) {
return mapSheetMngRepository.findMapSheetMng(mngYyyy);
}
@@ -146,18 +161,18 @@ public class MapSheetMngCoreService {
})
.sum();
entity.get().setTifSizeBytes(tifSize);
entity.get().setTfwSizeBytes(tfwSize);
entity.get().setTotalSizeBytes(tifSize + tfwSize);
MapSheetMngHstEntity mapSheetMngHst = entity.get();
mapSheetMngHst.updateFileInfos(tifSize, tfwSize);
// 엔터티 저장 -> 커스텀 업데이트로 변경
mapSheetMngRepository.updateHstFileSizes(
entity.get().getHstUid(), tifSize, tfwSize, tifSize + tfwSize);
} catch (IOException e) {
// 크기 계산 실패 시 0으로 저장
entity.get().setTifSizeBytes(0L);
entity.get().setTfwSizeBytes(0L);
entity.get().setTotalSizeBytes(0L);
MapSheetMngHstEntity mapSheetMng = entity.get();
mapSheetMng.updateFileInfos(0L, 0L);
mapSheetMngRepository.updateHstFileSizes(entity.get().getHstUid(), 0L, 0L, 0L);
}
@@ -254,13 +269,18 @@ public class MapSheetMngCoreService {
List<MapSheetMngDto.MngFilesDto> filesDto =
mapSheetMngRepository.findHstUidToMapSheetFileList(hstUid);
for (MapSheetMngDto.MngFilesDto dto : filesDto) {
if (dto.getFileExt().equals("tif")) reqDto.setSyncCheckTifFileName(dto.getFileName());
else if (dto.getFileExt().equals("tfw")) reqDto.setSyncCheckTfwFileName(dto.getFileName());
if (dto.getFileExt().equals("tif")) {
reqDto.setSyncCheckTifFileName(dto.getFileName());
} else if (dto.getFileExt().equals("tfw")) {
reqDto.setSyncCheckTfwFileName(dto.getFileName());
}
reqDto.setFilePath(dto.getFilePath());
}
String fileState = "DONE";
if (filesDto.size() > 2) fileState = "DONE";
if (filesDto.size() > 2) {
fileState = "DONE";
}
reqDto.setSyncCheckState(fileState);

View File

@@ -1,37 +1,92 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
import jakarta.persistence.*;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Size;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
/**
* This class represents the entity for managing the history of map sheets. It is mapped to the
* database table "tb_map_sheet_mng_hst" and contains various properties related to the 1:5k map
* sheet information, as well as metadata for file synchronization and management.
*
* <p>This entity: - Includes a primary key (hstUid) for unique identification. - Maintains
* information associated with map sheets such as code, name, scale ratio, and paths. - Tracks
* states, timestamps, and data synchronization details. - Maintains relationships with the
* `MapInkx5kEntity` entity through a many-to-one association. - Provides functionality to update
* file information and sizes (`tifSizeBytes`, `tfwSizeBytes`, and `totalSizeBytes`).
*
* <p>It extends the `CommonDateEntity` class to include common date management fields, such as
* creation and modification timestamps.
*
* <p>The `@Getter` annotation generates getter methods for all fields, while the access to setters
* is restricted to enforce controlled modifications. The entity uses `@NoArgsConstructor` with
* `AccessLevel.PROTECTED` to restrict direct instantiation. The `updateFileInfos` method allows
* dynamic updates of specific file information.
*
* <p>Fields include: - hstUid: Unique identifier for the history record. - mngYyyy: Year associated
* with the management record. - mapInkx5kByCode: Reference to the related `MapInkx5kEntity` object.
* - mapSheetNum: Map sheet number identifying specific map. - mapSheetName: Name of the map sheet.
* - mapSheetCodeSrc: Source code of the map sheet. - scaleRatio: Scale ratio of the map. -
* dataState: State/status of the map sheet data. - dataStateDttm: Timestamp of the data state. -
* useInference: Indicator or metadata for inference usage. - useInferenceDttm: Timestamp for
* inference-related use. - mapSheetPath: Path or location of the map sheet file. - refMapSheetNum:
* Reference to a related map sheet number. - createdUid: User ID of the record creator. -
* updatedUid: User ID of the last updater. - syncState and related fields: Fields to manage
* synchronization states and processes. - tifSizeBytes, tfwSizeBytes, totalSizeBytes: Fields to
* track file size details. - sync file name fields: Stores names of files relevant for
* synchronization and verification.
*
* <p>This entity is essential for tracking and managing map sheet revisions, status, and usage in a
* system leveraging 1:5k map data.
*/
@Getter
@Setter
// entity의 접근제어를 위해 @setter를 사용 x
// @Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
// 영상관리이력
@Table(name = "tb_map_sheet_mng_hst")
public class MapSheetMngHstEntity extends CommonDateEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "hst_uid")
private Long hstUid;
private Long hstUid; // id
@Column(name = "mng_yyyy")
private Integer mngYyyy;
private Integer mngYyyy; // 년도
@Column(name = "map_sheet_code")
private Integer mapSheetCode;
// JPA 연관관계: MapInkx5k 참조 (PK 기반) 소속도엽번호 1:5k
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "map_sheet_code", referencedColumnName = "fid")
private MapInkx5kEntity mapInkx5kByCode;
// TODO 1:5k 관련 정보 추후 제거 필요
@Column(name = "map_sheet_num")
private String mapSheetNum;
private String mapSheetNum; // 도엽번호
@Column(name = "map_sheet_name")
private String mapSheetName;
// TODO END
// 도엽파일이 저장된 경로
@Column(name = "map_sheet_code_src")
private Integer mapSheetCodeSrc;
// 도엽비율?
@Column(name = "scale_ratio")
private Integer scaleRatio;
@@ -103,4 +158,13 @@ public class MapSheetMngHstEntity extends CommonDateEntity {
@Size(max = 100)
@Column(name = "sync_check_tfw_file_name", length = 100)
private String syncCheckTfwFileName;
// 파일정보 업데이트
public void updateFileInfos(Long tifSizeBytes, Long tfwSizeBytes) {
tifSizeBytes = tifSizeBytes == null ? 0L : tifSizeBytes;
tfwSizeBytes = tfwSizeBytes == null ? 0L : tfwSizeBytes;
this.tifSizeBytes = tifSizeBytes;
this.tfwSizeBytes = tfwSizeBytes;
this.totalSizeBytes = tifSizeBytes + tfwSizeBytes;
}
}

View File

@@ -1,7 +1,9 @@
package com.kamco.cd.kamcoback.postgres.repository.mapsheet;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.YearSearchReq;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
import com.kamco.cd.kamcoback.postgres.entity.YearEntity;
import jakarta.validation.Valid;
import java.util.List;
import java.util.Optional;
@@ -55,4 +57,6 @@ public interface MapSheetMngRepositoryCustom {
MapSheetMngDto.MngFilesDto findIdToMapSheetFile(Long fileUid);
void updateHstFileSizes(Long hstUid, long tifSizeBytes, long tfwSizeBytes, long totalSizeBytes);
Page<YearEntity> getYears(YearSearchReq yearSearchReq);
}

View File

@@ -8,7 +8,10 @@ import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetMngHstEntity.mapSh
import static com.kamco.cd.kamcoback.postgres.entity.QYearEntity.yearEntity;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto.YearSearchReq;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
import com.kamco.cd.kamcoback.postgres.entity.QYearEntity;
import com.kamco.cd.kamcoback.postgres.entity.YearEntity;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
@@ -295,23 +298,7 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
mapSheetMngHstEntity.syncState.ne("DONE").and(mapSheetMngHstEntity.syncState.ne("NOTYET")));
if (searchReq.getSyncState() != null && !searchReq.getSyncState().isEmpty()) {
/*
if (searchReq.getSyncState().equals("NOTPAIR")) {
whereBuilder.and(
mapSheetMngHstEntity
.syncState
.eq("NOTPAIR")
.or(mapSheetMngHstEntity.syncState.eq("NOFILE")));
} else if (searchReq.getSyncState().equals("FAULT")) {
whereBuilder.and(
mapSheetMngHstEntity
.syncState
.eq("SIZEERROR")
.or(mapSheetMngHstEntity.syncState.eq("TYPEERROR")));
} else {
whereBuilder.and(mapSheetMngHstEntity.syncState.eq(searchReq.getSyncState()));
}
*/
whereBuilder.and(mapSheetMngHstEntity.syncState.eq(searchReq.getSyncState()));
}
@@ -379,8 +366,7 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
queryFactory
.select(mapSheetMngHstEntity.hstUid.count())
.from(mapSheetMngHstEntity)
.innerJoin(mapInkx5kEntity)
.on(mapSheetMngHstEntity.mapSheetCode.eq(mapInkx5kEntity.fid))
.innerJoin(mapSheetMngHstEntity.mapInkx5kByCode, mapInkx5kEntity)
.leftJoin(mapInkx50kEntity)
.on(mapInkx5kEntity.fidK50.eq(mapInkx50kEntity.fid.longValue()))
.where(whereBuilder)
@@ -737,6 +723,35 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
query.executeUpdate();
}
@Override
public Page<YearEntity> getYears(YearSearchReq req) {
Pageable pageable = req.toPageable();
// LISTS
List<YearEntity> content =
queryFactory
.selectFrom(yearEntity)
.where(eqYearStatus(yearEntity, req.getStatus()))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.orderBy(yearEntity.yyyy.asc())
.fetch();
// count 쿼리
Long total =
queryFactory
.select(yearEntity.yyyy.count())
.from(yearEntity)
.where(eqYearStatus(yearEntity, req.getStatus()))
.fetchOne();
return new PageImpl<>(content, pageable, total);
}
private BooleanExpression eqYearStatus(QYearEntity years, String status) {
if (status == null) {
return null;
}
return years.status.eq(status);
}
private NumberExpression<Integer> rowNum() {
return Expressions.numberTemplate(
Integer.class, "row_number() over(order by {0} desc)", mapSheetMngHstEntity.createdDate);