From b403cf57a62f8508c4bfbd75e2db26233a4e80f0 Mon Sep 17 00:00:00 2001 From: GiHwan2 Date: Tue, 3 Dec 2024 21:43:34 +0900 Subject: [PATCH] =?UTF-8?q?faet:=20=EC=97=AC=EB=9F=AC=20=EC=9C=A0=ED=98=95?= =?UTF-8?q?=EC=9D=98=20=EC=A7=84=EB=8B=A8=EC=84=9C=20=EB=8C=80=EC=9D=91=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ivory/ivory/ocr/CertificateOcrParser.java | 2 +- .../ocr/MedicalCertificateOcrParser.java | 1 - .../service/AbsenceCertificateService.java | 7 ----- .../service/MedicalCertificateService.java | 15 +++------- .../java/com/ivory/ivory/util/DateUtil.java | 28 +++++++++++++++---- src/main/resources/application.yml | 6 +++- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/ivory/ivory/ocr/CertificateOcrParser.java b/src/main/java/com/ivory/ivory/ocr/CertificateOcrParser.java index 24627d8..59fb775 100644 --- a/src/main/java/com/ivory/ivory/ocr/CertificateOcrParser.java +++ b/src/main/java/com/ivory/ivory/ocr/CertificateOcrParser.java @@ -7,8 +7,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -@Component("certificateOcrParser") @Slf4j +@Component public class CertificateOcrParser implements OcrParser { private final ObjectMapper objectMapper = new ObjectMapper(); diff --git a/src/main/java/com/ivory/ivory/ocr/MedicalCertificateOcrParser.java b/src/main/java/com/ivory/ivory/ocr/MedicalCertificateOcrParser.java index fca519e..2093400 100644 --- a/src/main/java/com/ivory/ivory/ocr/MedicalCertificateOcrParser.java +++ b/src/main/java/com/ivory/ivory/ocr/MedicalCertificateOcrParser.java @@ -7,7 +7,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -@Component("medicalCertificateOcrParser") @Slf4j public class MedicalCertificateOcrParser implements OcrParser { diff --git a/src/main/java/com/ivory/ivory/service/AbsenceCertificateService.java b/src/main/java/com/ivory/ivory/service/AbsenceCertificateService.java index 43d1110..ed659a5 100644 --- a/src/main/java/com/ivory/ivory/service/AbsenceCertificateService.java +++ b/src/main/java/com/ivory/ivory/service/AbsenceCertificateService.java @@ -2,14 +2,10 @@ import com.ivory.ivory.domain.AbsenceCertificate; import com.ivory.ivory.domain.Child; -import com.ivory.ivory.domain.MedicalCertificate; import com.ivory.ivory.dto.AbsenceCertificatePageDto; import com.ivory.ivory.dto.AbsenceCertificateRequestDto; import com.ivory.ivory.dto.AbsenceCertificateResponseDto; import com.ivory.ivory.dto.AbsenceCertificatesDto; -import com.ivory.ivory.dto.MedicalCertificatePageDto; -import com.ivory.ivory.dto.MedicalCertificateResponseDto; -import com.ivory.ivory.dto.MedicalCertificatesDto; import com.ivory.ivory.dto.PageInfo; import com.ivory.ivory.ocr.OcrParser; import com.ivory.ivory.ocr.OcrService; @@ -17,13 +13,11 @@ import com.ivory.ivory.repository.ChildRepository; import com.ivory.ivory.util.DateUtil; import java.io.IOException; -import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -40,7 +34,6 @@ public class AbsenceCertificateService { private final AbsenceCertificateRepository absenceCertificateRepository; private final ChildRepository childRepository; private final OcrService ocrService; - @Qualifier("certificateOcrParser") private final OcrParser certificateOcrParser; @Value("${ocr.api.url}") diff --git a/src/main/java/com/ivory/ivory/service/MedicalCertificateService.java b/src/main/java/com/ivory/ivory/service/MedicalCertificateService.java index ac8b2b9..c27fc95 100644 --- a/src/main/java/com/ivory/ivory/service/MedicalCertificateService.java +++ b/src/main/java/com/ivory/ivory/service/MedicalCertificateService.java @@ -1,20 +1,15 @@ package com.ivory.ivory.service; -import com.ivory.ivory.domain.AbsenceCertificate; import com.ivory.ivory.domain.Child; import com.ivory.ivory.domain.Disease; import com.ivory.ivory.domain.MedicalCertificate; -import com.ivory.ivory.dto.AbsenceCertificateRequestDto; -import com.ivory.ivory.dto.AbsenceCertificateResponseDto; import com.ivory.ivory.dto.MedicalCertificatePageDto; import com.ivory.ivory.dto.MedicalCertificateRequestDto; import com.ivory.ivory.dto.MedicalCertificateResponseDto; import com.ivory.ivory.dto.MedicalCertificatesDto; import com.ivory.ivory.dto.PageInfo; -import com.ivory.ivory.ocr.MedicalCertificateOcrService; import com.ivory.ivory.ocr.OcrParser; import com.ivory.ivory.ocr.OcrService; -import com.ivory.ivory.repository.AbsenceCertificateRepository; import com.ivory.ivory.repository.ChildRepository; import com.ivory.ivory.repository.MedicalCertificateRepository; import com.ivory.ivory.util.DateUtil; @@ -25,7 +20,6 @@ import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -41,13 +35,12 @@ public class MedicalCertificateService { private final MedicalCertificateRepository medicalCertificateRepository; private final ChildRepository childRepository; - private final MedicalCertificateOcrService ocrService; - - @Qualifier("medicalCertificateOcrParser") + private final OcrService ocrService; private final OcrParser medicalCertificateOcrParser; - @Value("${ocr.medical-certificate.api.url}") + + @Value("${ocr.api.url}") private String apiUrl; - @Value("${ocr.medical-certificate.api.secret-key}") + @Value("${ocr.api.secret-key}") private String secretKey; @Transactional diff --git a/src/main/java/com/ivory/ivory/util/DateUtil.java b/src/main/java/com/ivory/ivory/util/DateUtil.java index 4f3ec6d..0ca483c 100644 --- a/src/main/java/com/ivory/ivory/util/DateUtil.java +++ b/src/main/java/com/ivory/ivory/util/DateUtil.java @@ -3,15 +3,33 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.util.ArrayList; +import java.util.List; public class DateUtil { - private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일"); + private static final List formatters = new ArrayList<>(); + + static { + formatters.add(DateTimeFormatter.ofPattern("yyyy년 MM월 dd일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy년 M월 d일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy년 MM월 d일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy년 M월 dd일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy년MM월dd일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy년M월d일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy년MM월d일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy년M월dd일")); + formatters.add(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + formatters.add(DateTimeFormatter.ofPattern("yyyy/MM/dd")); + } public static LocalDate parseToLocalDate(String date) { - try { - return LocalDate.parse(date, formatter); - } catch (DateTimeParseException e) { - throw new IllegalArgumentException("유효하지 않은 날짜 형식: " + date, e); + for (DateTimeFormatter formatter : formatters) { + try { + return LocalDate.parse(date, formatter); + } catch (DateTimeParseException ignored) { + // 다음 패턴 시도 + } } + throw new IllegalArgumentException("유효하지 않은 날짜 형식: " + date); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cf1323c..bce8ab9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -38,4 +38,8 @@ kakaopay: cid: ${CID} jwt: - secret: ${JWT_SECRET} \ No newline at end of file + secret: ${JWT_SECRET} + +swagger: + server: + url: http://localhost:8080 \ No newline at end of file