도엽관리 목록,등록,추론업데이트 API
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ApiResponseCode;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ResponseObj;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapInkx50kEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapInkx5kEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.scene.MapInkx50kRepository;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.scene.MapInkx5kRepository;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto.UseInferReq;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MapInkxMngCoreService {
|
||||
|
||||
private final MapInkx5kRepository mapInkx5kRepository;
|
||||
private final MapInkx50kRepository mapInkx50kRepository;
|
||||
|
||||
// 목록
|
||||
public Page<MapInkxMngDto.MapList> findMapInkxMngList(
|
||||
MapInkxMngDto.searchReq searchReq, String useInference, String searchVal) {
|
||||
return mapInkx5kRepository.findMapInkxMngList(searchReq, useInference, searchVal);
|
||||
}
|
||||
|
||||
// 저장
|
||||
public ResponseObj saveMapInkx5k(MapInkxMngDto.AddMapReq req, Polygon map_polygon) {
|
||||
|
||||
Long existsCount = mapInkx5kRepository.findByMapidCdNoExists(req.getMapidcdNo());
|
||||
|
||||
if (existsCount > 0) {
|
||||
return new ResponseObj(ApiResponseCode.DUPLICATE_DATA, "이미 등록된 도엽코드 입니다.");
|
||||
}
|
||||
|
||||
Integer fid50k = mapInkx50kRepository.findByMapidCdParentNo(req.getMapidcdNo());
|
||||
if (fid50k == null || fid50k <= 0) {
|
||||
// parent도 등록
|
||||
MapInkx50kEntity parent =
|
||||
new MapInkx50kEntity(req.getMapidcdNo().substring(0, 5), req.getMapidNm(), "", null);
|
||||
MapInkx50kEntity result = mapInkx50kRepository.save(parent);
|
||||
fid50k = result.getFid();
|
||||
}
|
||||
|
||||
MapInkx5kEntity entity =
|
||||
new MapInkx5kEntity(
|
||||
req.getMapidcdNo(),
|
||||
req.getMapidNm(),
|
||||
map_polygon,
|
||||
fid50k == null ? null : fid50k.longValue(),
|
||||
"USE" // 기본은 USE로
|
||||
);
|
||||
|
||||
mapInkx5kRepository.save(entity);
|
||||
|
||||
return new ResponseObj(ApiResponseCode.OK, "");
|
||||
}
|
||||
|
||||
public ResponseObj updateUseInference(@Valid UseInferReq useInferReq) {
|
||||
Optional<MapInkx5kEntity> entity =
|
||||
Optional.ofNullable(
|
||||
mapInkx5kRepository
|
||||
.findByMapidCdNoInfo(useInferReq.getMapidcdNo())
|
||||
.orElseThrow(() -> new EntityNotFoundException("도엽정보를 찾을 수 없습니다.")));
|
||||
|
||||
entity.get().updateUseInference(useInferReq.getUseInference());
|
||||
return new ResponseObj(ApiResponseCode.OK, "");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,15 @@
|
||||
package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
@@ -9,7 +17,9 @@ import org.locationtech.jts.geom.Geometry;
|
||||
@Setter
|
||||
@Table(name = "tb_map_inkx_50k")
|
||||
@Entity
|
||||
public class MapInkx50kEntity {
|
||||
@NoArgsConstructor
|
||||
public class MapInkx50kEntity extends CommonDateEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_map_inkx_50k_fid_seq_gen")
|
||||
@SequenceGenerator(
|
||||
@@ -29,4 +39,11 @@ public class MapInkx50kEntity {
|
||||
|
||||
@Column(name = "geom")
|
||||
private Geometry geom;
|
||||
|
||||
public MapInkx50kEntity(String mapidcdNo, String mapidNm, String mapidNo, Geometry geom) {
|
||||
this.mapidcdNo = mapidcdNo;
|
||||
this.mapidNm = mapidNm;
|
||||
this.mapidNo = mapidNo;
|
||||
this.geom = geom;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.kamco.cd.kamcoback.postgres.entity;
|
||||
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.MapSheet;
|
||||
import com.kamco.cd.kamcoback.postgres.CommonDateEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@@ -10,6 +11,7 @@ import jakarta.persistence.Id;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
@@ -17,7 +19,8 @@ import org.locationtech.jts.geom.Geometry;
|
||||
@Setter
|
||||
@Table(name = "tb_map_inkx_5k")
|
||||
@Entity
|
||||
public class MapInkx5kEntity {
|
||||
@NoArgsConstructor
|
||||
public class MapInkx5kEntity extends CommonDateEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tb_map_inkx_5k_fid_seq_gen")
|
||||
@@ -39,6 +42,22 @@ public class MapInkx5kEntity {
|
||||
@Column(name = "fid_k50")
|
||||
private Long fidK50;
|
||||
|
||||
@Column(name = "use_inference")
|
||||
private String useInference;
|
||||
|
||||
public MapInkx5kEntity(
|
||||
String mapidcdNo, String mapidNm, Geometry geom, Long fidK50, String useInference) {
|
||||
this.mapidcdNo = mapidcdNo;
|
||||
this.mapidNm = mapidNm;
|
||||
this.geom = geom;
|
||||
this.fidK50 = fidK50;
|
||||
this.useInference = useInference;
|
||||
}
|
||||
|
||||
public void updateUseInference(String useInference) {
|
||||
this.useInference = useInference;
|
||||
}
|
||||
|
||||
public InferenceResultDto.MapSheet toEntity() {
|
||||
return new MapSheet(mapidcdNo, mapidNm);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.scene;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapInkx50kEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface MapInkx50kRepository
|
||||
extends JpaRepository<MapInkx50kEntity, Long>, MapInkx50kRepositoryCustom {}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.scene;
|
||||
|
||||
public interface MapInkx50kRepositoryCustom {
|
||||
|
||||
Integer findByMapidCdParentNo(String mapidcdNo);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.scene;
|
||||
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx50kEntity.mapInkx50kEntity;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapInkx5kEntity;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
|
||||
public class MapInkx50kRepositoryImpl extends QuerydslRepositorySupport
|
||||
implements MapInkx50kRepositoryCustom {
|
||||
|
||||
private final JPAQueryFactory queryFactory;
|
||||
|
||||
public MapInkx50kRepositoryImpl(JPAQueryFactory queryFactory) {
|
||||
super(MapInkx5kEntity.class);
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer findByMapidCdParentNo(String mapidcdNo) {
|
||||
String parentCd = mapidcdNo.substring(0, 5);
|
||||
return queryFactory
|
||||
.select(mapInkx50kEntity.fid)
|
||||
.from(mapInkx50kEntity)
|
||||
.where(mapInkx50kEntity.mapidcdNo.eq(parentCd))
|
||||
.fetchOne();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,20 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.scene;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapInkx5kEntity;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto.MapList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface MapInkx5kRepositoryCustom {
|
||||
|
||||
List<MapInkx5kEntity> listGetScenes5k(List<String> codes);
|
||||
|
||||
Page<MapList> findMapInkxMngList(
|
||||
MapInkxMngDto.searchReq searchReq, String useInference, String searchVal);
|
||||
|
||||
Long findByMapidCdNoExists(String mapidcdNo);
|
||||
|
||||
Optional<MapInkx5kEntity> findByMapidCdNoInfo(String mapidcdNo);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
package com.kamco.cd.kamcoback.postgres.repository.scene;
|
||||
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx50kEntity.mapInkx50kEntity;
|
||||
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity.mapInkx5kEntity;
|
||||
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapInkx5kEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto.MapList;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto.searchReq;
|
||||
import com.querydsl.core.types.Projections;
|
||||
import com.querydsl.core.types.dsl.BooleanExpression;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
|
||||
|
||||
public class MapInkx5kRepositoryImpl extends QuerydslRepositorySupport
|
||||
@@ -25,4 +39,84 @@ public class MapInkx5kRepositoryImpl extends QuerydslRepositorySupport
|
||||
.orderBy(map5k.mapidcdNo.asc())
|
||||
.fetch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<MapList> findMapInkxMngList(
|
||||
searchReq searchReq, String useInference, String searchVal) {
|
||||
|
||||
Pageable pageable = searchReq.toPageable();
|
||||
List<MapInkxMngDto.MapList> foundContent =
|
||||
queryFactory
|
||||
.select(
|
||||
Projections.constructor(
|
||||
MapInkxMngDto.MapList.class,
|
||||
Expressions.numberTemplate(
|
||||
Integer.class,
|
||||
"row_number() over(order by {0} asc)",
|
||||
mapInkx5kEntity.mapidcdNo),
|
||||
mapInkx5kEntity.mapidcdNo,
|
||||
mapInkx50kEntity.mapidcdNo,
|
||||
mapInkx5kEntity.mapidNm,
|
||||
mapInkx5kEntity.createdDate,
|
||||
mapInkx5kEntity.modifiedDate,
|
||||
// Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')",
|
||||
// mapInkx5kEntity.createdDate),
|
||||
// Expressions.stringTemplate("to_char({0}, 'YYYY-MM-DD')",
|
||||
// mapInkx5kEntity.modifiedDate),
|
||||
mapInkx5kEntity.useInference))
|
||||
.from(mapInkx5kEntity)
|
||||
.innerJoin(mapInkx50kEntity)
|
||||
.on(mapInkx5kEntity.fidK50.intValue().eq(mapInkx50kEntity.fid))
|
||||
.where(searchUseInference(useInference), searchValueMapCdNm(searchVal))
|
||||
.offset(pageable.getOffset())
|
||||
.limit(pageable.getPageSize())
|
||||
.orderBy(mapInkx5kEntity.mapidcdNo.asc())
|
||||
.fetch();
|
||||
|
||||
Long countQuery =
|
||||
queryFactory
|
||||
.select(mapInkx5kEntity.count())
|
||||
.from(mapInkx5kEntity)
|
||||
.innerJoin(mapInkx50kEntity)
|
||||
.on(mapInkx5kEntity.fidK50.intValue().eq(mapInkx50kEntity.fid))
|
||||
.where(searchUseInference(useInference), searchValueMapCdNm(searchVal))
|
||||
.fetchOne();
|
||||
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long findByMapidCdNoExists(String mapidcdNo) {
|
||||
return queryFactory
|
||||
.select(mapInkx5kEntity.count())
|
||||
.from(mapInkx5kEntity)
|
||||
.where(mapInkx5kEntity.mapidcdNo.eq(mapidcdNo))
|
||||
.fetchOne();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<MapInkx5kEntity> findByMapidCdNoInfo(String mapidcdNo) {
|
||||
return Optional.ofNullable(
|
||||
queryFactory
|
||||
.selectFrom(mapInkx5kEntity)
|
||||
.where(mapInkx5kEntity.mapidcdNo.eq(mapidcdNo))
|
||||
.fetchOne());
|
||||
}
|
||||
|
||||
private BooleanExpression searchUseInference(String useInference) {
|
||||
if (Objects.isNull(useInference)) {
|
||||
return null;
|
||||
}
|
||||
return mapInkx5kEntity.useInference.eq(useInference);
|
||||
}
|
||||
|
||||
private BooleanExpression searchValueMapCdNm(String searchVal) {
|
||||
if (Objects.isNull(searchVal)) {
|
||||
return null;
|
||||
}
|
||||
return mapInkx5kEntity
|
||||
.mapidcdNo
|
||||
.like("%" + searchVal + "%")
|
||||
.or(mapInkx5kEntity.mapidNm.like("%" + searchVal + "%"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user