Skip to content

Commit

Permalink
feat: 래티오
Browse files Browse the repository at this point in the history
  • Loading branch information
h-beeen committed Mar 23, 2024
1 parent 8790566 commit 3a8f212
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.vacgom.backend.disease.application.dto.response

import com.vacgom.backend.disease.domain.Disease
import com.vacgom.backend.search.application.dto.QnaResponse
import com.vacgom.backend.search.application.dto.response.QnaResponse

class DiseaseResponse(
val id: Long?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class InoculationService(
return vaccinations.map { vaccination ->
val vaccineOrders = hashMap[vaccination.vaccineName]?.toHashSet()?.toList() ?: listOf()
val isCompleted = vaccineOrders.any { order -> order == vaccination.maxOrder }

InoculationSimpleResponse(
vaccination.diseaseName,
vaccination.vaccineName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ interface InoculationRepository : JpaRepository<Inoculation, UUID> {
): List<Inoculation>?


@Query("SELECT i " +
"FROM Inoculation i JOIN i.vaccination v " +
"GROUP BY i.vaccination.id " +
"ORDER BY i.inoculationOrder DESC")
@Query(
"SELECT i " +
"FROM Inoculation i JOIN i.vaccination v " +
"GROUP BY i.vaccination.id " +
"ORDER BY i.inoculationOrder DESC"
)
fun findDistinctLatestInoculationsByMemberId(memberId: UUID): List<Inoculation>

@Query(
"SELECT i " +
"from Inoculation i " +
"where i.vaccination.diseaseName = :diseaseName"
)
fun findInoculationsByDiseaseName(diseaseName: String): List<Inoculation>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vacgom.backend.member.infrastructure.persistence

import com.vacgom.backend.auth.domain.constants.ProviderType
import com.vacgom.backend.auth.domain.constants.Role
import com.vacgom.backend.member.domain.Member
import com.vacgom.backend.member.domain.Nickname
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -17,4 +18,7 @@ interface MemberRepository : JpaRepository<Member, UUID> {

@Query("SELECT COUNT(m)+1 FROM Member m WHERE m.createdDate <= (SELECT m.createdDate FROM Member m WHERE m.id = :uuid)")
fun getJoinCount(uuid: UUID): Number

@Query("Select Count(m) From Member m where m.role = :role")
fun countMembersByRole(role: Role): Long
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vacgom.backend.search.application

import com.vacgom.backend.auth.domain.constants.Role
import com.vacgom.backend.disease.application.DiseaseService
import com.vacgom.backend.disease.domain.Disease
import com.vacgom.backend.disease.domain.constants.AgeCondition
Expand All @@ -11,26 +12,29 @@ import com.vacgom.backend.inoculation.infrastructure.persistence.InoculationRepo
import com.vacgom.backend.inoculation.infrastructure.persistence.VaccinationRepository
import com.vacgom.backend.member.exception.MemberError
import com.vacgom.backend.member.infrastructure.persistence.MemberRepository
import com.vacgom.backend.search.application.dto.DiseaseSearchResponse
import com.vacgom.backend.search.application.dto.VaccinationSearchResponse
import com.vacgom.backend.search.application.dto.response.DiseaseSearchResponse
import com.vacgom.backend.search.application.dto.response.SupportVaccineResponse
import com.vacgom.backend.search.application.dto.response.VaccinationSearchResponse
import org.slf4j.Logger
import org.springframework.stereotype.Service
import java.time.LocalDate
import java.util.*

@Service
class SearchService(
val vaccinationRepository: VaccinationRepository,
val inoculationRepository: InoculationRepository,
val memberRepository: MemberRepository,
val diseaseService: DiseaseService,
val vaccinationRepository: VaccinationRepository,
val inoculationRepository: InoculationRepository,
val memberRepository: MemberRepository,
val diseaseService: DiseaseService,
val log: Logger
) {
private fun findAllVaccinations(): List<Vaccination> {
return vaccinationRepository.findAll()
}

fun searchDisease(
age: List<AgeCondition>,
condition: List<HealthCondition>,
age: List<AgeCondition>,
condition: List<HealthCondition>,
): List<DiseaseSearchResponse> {
val diseases = diseaseService.findAll()

Expand All @@ -40,9 +44,9 @@ class SearchService(
}

fun searchVaccination(
age: List<AgeCondition>,
condition: List<HealthCondition>,
type: VaccinationType,
age: List<AgeCondition>,
condition: List<HealthCondition>,
type: VaccinationType,
): List<VaccinationSearchResponse> {
val diseases = this.searchDisease(age, condition)
val vaccinations = findAllVaccinations()
Expand All @@ -55,38 +59,38 @@ class SearchService(

fun searchRecommendVaccination(memberId: UUID): List<VaccinationSearchResponse> {
val member =
memberRepository.findById(memberId).orElseThrow {
BusinessException(MemberError.NOT_FOUND)
}
memberRepository.findById(memberId).orElseThrow {
BusinessException(MemberError.NOT_FOUND)
}

val ageCondition =
AgeCondition.getAgeCondition(member.memberDetails?.birthday?.year!!.minus(LocalDate.now().year))
AgeCondition.getAgeCondition(member.memberDetails?.birthday?.year!!.minus(LocalDate.now().year))
val vaccinations = findAllVaccinations()
val inoculatedDiseaseName =
inoculationRepository.findDistinctDiseaseNameByMemberId(memberId).flatMap { it.split("·") }.toSet()
inoculationRepository.findDistinctDiseaseNameByMemberId(memberId).flatMap { it.split("·") }.toSet()
val recommendedVaccinations =
vaccinations.filter { vaccination -> !inoculatedDiseaseName.contains(vaccination.vaccineName) }
vaccinations.filter { vaccination -> !inoculatedDiseaseName.contains(vaccination.vaccineName) }

val healthProfiles = member.healthProfiles.map { it.healthCondition }.toList()

val diseases =
this.searchDisease(listOf(ageCondition), healthProfiles).filter { response ->
!inoculatedDiseaseName.contains(response.name)
}.toList()
this.searchDisease(listOf(ageCondition), healthProfiles).filter { response ->
!inoculatedDiseaseName.contains(response.name)
}.toList()
return filterByDisease(recommendedVaccinations, diseases)
}

private fun filterByDisease(
vaccinations: List<Vaccination>,
diseases: List<DiseaseSearchResponse>,
vaccinations: List<Vaccination>,
diseases: List<DiseaseSearchResponse>,
) = vaccinations.filter {
diseases.any { disease -> it.diseaseName.contains(disease.name) }
}.map { VaccinationSearchResponse.of(it) }

fun isMatched(
disease: Disease,
age: List<AgeCondition>,
condition: List<HealthCondition>,
disease: Disease,
age: List<AgeCondition>,
condition: List<HealthCondition>,
): Boolean {
var conditionValue = 0
condition.forEach {
Expand All @@ -105,4 +109,14 @@ class SearchService(
disease.forbiddenHealthConditionFilter and conditionValue == 0
)
}

fun getInoculatedRatioResponse(): SupportVaccineResponse {
val membersCount = memberRepository.countMembersByRole(Role.ROLE_USER)
val hpvCount = inoculationRepository.findInoculationsByDiseaseName("사람유듀종바이러스감염증")
val tt = hpvCount.count()

log.warn("membersCount : {$membersCount}")
log.warn("hpvCount : {$tt}")
return SupportVaccineResponse(30, 30)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vacgom.backend.search.application.dto
package com.vacgom.backend.search.application.dto.response

import com.vacgom.backend.disease.domain.Disease

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vacgom.backend.search.application.dto
package com.vacgom.backend.search.application.dto.response

class QnaResponse(
val question: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.vacgom.backend.search.application.dto.response

data class SupportVaccineResponse(
val hpvRatio: Long,
val influenzaRatio: Long
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.vacgom.backend.search.application.dto
package com.vacgom.backend.search.application.dto.response

import com.vacgom.backend.inoculation.domain.Vaccination

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.vacgom.backend.disease.domain.constants.HealthCondition
import com.vacgom.backend.global.security.annotation.AuthId
import com.vacgom.backend.inoculation.domain.constants.VaccinationType
import com.vacgom.backend.search.application.SearchService
import com.vacgom.backend.search.application.dto.VaccinationSearchResponse
import com.vacgom.backend.search.application.dto.response.SupportVaccineResponse
import com.vacgom.backend.search.application.dto.response.VaccinationSearchResponse
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import java.util.*
Expand Down Expand Up @@ -66,4 +67,10 @@ class SearchController(
fun getCertificate(@AuthId id: UUID): ResponseEntity<List<VaccinationSearchResponse>> {
return ResponseEntity.ok(searchService.searchRecommendVaccination(id))
}

@GetMapping("/ratio")
fun getRatios(): ResponseEntity<SupportVaccineResponse> {
val response = searchService.getInoculatedRatioResponse()
return ResponseEntity.ok(response)
}
}

0 comments on commit 3a8f212

Please sign in to comment.