Skip to content

Commit

Permalink
faet: 여러 유형의 진단서 대응 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
GiHwan2 committed Dec 3, 2024
1 parent 3b57586 commit b403cf5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component("medicalCertificateOcrParser")
@Slf4j
public class MedicalCertificateOcrParser implements OcrParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@

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;
import com.ivory.ivory.repository.AbsenceCertificateRepository;
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;
Expand All @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
28 changes: 23 additions & 5 deletions src/main/java/com/ivory/ivory/util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTimeFormatter> 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);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ kakaopay:
cid: ${CID}

jwt:
secret: ${JWT_SECRET}
secret: ${JWT_SECRET}

swagger:
server:
url: http://localhost:8080

0 comments on commit b403cf5

Please sign in to comment.