도엽관리 목록,등록,추론업데이트 API
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package com.kamco.cd.kamcoback.scene;
|
||||
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.scene.dto.MapInkxMngDto;
|
||||
import com.kamco.cd.kamcoback.scene.service.MapInkxMngService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "도엽 관리", description = "도엽 관리 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/scene")
|
||||
public class MapInkxMngApiController {
|
||||
|
||||
private final MapInkxMngService mapInkxMngService;
|
||||
|
||||
@Operation(summary = "목록 조회", description = "도엽 목록 조회")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = CommonCodeDto.Basic.class))),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping
|
||||
public ApiResponseDto<Page<MapInkxMngDto.MapList>> findMapInkxMngList(
|
||||
@RequestParam int page,
|
||||
@RequestParam(defaultValue = "20") int size,
|
||||
@RequestParam(required = false) String useInference,
|
||||
@RequestParam(required = false) String searchVal) {
|
||||
MapInkxMngDto.searchReq searchReq = new MapInkxMngDto.searchReq(page, size, "");
|
||||
return ApiResponseDto.ok(
|
||||
mapInkxMngService.findMapInkxMngList(searchReq, useInference, searchVal));
|
||||
}
|
||||
|
||||
@Operation(summary = "저장", description = "도엽정보를 저장 합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "도엽정보 저장 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ApiResponseDto.ResponseObj.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PostMapping
|
||||
public ApiResponseDto<ApiResponseDto.ResponseObj> saveMapInkx5k(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "도엽정보 생성 요청 정보",
|
||||
required = true,
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = MapInkxMngDto.AddMapReq.class)))
|
||||
@RequestBody
|
||||
@Valid
|
||||
MapInkxMngDto.AddMapReq addReq) {
|
||||
return ApiResponseDto.okObject(mapInkxMngService.saveMapInkx5k(addReq));
|
||||
}
|
||||
|
||||
@Operation(summary = "추론제외 업데이트", description = "추론제외 업데이트 합니다.")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "201",
|
||||
description = "추론제외 업데이트 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ApiResponseDto.ResponseObj.class))),
|
||||
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터", content = @Content),
|
||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@PutMapping("/use-inference")
|
||||
public ApiResponseDto<ApiResponseDto.ResponseObj> updateUseInference(
|
||||
@io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "추론제외 업데이트 정보",
|
||||
required = true,
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = MapInkxMngDto.UseInferReq.class)))
|
||||
@RequestBody
|
||||
@Valid
|
||||
MapInkxMngDto.UseInferReq useInferReq) {
|
||||
return ApiResponseDto.okObject(mapInkxMngService.updateUseInference(useInferReq));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.kamco.cd.kamcoback.scene.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.kamco.cd.kamcoback.common.utils.enums.CodeExpose;
|
||||
import com.kamco.cd.kamcoback.common.utils.enums.EnumType;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
public class MapInkxMngDto {
|
||||
|
||||
@CodeExpose
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum UseInferenceType implements EnumType {
|
||||
USE("사용중"),
|
||||
EXCEPT("영구 추론제외");
|
||||
|
||||
private final String desc;
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
|
||||
@Schema(name = "Basic", description = "Basic")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Basic {
|
||||
|
||||
private Integer fid;
|
||||
private String mapidcdNo;
|
||||
private String mapidNm;
|
||||
private JsonNode geom;
|
||||
private Long fidK50;
|
||||
private String useInference;
|
||||
private ZonedDateTime createdDttm;
|
||||
private ZonedDateTime updatedDttm;
|
||||
}
|
||||
|
||||
@Schema(name = "MapList", description = "목록 항목")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public static class MapList {
|
||||
|
||||
private Integer rowNum;
|
||||
private String mapidcdNo5k;
|
||||
private String mapidcdNo50k;
|
||||
private String mapidNm;
|
||||
private String createdDttm;
|
||||
private String updatedDttm;
|
||||
private String useInference;
|
||||
private ZonedDateTime createdDttmTime;
|
||||
private ZonedDateTime updatedDttmTime;
|
||||
|
||||
// 목록 Querydsl 에서 리턴 받는 건 생성자 기준임 -> 쿼리 컬럼 그대로 받고 여기서 Java 형변환 해서 return 하기
|
||||
public MapList(
|
||||
Integer rowNum,
|
||||
String mapidcdNo5k,
|
||||
String mapidcdNo50k,
|
||||
String mapidNm,
|
||||
ZonedDateTime createdDttmTime,
|
||||
ZonedDateTime updatedDttmTime,
|
||||
String useInference) {
|
||||
this.rowNum = rowNum;
|
||||
this.mapidcdNo5k = mapidcdNo5k;
|
||||
this.mapidcdNo50k = mapidcdNo50k;
|
||||
this.mapidNm = mapidNm;
|
||||
|
||||
DateTimeFormatter fmt =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.of("Asia/Seoul"));
|
||||
this.createdDttm = fmt.format(createdDttmTime);
|
||||
this.updatedDttm = fmt.format(updatedDttmTime);
|
||||
this.createdDttmTime = createdDttmTime;
|
||||
this.updatedDttmTime = updatedDttmTime;
|
||||
this.useInference =
|
||||
useInference.equals("USE")
|
||||
? UseInferenceType.USE.getDesc()
|
||||
: UseInferenceType.EXCEPT.getDesc();
|
||||
}
|
||||
}
|
||||
|
||||
@Schema(name = "searchReq", description = "검색 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class searchReq {
|
||||
|
||||
// 페이징 파라미터
|
||||
private int page = 0;
|
||||
private int size = 20;
|
||||
private String sort;
|
||||
|
||||
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 = "AddMapReq", description = "등록 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class AddMapReq {
|
||||
|
||||
@Schema(description = "도엽번호", example = "31540687")
|
||||
private String mapidcdNo;
|
||||
|
||||
@Schema(description = "도엽명", example = "공덕")
|
||||
private String mapidNm;
|
||||
|
||||
@Schema(
|
||||
description = "좌표 목록 (한 줄에 한 점, '경도 위도' 형식)",
|
||||
example =
|
||||
"127.17500001632317 36.17499998262991\n"
|
||||
+ "127.14999995475043 36.17500002877932\n"
|
||||
+ "127.15000004313612 36.199999984012415\n"
|
||||
+ "127.1750000466954 36.20000001863179")
|
||||
private String coordinates;
|
||||
}
|
||||
|
||||
@Schema(name = "UseInferReq", description = "추론제외 업데이트 요청")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class UseInferReq {
|
||||
|
||||
private String mapidcdNo;
|
||||
private String useInference;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.kamco.cd.kamcoback.scene.service;
|
||||
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ResponseObj;
|
||||
import com.kamco.cd.kamcoback.postgres.core.MapInkxMngCoreService;
|
||||
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.UseInferReq;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
import org.locationtech.jts.geom.LinearRing;
|
||||
import org.locationtech.jts.geom.PrecisionModel;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MapInkxMngService {
|
||||
|
||||
private final MapInkxMngCoreService mapInkxMngCoreService;
|
||||
|
||||
public Page<MapList> findMapInkxMngList(
|
||||
MapInkxMngDto.searchReq searchReq, String useInference, String searchVal) {
|
||||
return mapInkxMngCoreService.findMapInkxMngList(searchReq, useInference, searchVal);
|
||||
}
|
||||
|
||||
public ResponseObj saveMapInkx5k(@Valid MapInkxMngDto.AddMapReq req) {
|
||||
|
||||
String[] coordinates = req.getCoordinates().split("\\r?\\n");
|
||||
List<Coordinate> coords = new ArrayList<Coordinate>();
|
||||
|
||||
for (String line : coordinates) {
|
||||
String[] parts = line.trim().split("\\s+");
|
||||
|
||||
double lon = Double.parseDouble(parts[0]); // 경도
|
||||
double lat = Double.parseDouble(parts[1]); // 위도
|
||||
|
||||
coords.add(new Coordinate(lon, lat));
|
||||
}
|
||||
|
||||
// Polygon은 반드시 닫혀 있어야 함
|
||||
if (!coords.get(0).equals2D(coords.get(coords.size() - 1))) {
|
||||
coords.add(coords.get(0));
|
||||
}
|
||||
|
||||
GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(new PrecisionModel(), 4326);
|
||||
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(coords.toArray(new Coordinate[0]));
|
||||
|
||||
return mapInkxMngCoreService.saveMapInkx5k(req, GEOMETRY_FACTORY.createPolygon(shell));
|
||||
}
|
||||
|
||||
public ResponseObj updateUseInference(@Valid UseInferReq useInferReq) {
|
||||
return mapInkxMngCoreService.updateUseInference(useInferReq);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user