변화탐지 clazz API : enum -> 공통코드로 변경
This commit is contained in:
@@ -3,10 +3,8 @@ package com.kamco.cd.kamcoback.code;
|
||||
import com.kamco.cd.kamcoback.code.config.CommonCodeCacheManager;
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.code.service.CommonCodeService;
|
||||
import com.kamco.cd.kamcoback.common.enums.DetectionClassification;
|
||||
import com.kamco.cd.kamcoback.common.utils.CommonCodeUtil;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Clazzes;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -14,8 +12,6 @@ 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 java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@@ -36,6 +32,7 @@ public class CommonCodeApiController {
|
||||
|
||||
private final CommonCodeService commonCodeService;
|
||||
private final CommonCodeCacheManager commonCodeCacheManager;
|
||||
private final CommonCodeUtil commonCodeUtil;
|
||||
|
||||
@Operation(summary = "목록 조회", description = "모든 공통코드 조회")
|
||||
@ApiResponses(
|
||||
@@ -213,12 +210,20 @@ public class CommonCodeApiController {
|
||||
}
|
||||
|
||||
@GetMapping("/clazz")
|
||||
public ApiResponseDto<List<InferenceResultDto.Clazzes>> getClasses() {
|
||||
public ApiResponseDto<List<CommonCodeDto.Clazzes>> getClasses() {
|
||||
|
||||
List<Clazzes> list =
|
||||
Arrays.stream(DetectionClassification.values())
|
||||
.sorted(Comparator.comparingInt(DetectionClassification::getOrder))
|
||||
.map(Clazzes::new)
|
||||
// List<Clazzes> list =
|
||||
// Arrays.stream(DetectionClassification.values())
|
||||
// .sorted(Comparator.comparingInt(DetectionClassification::getOrder))
|
||||
// .map(Clazzes::new)
|
||||
// .toList();
|
||||
|
||||
//변화탐지 clazz API : enum -> 공통코드로 변경
|
||||
List<CommonCodeDto.Clazzes> list =
|
||||
commonCodeUtil.getChildCodesByParentCode("0000").stream()
|
||||
.map(
|
||||
child ->
|
||||
new CommonCodeDto.Clazzes(child.getCode(), child.getName(), child.getOrder()))
|
||||
.toList();
|
||||
|
||||
return ApiResponseDto.ok(list);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.code.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.kamco.cd.kamcoback.common.utils.html.HtmlEscapeDeserializer;
|
||||
@@ -71,15 +72,6 @@ public class CommonCodeDto {
|
||||
@NotNull private Integer order;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class OrderReqDetail {
|
||||
@NotNull private Long id;
|
||||
@NotNull private Integer order;
|
||||
}
|
||||
|
||||
@Schema(name = "CommonCode Basic", description = "공통코드 기본 정보")
|
||||
@Getter
|
||||
public static class Basic {
|
||||
@@ -139,4 +131,22 @@ public class CommonCodeDto {
|
||||
this.deletedDttm = deletedDttm;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class Clazzes {
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Double score;
|
||||
|
||||
private Integer order;
|
||||
|
||||
public Clazzes(String code, String name, Integer order) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.kamco.cd.kamcoback.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.Basic;
|
||||
import com.kamco.cd.kamcoback.code.service.CommonCodeService;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
@@ -19,6 +23,8 @@ public class CommonCodeUtil {
|
||||
|
||||
private final CommonCodeService commonCodeService;
|
||||
|
||||
@Autowired private ObjectMapper objectMapper;
|
||||
|
||||
public CommonCodeUtil(CommonCodeService commonCodeService) {
|
||||
this.commonCodeService = commonCodeService;
|
||||
}
|
||||
@@ -30,7 +36,21 @@ public class CommonCodeUtil {
|
||||
*/
|
||||
public List<Basic> getAllCommonCodes() {
|
||||
try {
|
||||
return commonCodeService.getFindAll();
|
||||
// 캐시에 들어간 이후 꺼낼 때, DTO를 인식하지 못하여 LinkedHashMap으로 리턴됨.
|
||||
// LinkedHashMap인 경우 변환처리, 아닌 경우는 그대로 리턴함.
|
||||
List<?> allCodes = commonCodeService.getFindAll();
|
||||
return allCodes.stream()
|
||||
.map(
|
||||
item -> {
|
||||
if (item instanceof LinkedHashMap<?, ?> map) {
|
||||
return objectMapper.convertValue(map, CommonCodeDto.Basic.class);
|
||||
} else if (item instanceof CommonCodeDto.Basic dto) {
|
||||
return dto;
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported cache type: " + item.getClass());
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
} catch (Exception e) {
|
||||
log.error("공통코드 전체 조회 중 오류 발생", e);
|
||||
return List.of();
|
||||
@@ -111,8 +131,24 @@ public class CommonCodeUtil {
|
||||
}
|
||||
|
||||
try {
|
||||
List<Basic> allCodes = commonCodeService.getFindAll();
|
||||
return allCodes.stream()
|
||||
// 캐시에 들어간 이후 꺼낼 때, DTO를 인식하지 못하여 LinkedHashMap으로 리턴됨.
|
||||
// LinkedHashMap인 경우 변환처리, 아닌 경우는 그대로 리턴함.
|
||||
List<?> allCodes = commonCodeService.getFindAll();
|
||||
List<Basic> convertList =
|
||||
allCodes.stream()
|
||||
.map(
|
||||
item -> {
|
||||
if (item instanceof LinkedHashMap<?, ?> map) {
|
||||
return objectMapper.convertValue(map, CommonCodeDto.Basic.class);
|
||||
} else if (item instanceof CommonCodeDto.Basic dto) {
|
||||
return dto;
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported cache type: " + item.getClass());
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
|
||||
return convertList.stream()
|
||||
.filter(code -> parentCode.equals(code.getCode()))
|
||||
.findFirst()
|
||||
.map(Basic::getChildren)
|
||||
@@ -126,12 +162,12 @@ public class CommonCodeUtil {
|
||||
/**
|
||||
* 코드 사용 가능 여부 확인
|
||||
*
|
||||
* @param parentId 상위 코드 ID
|
||||
* @param parentId 상위 코드 ID -> 1depth 는 null 허용 (파라미터 미필수로 변경)
|
||||
* @param code 확인할 코드값
|
||||
* @return 사용 가능 여부 (true: 사용 가능, false: 중복 또는 오류)
|
||||
*/
|
||||
public boolean isCodeAvailable(Long parentId, String code) {
|
||||
if (parentId == null || parentId <= 0 || code == null || code.isEmpty()) {
|
||||
if (parentId <= 0 || code == null || code.isEmpty()) {
|
||||
log.warn("유효하지 않은 입력: parentId={}, code={}", parentId, code);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user