Skip to content

Commit

Permalink
[차트 입력 기능] OCR + S3 + presigned url로 구현하기 (#86)
Browse files Browse the repository at this point in the history
* refactor : 알림 예약 수정 부분 삭제하기

* feat : 알림 전용 테이블 만들기

* feat : 리뷰 반영

* feat : sqs 서비스 붙이고 테스트하기

* feat : sqs 서비스 통일화

* feat : 관리자 페이지에서 요양보호사 추가할 때 알람 테이블도 추가하기

* refactor : 스케쥴러 코드 수정하기

* feat : 요양보호사 성공!!!

* feat : 다음 근무일에 보낼 알림 메시지 작성

* feat : 요양보호사 로직 완성

* refactor : 디렉토리 위치 변경

* feat : coolsms 의존성 추가

* feat : sms 문자 메시지 api 연결 완료

* feat : Presigned Url 생성 및 테스트 완료

* feat : 키값과 presigned url을 OcrData 테이블에 저장해주기

* feat : Naver Clova OCR API를 통하여 텍스트 추출 성공

* feat : Naver Clova OCR API를 통하여 표 추출 성공

* refactor : Presigned URL 생성 및 반환 로직 수정

* refactor : OCR 인식 과정 수정

* refactor : 간단한 수정

* refactor : excel 파일 이전

* refactor : 이름 수정

* refactor : 엑셀 파일 이전

* refactor : 4. Chart API까지 확인 완료

* refactor : 숨기기

* refactor : OCR Test 완료!!!
  • Loading branch information
pykido authored Nov 10, 2024
1 parent 0f5644e commit 288e1d4
Show file tree
Hide file tree
Showing 47 changed files with 1,237 additions and 432 deletions.
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ dependencies {

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// SQS
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.1")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sqs'

// CoolSMS
implementation 'net.nurigo:sdk:4.3.0'

// AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// Naver Clova OCR API
implementation 'org.springframework.boot:spring-boot-starter-webflux' // WebClient 사용을 위한 라이브러리
}

tasks.named('test') {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/dbdr/domain/careworker/WorkDay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dbdr.domain.careworker;

public enum WorkDay {
MONDAY(1),
TUESDAY(2),
WEDNESDAY(4),
THURSDAY(8),
FRIDAY(16),
SATURDAY(32),
SUNDAY(64);

private final int value;

WorkDay(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.springframework.web.bind.annotation.RestController;


@Tag(name = "요양보호사 마이페이지", description = "요양보호사 본인의 정보 조회 및 수정")
@Tag(name = "[요양보호사] 마이페이지", description = "요양보호사 본인의 정보 조회 및 수정")
@RestController
@RequestMapping("/${spring.app.version}/careworker")
@RequiredArgsConstructor
Expand Down Expand Up @@ -51,4 +51,4 @@ public ResponseEntity<ApiUtils.ApiResult<CareworkerMyPageResponse>> updateCarewo
careworkerRequest);
return ResponseEntity.ok(ApiUtils.success(updatedResponse));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dbdr.global.util.api.ApiUtils;
import dbdr.security.LoginInstitution;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
Expand All @@ -28,7 +29,7 @@ public class CareworkerInstitutionController {
@Operation(summary = "특정 요양원아이디로 전체 요양보호사 정보 조회", security = @SecurityRequirement(name = "JWT"))
@GetMapping("/institution")
public ResponseEntity<ApiUtils.ApiResult<List<CareworkerResponse>>> getAllCareworkers(
@LoginInstitution Institution institution) {
@Parameter(hidden = true) @LoginInstitution Institution institution) {
List<CareworkerResponse> institutions = careworkerService.getCareworkersByInstitution(institution.getId());
return ResponseEntity.ok(ApiUtils.success(institutions)) ;
}
Expand All @@ -37,7 +38,7 @@ public ResponseEntity<ApiUtils.ApiResult<List<CareworkerResponse>>> getAllCarewo
@GetMapping("/{careworkerId}")
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> getCareworkerById(
@PathVariable("careworkerId") Long careworkerId,
@LoginInstitution Institution institution) {
@Parameter(hidden = true) @LoginInstitution Institution institution) {
CareworkerResponse careworker = careworkerService.getCareworkerByInstitution(careworkerId, institution.getId());
return ResponseEntity.ok(ApiUtils.success(careworker)) ;
}
Expand All @@ -46,7 +47,7 @@ public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> getCareworkerById(
@Operation(summary = "요양보호사 추가", security = @SecurityRequirement(name = "JWT"))
@PostMapping
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> createCareworker(
@LoginInstitution Institution institution,
@Parameter(hidden = true) @LoginInstitution Institution institution,
@Valid @RequestBody CareworkerRequest careworkerDTO) {
CareworkerResponse newCareworker = careworkerService.createCareworker(careworkerDTO);
return ResponseEntity.status(HttpStatus.CREATED).body(ApiUtils.success(newCareworker));
Expand All @@ -58,7 +59,7 @@ public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> createCareworker(
@PutMapping("/{careworkerId}")
public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> updateCareworker(
@PathVariable Long careworkerId,
@LoginInstitution Institution institution,
@Parameter(hidden = true) @LoginInstitution Institution institution,
@RequestBody CareworkerRequest careworkerDTO) {
CareworkerResponse updatedCareworker = careworkerService.updateCareworker(careworkerId, careworkerDTO);
return ResponseEntity.ok(ApiUtils.success(updatedCareworker));
Expand All @@ -68,8 +69,8 @@ public ResponseEntity<ApiUtils.ApiResult<CareworkerResponse>> updateCareworker(
@DeleteMapping("/{careworkerId}")
public ResponseEntity<ApiUtils.ApiResult<String>> deleteCareworker(
@PathVariable Long careworkerId,
@LoginInstitution Institution institution) {
@Parameter(hidden = true) @LoginInstitution Institution institution) {
careworkerService.deleteCareworker(careworkerId, institution.getId());
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dbdr.domain.careworker.dto.request;


import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -9,13 +10,18 @@
import java.time.LocalTime;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonFormat;

@Getter
@AllArgsConstructor
public class CareworkerUpdateRequest {

@NotNull(message = "근무일은 필수 항목입니다.")
@Schema(description = "근무 요일 목록", example = "[\"MONDAY\", \"WEDNESDAY\", \"FRIDAY\"]")
private Set<DayOfWeek> workingDays;

@JsonFormat(pattern = "HH:mm")
@NotNull(message = "알림 시간은 필수 항목입니다.")
@Schema(description = "알림 시간 (HH:mm 형식)", example = "17:00")
private LocalTime alertTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class CareworkerMyPageResponse {
private String name;
private String phone;
private String institutionName;
private Set<DayOfWeek> workingDays;
private LocalTime alertTime;
}
private Set<DayOfWeek> workingDays;
}
62 changes: 44 additions & 18 deletions src/main/java/dbdr/domain/careworker/entity/Careworker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dbdr.domain.careworker.entity;

import java.time.DayOfWeek;
import java.time.LocalTime;

import dbdr.domain.core.base.entity.BaseEntity;
import dbdr.domain.institution.entity.Institution;
import jakarta.persistence.Column;
Expand All @@ -14,6 +17,7 @@
import jakarta.validation.constraints.Pattern;
import java.time.DayOfWeek;
import java.time.LocalTime;
import java.util.EnumSet;
import java.util.Set;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -43,29 +47,18 @@ public class Careworker extends BaseEntity {
@JoinColumn(name = "institution_id")
private Institution institution;

// 근무일을 요일로 설정
@ElementCollection(fetch = FetchType.LAZY)
@Enumerated(EnumType.STRING)
private Set<DayOfWeek> workingDays;
@Column(nullable = false)
private int workDays; // 비트 플래그로 요일 저장

@Column(nullable = true)
private String lineUserId;

@Column(nullable = true)
private LocalTime alertTime;
private LocalTime alertTime = LocalTime.of(17, 0); // 오후 5시로 초기화

@Column(unique = true)
private String email;

// @Builder
// public Careworker(Institution institution, String name, String email, String phone) {
// this.institution = institution;
// this.name = name;
// this.email = email;
// this.phone = phone;
// this.alertTime = LocalTime.of(17, 0); // 오후 5시로 초기화
// }

@Builder
public Careworker(String loginPassword, String phone, String name, Institution institution,
String email) {
Expand All @@ -74,6 +67,7 @@ public Careworker(String loginPassword, String phone, String name, Institution i
this.name = name;
this.institution = institution;
this.email = email;
this.alertTime = LocalTime.of(17, 0); // 오후 5시로 초기화
}

public void updateCareworker(Careworker careworker) {
Expand All @@ -87,15 +81,47 @@ public void updateLineUserId(String lineUserId) {
}

public void updateWorkingDays(Set<DayOfWeek> workingDays) {
this.workingDays = workingDays;
this.workDays = 0; // 초기화하여 기존 값을 제거합니다.
for (DayOfWeek day : workingDays) {
this.workDays |= (1 << (day.getValue() - 1)); // 각 요일을 비트 플래그로 추가합니다.
}
}

public Set<DayOfWeek> getWorkingDays() {
Set<DayOfWeek> workingDays = EnumSet.noneOf(DayOfWeek.class);
for (DayOfWeek day : DayOfWeek.values()) {
if ((this.workDays & (1 << (day.getValue() - 1))) != 0) {
workingDays.add(day);
}
}
return workingDays;
}
public void updateAlertTime(LocalTime alertTime) {
this.alertTime = alertTime;
}

public void updateInstitution(Institution institution) {
this.institution = institution;
public void updateInstitution(Institution institution) {
this.institution = institution;
}

// 요일 설정 및 조회 메서드
public void addWorkDay(DayOfWeek day) {
this.workDays |= day.getValue();
}

}
// 다음 근무일 찾기
public DayOfWeek getNextWorkingDay(DayOfWeek currentDay) {
for (int i = 1; i <= 7; i++) { // 최대 7일을 순환하여 다음 근무일 찾기
DayOfWeek nextDay = currentDay.plus(i);
if (isWorkingOn(nextDay)) {
return nextDay;
}
}
return null;
}

// 근무일인지 확인하기
public boolean isWorkingOn(DayOfWeek day) {
return (this.workDays & (1 << (day.getValue() - 1))) != 0;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dbdr.domain.careworker.dto.response.CareworkerResponse;
import dbdr.domain.careworker.entity.Careworker;
import dbdr.domain.careworker.repository.CareworkerRepository;
import dbdr.domain.core.alarm.service.AlarmService;
import dbdr.domain.institution.entity.Institution;
import dbdr.domain.institution.service.InstitutionService;
import dbdr.global.exception.ApplicationError;
Expand All @@ -16,6 +17,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalTime;
import java.util.List;

@Service
Expand All @@ -24,6 +26,7 @@ public class CareworkerService {

private final CareworkerRepository careworkerRepository;
private final InstitutionService institutionService;
private final AlarmService alarmService;
private final CareworkerMapper careworkerMapper;

@Transactional(readOnly = true)
Expand Down Expand Up @@ -73,6 +76,8 @@ public CareworkerResponse createCareworker(CareworkerRequest careworkerRequestDT
Careworker careworker = careworkerMapper.toEntity(careworkerRequestDTO);

careworkerRepository.save(careworker);
alarmService.createCareworkerAlarm(careworker);

return careworkerMapper.toResponse(careworker);
}

Expand Down Expand Up @@ -176,8 +181,8 @@ private void ensureUniqueEmailButNotId(String phone, Long id) {
}
}

public Careworker findByLineUserId(String userId) {
return careworkerRepository.findByLineUserId(userId).orElse(null);
public List<Careworker> findByAlertTime(LocalTime currentTime) {
return careworkerRepository.findByAlertTime(currentTime);
}

public Careworker findByPhone(String phoneNumber) {
Expand All @@ -189,8 +194,17 @@ private CareworkerMyPageResponse toMyPageResponseDTO(Careworker careworker) {
careworker.getName(),
careworker.getPhone(),
careworker.getInstitution().getInstitutionName(),
careworker.getWorkingDays(),
careworker.getAlertTime()
careworker.getAlertTime(),
careworker.getWorkingDays()
);
}

@Transactional
public void updateLineUserId(String userId, String phoneNumber) {
Careworker careworker = findByPhone(phoneNumber);
careworker.updateLineUserId(userId);
careworkerRepository.save(careworker);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.springframework.web.bind.annotation.RestController;

// 요양사 권한 필요
@Tag(name = "[요양관리사] 차트 관리", description = "요양관리사의 차트 조회, 추가, 수정, 삭제")
@Tag(name = "[요양보호사] 차트 관리", description = "요양보호사의 차트 조회, 추가, 수정, 삭제")
@RestController
@RequestMapping("/${spring.app.version}/careworker/chart")
@RequiredArgsConstructor
Expand Down
Loading

0 comments on commit 288e1d4

Please sign in to comment.