Skip to content

Commit

Permalink
Feat: 약 재고 사용 history 엔티티에 저장 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
suminiee committed May 6, 2024
1 parent ef8d48d commit a08a9ab
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public class ProvidedDrugInfo {
private ConsultContentInfo consultId;

@Column(nullable = false)
private Long providedAmount;
private int providedAmount;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.medicare.neulpeum.dto;

import com.medicare.neulpeum.domain.entity.ConsultContentInfo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -9,7 +8,7 @@
@Setter
@NoArgsConstructor
public class DrugUpdateRequestDto {
private ConsultContentInfo consultId;
private Long consultId;
private String drugName;
private int usedAmount;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.medicare.neulpeum.service;

import com.medicare.neulpeum.domain.entity.ConsultContentInfo;
import com.medicare.neulpeum.domain.entity.PatientInfo;
import com.medicare.neulpeum.dto.*;
import com.medicare.neulpeum.dto.ConsultDetailResponseDto;
import com.medicare.neulpeum.dto.ConsultRequestDto;
import com.medicare.neulpeum.dto.ConsultResponseDto;
import com.medicare.neulpeum.dto.ConsultUpdateRequestDto;

import java.util.List;

Expand All @@ -15,4 +19,6 @@ public interface ConsultService {
void update(ConsultUpdateRequestDto consultUpdateRequestDto);

void delete(Long consultId);

ConsultContentInfo findById(Long consultId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,10 @@ public void delete(Long consultId) {
consultRepository.deleteByConsultId(consultId);
}
}

@Override
public ConsultContentInfo findById(Long consultId) {
Optional<ConsultContentInfo> consultContentInfoOptional= consultRepository.findById(consultId);
return consultContentInfoOptional.orElse(null);
}
}
23 changes: 18 additions & 5 deletions src/main/java/com/medicare/neulpeum/service/DrugServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.medicare.neulpeum.service;

import com.medicare.neulpeum.Repository.ConsultRepository;
import com.medicare.neulpeum.Repository.DrugRepository;
import com.medicare.neulpeum.Repository.ProvidedDrugRepository;
import com.medicare.neulpeum.domain.entity.ConsultContentInfo;
import com.medicare.neulpeum.domain.entity.DrugInfo;
import com.medicare.neulpeum.domain.entity.ProvidedDrugInfo;
import com.medicare.neulpeum.dto.*;
import com.medicare.neulpeum.dto.DrugNameAndAmountResponseDto;
import com.medicare.neulpeum.dto.DrugRequestDto;
import com.medicare.neulpeum.dto.DrugResponseDto;
import com.medicare.neulpeum.dto.DrugUpdateRequestDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -23,6 +28,8 @@ public class DrugServiceImpl implements DrugService{
DrugRepository drugRepository;
@Autowired
ProvidedDrugRepository providedDrugRepository;
@Autowired
ConsultRepository consultRepository;

@Override
public void save(DrugRequestDto drugReq) {
Expand Down Expand Up @@ -93,6 +100,11 @@ public void updateUsedDrug(List<DrugUpdateRequestDto> drugUpdateRequestDtoList)
for (DrugUpdateRequestDto updateRequestDto : drugUpdateRequestDtoList) {
String drugName = updateRequestDto.getDrugName();
int usedAmount = updateRequestDto.getUsedAmount();
ConsultContentInfo consultId = consultRepository.findByConsultId(updateRequestDto.getConsultId()).orElse(null);
if (consultId == null) {
throw new IllegalArgumentException("상담내역을 찾을 수 없습니다. ID: " + updateRequestDto.getConsultId());
}


//약 이름으로 유통기한이 가장 짧은 것을 DB에서 조회
List<DrugInfo> drugs = drugRepository.findByDrugNameOrderByExpireDateAsc(drugName);
Expand All @@ -105,10 +117,11 @@ public void updateUsedDrug(List<DrugUpdateRequestDto> drugUpdateRequestDtoList)
drugRepository.save(drug);

//ProvidedDrugInfo 테이블에 저장

ProvidedDrugInfo providedDrugInfo = ProvidedDrugInfo.builder()
.drugId(drug)
.consultId(updateRequestDto.getConsultId())
.providedAmount((long) remainingAmount)
.consultId(consultId)
.providedAmount(remainingAmount)
.build();
providedDrugRepository.save(providedDrugInfo);

Expand All @@ -123,8 +136,8 @@ public void updateUsedDrug(List<DrugUpdateRequestDto> drugUpdateRequestDtoList)
//ProvidedDrugInfo 테이블에 저장
ProvidedDrugInfo providedDrugInfo = ProvidedDrugInfo.builder()
.drugId(drug)
.consultId(updateRequestDto.getConsultId())
.providedAmount((long) remainingAmount)
.consultId(consultId)
.providedAmount(usableAmount)
.build();
providedDrugRepository.save(providedDrugInfo);
}
Expand Down

0 comments on commit a08a9ab

Please sign in to comment.