Skip to content
Merged

Dev #69

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package com.balybus.galaxy.domain.tblCare;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TblCareRepository extends JpaRepository<TblCare, Long> {
List<TblCare> findByCare_IdAndCareYnTrue(Long topCareSeq);

@Query(value = """
select care_seq
from tbl_care tc
where care_yn = true
and top_care_seq = :topCareSeq
and care_val & :calValTotal <> 0
""", nativeQuery = true)
List<Long> findByCareIdList(@Param("topCareSeq") Long topCareSeq, @Param("calValTotal") int calValTotal);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.balybus.galaxy.domain.tblCare.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CareBaseDto {
protected Integer careLevel; // 장기요양등급
protected Integer inmateState; // 동거인여부
protected Integer workType; // 근무종류
protected Integer gender; // 남성:1 여성:2
protected Integer dementiaSymptom; // 치매증상
protected Integer serviceMeal; // 식사보조
protected Integer serviceToilet; // 배변보조
protected Integer serviceMobility; // 이동보조
protected Integer serviceDaily; // 일상생활
protected Integer welfare; // 복리후생
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.balybus.galaxy.domain.tblCare.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class CareChoiceListDto {
private List<Long> workTypeList; // 근무종류
private List<Long> careLevelList; // 장기요양등급
private List<Long> dementiaSymptomList; // 치매증상
private List<Long> inmateStateList; // 동거인 여부
private List<Long> genderList; // 성별

private List<Long> serviceMealList; // 식사보조
private List<Long> serviceToiletList; // 배변보조
private List<Long> serviceMobilityList; // 이동보조
private List<Long> serviceDailyList; // 일상생활

@JsonInclude(JsonInclude.Include.NON_NULL)
private List<Long> welfareList; // 복리후생
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.balybus.galaxy.domain.tblCare.TblCareRepository;
import com.balybus.galaxy.domain.tblCare.TblCareTopEnum;
import com.balybus.galaxy.domain.tblCare.dto.CareRequestDto;
import com.balybus.galaxy.domain.tblCare.dto.CareResponseDto;
import com.balybus.galaxy.domain.tblCare.dto.TblCareDto;
import com.balybus.galaxy.domain.tblCare.dto.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -22,35 +20,35 @@
public class TblCareServiceImpl implements TblCareService{
private final TblCareRepository careRepository;

private List<TblCareDto> getCareDtoList(TblCareTopEnum careTopEnum){
return careRepository.findByCare_IdAndCareYnTrue(careTopEnum.getCareSeq()).stream().map(TblCareDto::new).toList();
}
@Override
public CareResponseDto.GetAllCodeList getAllCodeList() {
return CareResponseDto.GetAllCodeList.builder()
.workTypeList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.WORK_TYPE.getCareSeq()).stream().map(TblCareDto::new).toList()) // 근무종류
.welfareList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.WELFARE.getCareSeq()).stream().map(TblCareDto::new).toList()) // 복리후생
.careLevelList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.CARE_LEVEL.getCareSeq()).stream().map(TblCareDto::new).toList()) // 장기요양등급
.dementiaSymptomList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.DEMENTIA_SYMPTOM.getCareSeq()).stream().map(TblCareDto::new).toList()) // 치매증상
.inmateStateList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.INMATE_STATE.getCareSeq()).stream().map(TblCareDto::new).toList()) // 동거인 여부
.serviceMealList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_MEAL.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 식사보조
.serviceToiletList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_TOILET.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 배변보조
.serviceMobilityList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_MOBILITY.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 이동보조
.serviceDailyList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_DAILY.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 일상생활
.gender(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.GENDER.getCareSeq()).stream().map(TblCareDto::new).toList()) // 성별
.workTypeList(getCareDtoList(TblCareTopEnum.WORK_TYPE)) // 근무종류
.welfareList(getCareDtoList(TblCareTopEnum.WELFARE)) // 복리후생
.careLevelList(getCareDtoList(TblCareTopEnum.CARE_LEVEL)) // 장기요양등급
.dementiaSymptomList(getCareDtoList(TblCareTopEnum.DEMENTIA_SYMPTOM)) // 치매증상
.inmateStateList(getCareDtoList(TblCareTopEnum.INMATE_STATE)) // 동거인 여부
.serviceMealList(getCareDtoList(TblCareTopEnum.SERVICE_MEAL)) // 어르신 필요 서비스 - 식사보조
.serviceToiletList(getCareDtoList(TblCareTopEnum.SERVICE_TOILET)) // 어르신 필요 서비스 - 배변보조
.serviceMobilityList(getCareDtoList(TblCareTopEnum.SERVICE_MOBILITY)) // 어르신 필요 서비스 - 이동보조
.serviceDailyList(getCareDtoList(TblCareTopEnum.SERVICE_DAILY)) // 어르신 필요 서비스 - 일상생활
.gender(getCareDtoList(TblCareTopEnum.GENDER)) // 성별
.build();
}
@Override
public CareResponseDto.GetServiceCodeList getServiceCodeList() {
return CareResponseDto.GetServiceCodeList.builder()
.serviceMealList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_MEAL.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 식사보조
.serviceToiletList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_TOILET.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 배변보조
.serviceMobilityList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_MOBILITY.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 이동보조
.serviceDailyList(careRepository.findByCare_IdAndCareYnTrue(TblCareTopEnum.SERVICE_DAILY.getCareSeq()).stream().map(TblCareDto::new).toList()) // 어르신 필요 서비스 - 일상생활
.serviceMealList(getCareDtoList(TblCareTopEnum.SERVICE_MEAL)) // 어르신 필요 서비스 - 식사보조
.serviceToiletList(getCareDtoList(TblCareTopEnum.SERVICE_TOILET)) // 어르신 필요 서비스 - 배변보조
.serviceMobilityList(getCareDtoList(TblCareTopEnum.SERVICE_MOBILITY)) // 어르신 필요 서비스 - 이동보조
.serviceDailyList(getCareDtoList(TblCareTopEnum.SERVICE_DAILY)) // 어르신 필요 서비스 - 일상생활
.build();
}

@Override
public CareResponseDto.GetRequestCodeList getRequestCodeList(CareRequestDto.GetRequestCodeList req) {
CareResponseDto.GetRequestCodeList resultDto = new CareResponseDto.GetRequestCodeList();

// EnumMap을 사용하여 각 Enum 값에 해당하는 setter 매핑
Map<TblCareTopEnum, BiConsumer<CareResponseDto.GetRequestCodeList, List<TblCareDto>>> setterMap = new EnumMap<>(TblCareTopEnum.class);
setterMap.put(TblCareTopEnum.WORK_TYPE, CareResponseDto.GetRequestCodeList::setWorkTypeList);
Expand All @@ -66,16 +64,59 @@ public CareResponseDto.GetRequestCodeList getRequestCodeList(CareRequestDto.GetR
setterMap.put(TblCareTopEnum.GENDER, CareResponseDto.GetRequestCodeList::setGender);

// 데이터를 가져오는 공통 로직
Function<TblCareTopEnum, List<TblCareDto>> fetchCareList =
e -> careRepository.findByCare_IdAndCareYnTrue(e.getCareSeq()).stream()
.map(TblCareDto::new)
.toList();
Function<TblCareTopEnum, List<TblCareDto>> fetchCareList = this::getCareDtoList;

// 요청된 Enum 리스트를 순회하며 동적으로 처리
CareResponseDto.GetRequestCodeList resultDto = new CareResponseDto.GetRequestCodeList();
for (TblCareTopEnum topEnum : req.getCareTopEnumList()) {
setterMap.getOrDefault(topEnum, (dto, list) -> {}).accept(resultDto, fetchCareList.apply(topEnum));
}

return resultDto;
}

/**
* 선택한 돌봄 항목 항목별 pk 값 리스트 반환
* @param careDto CareBaseDto
* @param needWelfare boolean:복리후생 데이터 반환 여부
* @return CareChoiceListDto
*/
public CareChoiceListDto getCareChoiceList(CareBaseDto careDto, boolean needWelfare){
CareChoiceListDto resultDto = new CareChoiceListDto();
for(TblCareTopEnum careTopEnum : TblCareTopEnum.values()) {
switch (careTopEnum) {
case WORK_TYPE:
resultDto.setWorkTypeList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getWorkType()));
break;
case CARE_LEVEL:
resultDto.setCareLevelList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getCareLevel()));
break;
case DEMENTIA_SYMPTOM:
resultDto.setDementiaSymptomList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getDementiaSymptom()));
break;
case INMATE_STATE:
resultDto.setInmateStateList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getInmateState()));
break;
case GENDER:
resultDto.setGenderList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getGender()));
break;
case SERVICE_MEAL:
resultDto.setServiceMealList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getServiceMeal()));
break;
case SERVICE_TOILET:
resultDto.setServiceToiletList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getServiceToilet()));
break;
case SERVICE_MOBILITY:
resultDto.setServiceMobilityList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getServiceMobility()));
break;
case SERVICE_DAILY:
resultDto.setServiceDailyList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getServiceDaily()));
break;
case WELFARE:
if(needWelfare) resultDto.setWelfareList(careRepository.findByCareIdList(careTopEnum.getCareSeq(), careDto.getWelfare()));
break;
}
}
return resultDto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum ExceptionCode {
CENTER_EXIST(4004, "센터 정보가 존재합니다."),
UNAUTHORIZED(4005, "권한이 없습니다."),
ALREADY_EXISTS_USER_EMAIL(4007, "카카오 이메일이 이미 존재합니다."),
DO_NOT_LOGIN(4008, "로그인이 필요합니다."),

// 5xxx 서버에러
INTERNAL_SEVER_ERROR(5000, "서버에서 에러가 발생하였습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.balybus.galaxy.patient.controller;

import com.balybus.galaxy.global.exception.ErrorResponse;
import com.balybus.galaxy.patient.dto.PatientRequestDto;
import com.balybus.galaxy.patient.dto.PatientResponseDto;
import com.balybus.galaxy.patient.service.serviceImpl.PatientServiceImpl;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
Expand All @@ -21,17 +24,60 @@ public class PatientController {
private final PatientServiceImpl patientService;

@PostMapping("/save")
@Operation(summary = "어르신 정보 등록 API")
@Operation(summary = "어르신 정보 등록 API", description = "어르신 정보를 등록합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "등록 성공",
content = @Content(schema = @Schema(implementation = PatientResponseDto.SavePatientInfo.class))),
@ApiResponse(responseCode = "4008", description = "사용자정의에러코드:로그인이 정보 없음(쿠키 없음)",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "7000", description = "사용자정의에러코드:로그인한 사용자의 권한이 매니저가 아닙니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "1001", description = "사용자정의에러코드:주소값이 잘못 설정되었습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
public ResponseEntity<?> savePatientInfo(@AuthenticationPrincipal UserDetails userDetails,
@RequestBody PatientRequestDto.SavePatientInfo dto) {
return ResponseEntity.ok().body(patientService.savePatientInfo(userDetails, dto));
return ResponseEntity.ok().body(patientService.savePatientInfo(userDetails.getUsername(), dto));
}

@PostMapping("/update")
@Operation(summary = "어르신 정보 수정 API")
@Operation(summary = "어르신 정보 수정 API", description = "어르신 정보를 수정합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공",
content = @Content(schema = @Schema(implementation = PatientResponseDto.SavePatientInfo.class))),
@ApiResponse(responseCode = "4008", description = "사용자정의에러코드:로그인이 정보 없음(쿠키 없음)",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "7000", description = "사용자정의에러코드:로그인한 사용자의 권한이 매니저가 아닙니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "8000", description = "사용자정의에러코드:해당 어르신 정보를 찾을 수 없습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "7001", description = "사용자정의에러코드:수정 권한 없음",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "1001", description = "사용자정의에러코드:주소값이 잘못 설정되었습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
public ResponseEntity<?> updatePatientInfo(@AuthenticationPrincipal UserDetails userDetails,
@RequestBody PatientRequestDto.UpdatePatientInfo dto) {
return ResponseEntity.ok().body(patientService.updatePatientInfo(userDetails, dto));
return ResponseEntity.ok().body(patientService.updatePatientInfo(userDetails.getUsername(), dto));
}

@PostMapping("/{patientSeq}/detail")
@Operation(summary = "어르신 정보 상세 조회 API", description = "어르신 정보를 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공",
content = @Content(schema = @Schema(implementation = PatientResponseDto.SavePatientInfo.class))),
@ApiResponse(responseCode = "4008", description = "사용자정의에러코드:로그인이 정보 없음(쿠키 없음)",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "7000", description = "사용자정의에러코드:로그인한 사용자의 권한이 매니저가 아닙니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "8000", description = "사용자정의에러코드:해당 어르신 정보를 찾을 수 없습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "7001", description = "사용자정의에러코드:조회 권한 없음",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
public ResponseEntity<?> getOnePatientInfo(@AuthenticationPrincipal UserDetails userDetails,
@PathVariable("patientSeq") Long patientSeq) {
return ResponseEntity.ok().body(patientService.getOnePatientInfo(userDetails.getUsername(), patientSeq));
}

@PostMapping("/recruit-helper")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public class TblPatient extends BaseEntity implements ChangeProfileImg {
@Comment("돌봄 요일 시간 협의 여부")
private Boolean timeNegotiation;

@Column(name = "patient_request_contents", length = 255)
@Comment("기타 요청 사항")
private String requestContents;
// @Column(name = "patient_request_contents", length = 255)
// @Comment("기타 요청 사항")
// private String requestContents;

/* ========================================================
* UPDATE
Expand Down Expand Up @@ -145,6 +145,6 @@ public void basicUpdate(PatientRequestDto.UpdatePatientInfo dto,TblAddressFirst
this.weight = dto.getWeight();
this.diseases = dto.getDiseases();
this.timeNegotiation = dto.getTimeNegotiation();
this.requestContents = dto.getRequestContents();
// this.requestContents = dto.getRequestContents();
}
}
Loading
Loading