추론실행 수정

This commit is contained in:
2026-01-29 10:27:08 +09:00
parent 0f8261b20b
commit f793042927
20 changed files with 1378 additions and 101 deletions

View File

@@ -3,11 +3,23 @@ package com.kamco.cd.kamcoback.postgres.core;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kamco.cd.kamcoback.common.enums.LayerType;
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
import com.kamco.cd.kamcoback.common.utils.UserUtil;
import com.kamco.cd.kamcoback.layer.dto.LayerDto;
import com.kamco.cd.kamcoback.layer.dto.LayerDto.OrderReq;
import com.kamco.cd.kamcoback.layer.dto.WmsDto.WmsAddDto;
import com.kamco.cd.kamcoback.layer.dto.WmtsDto.WmtsAddDto;
import com.kamco.cd.kamcoback.postgres.entity.MapLayerEntity;
import com.kamco.cd.kamcoback.postgres.repository.layer.MapLayerRepository;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
@Service
@@ -17,33 +29,266 @@ public class MapLayerCoreService {
private final UserUtil userUtil;
private final ObjectMapper objectMapper;
/**
* 지도 레이어 관리 목록
*
* @return
*/
public List<LayerDto.Basic> getLayers(LayerDto.SearchReq searchReq) {
return mapLayerRepository.findAllLayer(searchReq);
}
/**
* 지도 레이어 상세 목록
*
* @param uuid
* @return
*/
public LayerDto.Detail getLayers(UUID uuid) {
MapLayerEntity entity =
mapLayerRepository
.findDetailByUuid(uuid)
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
return entity.toDto();
}
/**
* 삭제
*
* @param uuid
*/
public void delete(UUID uuid) {
MapLayerEntity entity =
mapLayerRepository
.findDetailByUuid(uuid)
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
if (LayerType.TILE.getId().equals(entity.getLayerType())) {
throw new CustomApiException("UNPROCESSABLE_ENTITY", HttpStatus.CONFLICT);
}
entity.setIsDeleted(true);
entity.setUpdatedUid(userUtil.getId());
entity.setUpdatedDttm(ZonedDateTime.now());
}
/**
* 수정
*
* @param uuid
*/
public void update(UUID uuid, LayerDto.Detail dto) {
MapLayerEntity entity =
mapLayerRepository
.findDetailByUuid(uuid)
.orElseThrow(() -> new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND));
if (dto.getDescription() != null) {
entity.setDescription(dto.getDescription());
}
if (dto.getUrl() != null) {
entity.setUrl(dto.getUrl());
}
if (dto.getTag() != null) {
entity.setTag(dto.getTag());
}
if (dto.getMinLon() != null) {
entity.setMinLon(dto.getMinLon());
}
if (dto.getMaxLon() != null) {
entity.setMaxLon(dto.getMaxLon());
}
if (dto.getMinLat() != null) {
entity.setMinLat(dto.getMinLat());
}
if (dto.getMaxLat() != null) {
entity.setMaxLat(dto.getMaxLat());
}
if (dto.getMin() != null) {
entity.setMinZoom(dto.getMin());
}
if (dto.getMax() != null) {
entity.setMaxZoom(dto.getMax());
}
if (dto.getIsChangeMap() != null) {
entity.setIsChangeMap(dto.getIsChangeMap());
}
if (dto.getIsLabelingMap() != null) {
entity.setIsLabelingMap(dto.getIsLabelingMap());
}
entity.setUpdatedUid(userUtil.getId());
entity.setUpdatedDttm(ZonedDateTime.now());
}
/**
* 순서 수정
*
* @param dtoList
*/
public void orderUpdate(List<OrderReq> dtoList) {
if (dtoList == null || dtoList.isEmpty()) {
return;
}
List<UUID> uuids =
dtoList.stream().map(OrderReq::getUuid).filter(Objects::nonNull).distinct().toList();
if (uuids.isEmpty()) {
throw new CustomApiException("BAD_REQUEST", HttpStatus.BAD_REQUEST);
}
List<MapLayerEntity> entities = mapLayerRepository.findAllByUuidIn(uuids);
Map<UUID, MapLayerEntity> entityMap =
entities.stream().collect(Collectors.toMap(MapLayerEntity::getUuid, Function.identity()));
List<UUID> notFound = uuids.stream().filter(u -> !entityMap.containsKey(u)).toList();
if (!notFound.isEmpty()) {
throw new CustomApiException("NOT_FOUND_DATA", HttpStatus.NOT_FOUND);
}
Long uid = userUtil.getId();
ZonedDateTime now = ZonedDateTime.now();
for (OrderReq dto : dtoList) {
if (dto.getOrder() == null) {
throw new CustomApiException("INVALID_REQUEST", HttpStatus.BAD_REQUEST);
}
MapLayerEntity entity = entityMap.get(dto.getUuid());
entity.setOrder(dto.getOrder());
entity.setUpdatedUid(uid);
entity.setUpdatedDttm(now);
}
}
/**
* Tile 저장
*
* @param dto
*/
public UUID saveTile(LayerDto.AddReq dto) {
LayerDto.SearchReq searchReq = new LayerDto.SearchReq();
searchReq.setLayerType(LayerType.TILE.getId());
List<LayerDto.Basic> entityList = mapLayerRepository.findAllLayer(searchReq);
if (!entityList.isEmpty()) {
throw new CustomApiException("DUPLICATE_DATA", HttpStatus.CONFLICT);
}
MapLayerEntity mapLayerEntity = new MapLayerEntity();
mapLayerEntity.setDescription(dto.getDescription());
mapLayerEntity.setUrl(dto.getUrl());
mapLayerEntity.setTag(dto.getTag());
mapLayerEntity.setMinLon(dto.getMinLon());
mapLayerEntity.setMinLat(dto.getMinLat());
mapLayerEntity.setMaxLon(dto.getMaxLon());
mapLayerEntity.setMaxLat(dto.getMaxLat());
mapLayerEntity.setMinZoom(dto.getMin());
mapLayerEntity.setMaxZoom(dto.getMax());
mapLayerEntity.setCreatedUid(userUtil.getId());
mapLayerEntity.setIsChangeMap(true);
mapLayerEntity.setIsLabelingMap(false);
mapLayerEntity.setOrder(1L);
mapLayerEntity.setLayerType(LayerType.TILE.getId());
mapLayerEntity.setUpdatedDttm(ZonedDateTime.now());
return mapLayerRepository.save(mapLayerEntity).getUuid();
}
/**
* GeoJson 저장
*
* @param addDto
* @return
*/
public UUID saveGeoJson(LayerDto.AddReq addDto) {
Long order = mapLayerRepository.findSortOrderDesc();
MapLayerEntity mapLayerEntity = new MapLayerEntity();
mapLayerEntity.setDescription(addDto.getDescription());
mapLayerEntity.setUrl(addDto.getUrl());
mapLayerEntity.setTag(addDto.getTag());
mapLayerEntity.setCreatedUid(userUtil.getId());
mapLayerEntity.setIsChangeMap(true);
mapLayerEntity.setIsLabelingMap(true);
mapLayerEntity.setLayerType(LayerType.GEOJSON.getId());
mapLayerEntity.setUpdatedDttm(ZonedDateTime.now());
mapLayerEntity.setOrder(order + 1);
return mapLayerRepository.save(mapLayerEntity).getUuid();
}
/**
* wmts 저장
*
* @param addDto
*/
public void save(WmtsAddDto addDto) {
Long order = 20L;
MapLayerEntity entity = mapLayerRepository.findSortOrderDesc().orElse(null);
if (entity != null) {
order = entity.getOrder() == null ? order : entity.getOrder() + 10;
}
public UUID saveWmts(WmtsAddDto addDto) {
Long order = mapLayerRepository.findSortOrderDesc();
String rawJson = "";
try {
String rawJson = objectMapper.writeValueAsString(addDto.getWmtsLayerInfo()); // data 없는 형태로 저장
MapLayerEntity mapLayerEntity = new MapLayerEntity();
mapLayerEntity.setTitle(addDto.getTitle());
mapLayerEntity.setDescription(addDto.getDescription());
mapLayerEntity.setCreatedUid(userUtil.getId());
mapLayerEntity.setRawJson(rawJson);
mapLayerEntity.setIsChangeMap(true);
mapLayerEntity.setIsLabelingMap(true);
mapLayerEntity.setOrder(order);
mapLayerEntity.setLayerType(LayerType.WMTS.getId());
mapLayerRepository.save(mapLayerEntity);
rawJson = objectMapper.writeValueAsString(addDto.getWmtsLayerInfo()); // data 없는 형태로 저장
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
MapLayerEntity mapLayerEntity = new MapLayerEntity();
mapLayerEntity.setTitle(addDto.getTitle());
mapLayerEntity.setDescription(addDto.getDescription());
mapLayerEntity.setCreatedUid(userUtil.getId());
mapLayerEntity.setRawJson(rawJson);
mapLayerEntity.setIsChangeMap(true);
mapLayerEntity.setIsLabelingMap(true);
mapLayerEntity.setOrder(order + 1);
mapLayerEntity.setLayerType(LayerType.WMTS.getId());
mapLayerEntity.setUpdatedDttm(ZonedDateTime.now());
mapLayerEntity.setTag(addDto.getTag());
return mapLayerRepository.save(mapLayerEntity).getUuid();
}
/**
* wms 저장
*
* @param addDto
* @return
*/
public UUID saveWms(WmsAddDto addDto) {
Long order = mapLayerRepository.findSortOrderDesc();
String rawJson = "";
try {
rawJson = objectMapper.writeValueAsString(addDto.getWmsLayerInfo()); // data 없는 형태로 저장
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
MapLayerEntity mapLayerEntity = new MapLayerEntity();
mapLayerEntity.setTitle(addDto.getTitle());
mapLayerEntity.setDescription(addDto.getDescription());
mapLayerEntity.setCreatedUid(userUtil.getId());
mapLayerEntity.setRawJson(rawJson);
mapLayerEntity.setIsChangeMap(true);
mapLayerEntity.setIsLabelingMap(true);
mapLayerEntity.setOrder(order + 1);
mapLayerEntity.setLayerType(LayerType.WMS.getId());
mapLayerEntity.setUpdatedDttm(ZonedDateTime.now());
mapLayerEntity.setTag(addDto.getTag());
return mapLayerRepository.save(mapLayerEntity).getUuid();
}
}

View File

@@ -1,5 +1,6 @@
package com.kamco.cd.kamcoback.postgres.entity;
import com.kamco.cd.kamcoback.layer.dto.LayerDto;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -73,10 +74,10 @@ public class MapLayerEntity {
@NotNull
@ColumnDefault("now()")
@Column(name = "created_dttm", nullable = false)
private ZonedDateTime createdAt = ZonedDateTime.now();
private ZonedDateTime createdDttm = ZonedDateTime.now();
@Column(name = "updated_dttm")
private ZonedDateTime updatedAt;
private ZonedDateTime updatedDttm;
@Column(name = "uuid")
private UUID uuid = UUID.randomUUID();
@@ -95,4 +96,30 @@ public class MapLayerEntity {
@Column(name = "sort_order")
private Long order;
@Column(name = "tag")
private String tag;
@Column(name = "is_deleted")
private Boolean isDeleted = false;
public LayerDto.Detail toDto() {
return new LayerDto.Detail(
this.uuid,
this.layerType,
this.title,
this.description,
this.tag,
this.order,
this.isChangeMap,
this.isLabelingMap,
this.url,
this.minLon,
this.minLat,
this.maxLon,
this.maxLat,
this.minZoom,
this.maxZoom,
this.createdDttm);
}
}

View File

@@ -1,8 +1,18 @@
package com.kamco.cd.kamcoback.postgres.repository.layer;
import com.kamco.cd.kamcoback.layer.dto.LayerDto;
import com.kamco.cd.kamcoback.postgres.entity.MapLayerEntity;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface MapLayerRepositoryCustom {
Optional<MapLayerEntity> findSortOrderDesc();
Long findSortOrderDesc();
List<LayerDto.Basic> findAllLayer(LayerDto.SearchReq searchReq);
Optional<MapLayerEntity> findDetailByUuid(UUID uuid);
List<MapLayerEntity> findAllByUuidIn(Collection<UUID> uuids);
}

View File

@@ -2,9 +2,15 @@ package com.kamco.cd.kamcoback.postgres.repository.layer;
import static com.kamco.cd.kamcoback.postgres.entity.QMapLayerEntity.mapLayerEntity;
import com.kamco.cd.kamcoback.layer.dto.LayerDto;
import com.kamco.cd.kamcoback.postgres.entity.MapLayerEntity;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
@@ -15,13 +21,67 @@ public class MapLayerRepositoryImpl implements MapLayerRepositoryCustom {
private final JPAQueryFactory queryFactory;
@Override
public Optional<MapLayerEntity> findSortOrderDesc() {
public Long findSortOrderDesc() {
return queryFactory
.select(mapLayerEntity.order.max().coalesce(0L))
.from(mapLayerEntity)
.where(mapLayerEntity.order.isNotNull())
.fetchOne();
}
@Override
public List<LayerDto.Basic> findAllLayer(LayerDto.SearchReq searchReq) {
BooleanBuilder whereBuilder = new BooleanBuilder();
whereBuilder.and(mapLayerEntity.isDeleted.isFalse());
if (searchReq != null) {
if (searchReq.getTag() != null) {
whereBuilder.and(mapLayerEntity.tag.toLowerCase().eq(searchReq.getTag().toLowerCase()));
}
if (searchReq.getLayerType() != null) {
whereBuilder.and(
mapLayerEntity.layerType.toLowerCase().eq(searchReq.getLayerType().toLowerCase()));
}
}
return queryFactory
.select(
Projections.constructor(
LayerDto.Basic.class,
mapLayerEntity.uuid,
mapLayerEntity.layerType,
mapLayerEntity.description,
mapLayerEntity.tag,
mapLayerEntity.order,
mapLayerEntity.isChangeMap,
mapLayerEntity.isLabelingMap,
mapLayerEntity.createdDttm))
.from(mapLayerEntity)
.where(whereBuilder)
.orderBy(mapLayerEntity.order.asc())
.fetch();
}
@Override
public Optional<MapLayerEntity> findDetailByUuid(UUID uuid) {
return Optional.ofNullable(
queryFactory
.selectFrom(mapLayerEntity)
.where(mapLayerEntity.order.isNotNull())
.orderBy(mapLayerEntity.order.desc())
.limit(1)
.select(mapLayerEntity)
.from(mapLayerEntity)
.where(mapLayerEntity.uuid.eq(uuid).and(mapLayerEntity.isDeleted.isFalse()))
.orderBy(mapLayerEntity.order.asc())
.fetchOne());
}
@Override
public List<MapLayerEntity> findAllByUuidIn(Collection<UUID> uuids) {
return queryFactory
.select(mapLayerEntity)
.from(mapLayerEntity)
.where(mapLayerEntity.uuid.in(uuids).and(mapLayerEntity.isDeleted.isFalse()))
.orderBy(mapLayerEntity.order.asc())
.fetch();
}
}